T
tguclu
Hi everyone ,
Actually I have posted this item in gcc.help but no one replied it .
Then I decided to post it to here because it seems to me that my
question is related to C programming itself .
Question:
I'm trying to pass a pointer to (struct osa_localtime) and get the
local time info to these structure but it doesn't work. After func.
finishes its job and returns to main , my variable in main doesn't
get modified as i expected.
I don't think it's a variable scope issue or is it ? I guess it sth.
specific to structure belongs to "time.h"
gcc version :3.3.1 (cygming special)
host os : winxp pro sp2
Below is the source code
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <locale.h>
#include <string.h>
#include <sys/time.h>
#include <sys/times.h>
typedef unsigned short WORD;
//typedef struct tm SYSTEMTIME ;
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
struct osa_localtime
{
SYSTEMTIME *st;
time_t curtime;
struct tm* localtm;
struct timeval tv;
struct timespec *tp;
};
typedef struct osa_localtime OSA_LOCAL_TIME;
void OSAGetLocaleTime( SYSTEMTIME *local_time);
void OSAGetLocaleTime( SYSTEMTIME *local_time)
{
#ifdef _WIN32_NT_
GetLocalTime(local_time);
#else
OSA_LOCAL_TIME *loc = (OSA_LOCAL_TIME
*)malloc(sizeof(OSA_LOCAL_TIME));
WORD miliseconds;
setlocale (LC_ALL, "");
loc->tp = (struct timespec
*)malloc(sizeof(struct timespec));
clock_gettime(CLOCK_REALTIME,loc->tp);
miliseconds = (WORD)((loc->tp->tv_nsec /
1000 )/1000);
loc-
loc->curtime =
time (NULL);
loc->localtm = localtime (&loc-
starts from 1900
loc->localtm->tm_mon++ ; //tm_mon starts Jan
as 0 index but wMonth
gets Jan as 1
memcpy(&(loc->st->wYear),&(loc->localtm-
memcpy(&(loc->st->wDay),&(loc->localtm-
// *local_time = *(loc->st); //this one works
but i don't like this
way.
#endif
}
int test_osa_local_time (void)
{
int x = 88;
SYSTEMTIME st;
OSAGetLocaleTime(&st);
printf("\n!!!!!!!!!!!!!!!!!!!!!!OSA TIME
TESTYear!!!!!!!!!!!!!!!!!!!!!!");
printf("\nOSA Year : %d", st.wYear);
printf("\nOSA Day : %d", st.wDay);
printf("\nOSA Day of Week : %d",
st.wDayOfWeek);
printf("\nOSA Hour : %d", st.wHour);
printf("\nOSA Minute : %d", st.wMinute);
printf("\nOSA Seconds : %d", st.wSecond);
printf("\nOSA MiliSeconds : %d",
st.wMilliseconds);
printf("\nOSA Month : %d", st.wMonth);
return 0;
}
void OSAGetSystemTime( OSA_LOCAL_TIME *loc)
{
}
int main (void)
{
test_osa_local_time();
return 0;
Actually I have posted this item in gcc.help but no one replied it .
Then I decided to post it to here because it seems to me that my
question is related to C programming itself .
Question:
I'm trying to pass a pointer to (struct osa_localtime) and get the
local time info to these structure but it doesn't work. After func.
finishes its job and returns to main , my variable in main doesn't
get modified as i expected.
I don't think it's a variable scope issue or is it ? I guess it sth.
specific to structure belongs to "time.h"
gcc version :3.3.1 (cygming special)
host os : winxp pro sp2
Below is the source code
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <locale.h>
#include <string.h>
#include <sys/time.h>
#include <sys/times.h>
typedef unsigned short WORD;
//typedef struct tm SYSTEMTIME ;
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
struct osa_localtime
{
SYSTEMTIME *st;
time_t curtime;
struct tm* localtm;
struct timeval tv;
struct timespec *tp;
};
typedef struct osa_localtime OSA_LOCAL_TIME;
void OSAGetLocaleTime( SYSTEMTIME *local_time);
void OSAGetLocaleTime( SYSTEMTIME *local_time)
{
#ifdef _WIN32_NT_
GetLocalTime(local_time);
#else
OSA_LOCAL_TIME *loc = (OSA_LOCAL_TIME
*)malloc(sizeof(OSA_LOCAL_TIME));
WORD miliseconds;
setlocale (LC_ALL, "");
loc->tp = (struct timespec
*)malloc(sizeof(struct timespec));
clock_gettime(CLOCK_REALTIME,loc->tp);
miliseconds = (WORD)((loc->tp->tv_nsec /
1000 )/1000);
loc-
(SYSTEMTIME *)malloc(sizeof(SYSTEMTIME)) ;st =
loc->curtime =
time (NULL);
loc->localtm = localtime (&loc-
loc->localtm->tm_year += 1900 ; //tm_yearcurtime) ;
starts from 1900
loc->localtm->tm_mon++ ; //tm_mon starts Jan
as 0 index but wMonth
gets Jan as 1
memcpy(&(loc->st->wYear),&(loc->localtm-
memcpy(&(loc->st->wMonth),&(loc->localtm-tm_year),sizeof(WORD));
memcpy(&(loc->st->wDayOfWeek),&(loc->localtm-tm_mon),sizeof(WORD));
tm_wday),sizeof(WORD));
memcpy(&(loc->st->wDay),&(loc->localtm-
memcpy(&(loc->st->wHour),&(loc->localtm-tm_mday),sizeof(WORD));
memcpy(&(loc->st->wMinute),&(loc->localtm-tm_hour),sizeof(WORD));
memcpy(&(loc->st->wSecond),&(loc->localtm-tm_min),sizeof(WORD));
memcpy(&(loc->st-tm_sec),sizeof(WORD));
local_time = loc->st;wMilliseconds),&miliseconds,sizeof(WORD));
// *local_time = *(loc->st); //this one works
but i don't like this
way.
#endif
}
int test_osa_local_time (void)
{
int x = 88;
SYSTEMTIME st;
OSAGetLocaleTime(&st);
printf("\n!!!!!!!!!!!!!!!!!!!!!!OSA TIME
TESTYear!!!!!!!!!!!!!!!!!!!!!!");
printf("\nOSA Year : %d", st.wYear);
printf("\nOSA Day : %d", st.wDay);
printf("\nOSA Day of Week : %d",
st.wDayOfWeek);
printf("\nOSA Hour : %d", st.wHour);
printf("\nOSA Minute : %d", st.wMinute);
printf("\nOSA Seconds : %d", st.wSecond);
printf("\nOSA MiliSeconds : %d",
st.wMilliseconds);
printf("\nOSA Month : %d", st.wMonth);
return 0;
}
void OSAGetSystemTime( OSA_LOCAL_TIME *loc)
{
}
int main (void)
{
test_osa_local_time();
return 0;