Watt-32 tcp/ip  2.2 dev-rel.10
settod.c
Go to the documentation of this file.
1 
16 #if !defined(__DJGPP__) && !defined(__CYGWIN__) /* already have settimeofday() */
17 
18 #include <errno.h> /* EINVAL */
19 #include <sys/wtime.h> /* time func/types */
20 
21 #include "wattcp.h"
22 #include "misc.h"
23 #include "settod.h"
24 
25 int MS_CDECL settimeofday (struct timeval *tv, ...)
26 {
27  if (tv)
28  {
29  time_t t = (time_t)tv->tv_sec;
30  struct tm res;
31  struct tm *rc = localtime_r (&t, &res);
32 
33  if (rc && res.tm_year >= 80)
34  {
35 #if defined(WIN32)
36  SYSTEMTIME tim;
37 
38  tim.wYear = res.tm_year + 1900;
39  tim.wMonth = res.tm_mon + 1;
40  tim.wDayOfWeek = res.tm_wday;
41  tim.wDay = res.tm_mday;
42  tim.wHour = res.tm_hour;
43  tim.wMinute = res.tm_min;
44  tim.wSecond = res.tm_sec;
45  tim.wMilliseconds = tv->tv_usec / 1000;
46  if (SetLocalTime(&tim))
47  return (0);
48 #else
49  struct dosdate_t newdate;
50  struct dostime_t newtime;
51 
52  newdate.year = (WORD)(res.tm_year + 1900);
53  newdate.month = (BYTE)(res.tm_mon + 1);
54  newdate.day = (BYTE)(res.tm_mday);
55  newtime.hour = (BYTE)(res.tm_hour);
56  newtime.minute = (BYTE)(res.tm_min);
57  newtime.second = (BYTE)(res.tm_sec);
58  newtime.hsecond = (BYTE)(tv->tv_usec / 10000ul);
59  if (_dos_setdate(&newdate) == 0 && /* int 21h fxn 2Bh */
60  _dos_settime(&newtime) == 0) /* int 21h fxn 2Dh */
61  return (0);
62 #endif
63  }
64  }
65  SOCK_ERRNO (EINVAL);
66  return (-1);
67 }
68 #endif /* !__DJGPP__ && !__CYGWIN__ */
struct tm * localtime_r(const time_t *t, struct tm *res)
A reentrant localtime().
Definition: misc.c:886
Core definitions.
Definition: wtime.h:38