tzset.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* $Id$ */
  2. #ifdef __BSD4_2
  3. struct timeval {
  4. long tv_sec, tv_usec;
  5. };
  6. struct timezone {
  7. int tz_minuteswest, tz_dsttime;
  8. };
  9. #else
  10. #ifndef __USG
  11. #include <sys/types.h>
  12. struct timeb
  13. {
  14. time_t time;
  15. ushort millitm;
  16. short timezone;
  17. short dstflag;
  18. };
  19. #endif
  20. #endif
  21. #ifdef __USG
  22. long timezone = -1 * 60;
  23. int daylight = 1;
  24. char *tzname[] = {"MET", "MDT",};
  25. #endif
  26. long __timezone = -1 * 60;
  27. int __daylight = 1;
  28. char *__tzname[] = {"MET", "MDT", };
  29. tzset()
  30. {
  31. #ifdef __BSD4_2
  32. struct timeval tval;
  33. struct timezone tzon;
  34. gettimeofday(&tval, &tzon);
  35. __timezone = tzon.tz_minuteswest * 60L;
  36. __daylight = tzon.tz_dsttime;
  37. #else
  38. #ifndef __USG
  39. #if minix || minixST
  40. __timezone = 0L;
  41. __daylight = 0;
  42. #else
  43. struct timeb time;
  44. ftime(&time);
  45. __timezone = time.timezone*60L;
  46. __daylight = time.dstflag;
  47. #endif
  48. #endif
  49. #endif
  50. {
  51. extern char *getenv();
  52. register char *p = getenv("TZ");
  53. if (p && *p) {
  54. register int n = 0;
  55. int sign = 1;
  56. strncpy(__tzname[0], p, 3);
  57. if (*(p += 3) == '-') {
  58. sign = -1;
  59. p++;
  60. }
  61. while(*p >= '0' && *p <= '9')
  62. n = 10 * n + (*p++ - '0');
  63. n *= sign;
  64. __timezone = ((long)(n * 60)) * 60;
  65. __daylight = (*p != '\0');
  66. strncpy(__tzname[1], p, 3);
  67. }
  68. }
  69. #ifdef __USG
  70. timezone = __timezone;
  71. daylight = __daylight;
  72. tzname[0] = __tzname[0];
  73. tzname[1] = __tzname[1];
  74. #endif
  75. }