HI, Your example below is not thread-safe. I suggest that you change it to pass in a pointer to a place to store the result instead of using static "dtt" in the function (and remove the "len" argument, since it is not needed).
That is, change the function signature to: DT_T *AGUTIL_get_date_and_time(DT_T *buf, time_t *tv) By the way, even if yout program is not using threads, it's a good thing to write all of your code to be thread-safe, since someone else may want to use it in a threaded environment, and if a signal handler gets control, you may have the same issues as with threading. On Mon, 27 Dec 2004, Elisabeth Gloria wrote: > I do have such one, you may try to use it: > > char * AGUTIL_get_date_and_time (time_t * tv, > size_t * len) > { > typedef struct snmp_data_and_time_s { > unsigned short year; > unsigned char month; > unsigned char day; > unsigned char hour; > unsigned char minutes; > unsigned char seconds; > unsigned char deci_seconds; > unsigned char direction_from_UTC; > unsigned char hours_from_UTC; > unsigned char minutes_from_UTC; > } DT_T; > static DT_T dtt; > unsigned short iday; > struct tm * tm_data = gmtime(tv); > iday = tm_data->tm_year + 1900; > dtt.year = htons(iday); > dtt.month = 1 + tm_data->tm_mon; > dtt.day = tm_data->tm_mday; > dtt.hour = tm_data->tm_hour; > dtt.minutes = tm_data->tm_min; > dtt.seconds = tm_data->tm_sec; > dtt.deci_seconds = 0; > *len = 8; > return (char *) &dtt; > } > > > Wes Hardaker wrote: > >>>>> On Mon, 15 Nov 2004 13:11:42 +0100 (MET), "Sven Jonas" said: > > Sven> is there any funtion that converts an u_char time[11] to a > Sven> time_t-Struct? > > Nope, but if you write one please send it to us! > > -- > Wes Hardaker > Sparta Regards, /david t. perkins ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/ _______________________________________________ Net-snmp-coders mailing list Net-snmp-coders@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/net-snmp-coders