smbtime.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "headers.h"
  10. void
  11. smbplan9time2datetime(uint32_t time, int tzoff, uint16_t *datep,
  12. uint16_t *timep)
  13. {
  14. Tm *tm;
  15. if (tzoff < 0)
  16. time -= (uint32_t)-tzoff;
  17. else
  18. time += tzoff;
  19. tm = gmtime(time);
  20. *datep = (tm->mday) | ((tm->mon + 1) << 5) | ((tm->year - 80) << 9);
  21. *timep = (tm->sec >> 1) | (tm->min << 5) | (tm->hour << 11);
  22. }
  23. uint32_t
  24. smbdatetime2plan9time(uint16_t date, uint16_t time, int tzoff)
  25. {
  26. Tm tm;
  27. strcpy(tm.zone, "GMT");
  28. tm.mday = date & 0x1f;
  29. tm.mon = ((date >> 5) & 0xf) - 1;
  30. tm.year = (date >> 9) + 80;
  31. tm.yday = 0;
  32. tm.sec = (time & 0x1f) << 1;
  33. tm.min = (time >> 5) & 0x3f;
  34. tm.hour = time >> 11;
  35. smblogprint(-1, "smbdatetime2plan9time: converting %d/%d/%d %d:%d:%d\n",
  36. tm.year + 1900, tm.mon + 1, tm.mday, tm.hour, tm.min, tm.sec);
  37. return tm2sec(&tm) - tzoff;
  38. }
  39. int64_t
  40. smbplan9time2time(uint32_t time)
  41. {
  42. return ((int64_t)time + 11644473600LL) * 10000000;
  43. }
  44. uint32_t
  45. smbtime2plan9time(int64_t nttime)
  46. {
  47. return (nttime / 10000000 - 11644473600LL);
  48. }
  49. uint32_t
  50. smbplan9time2utime(uint32_t time, int tzoff)
  51. {
  52. if (tzoff < 0)
  53. time -= (uint32_t)-tzoff;
  54. else
  55. time += tzoff;
  56. return time;
  57. }
  58. uint32_t
  59. smbutime2plan9time(uint32_t utime, int tzoff)
  60. {
  61. if (tzoff < 0)
  62. utime += (uint32_t)-tzoff;
  63. else
  64. utime -= tzoff;
  65. return utime;
  66. }