original development tree for Linux kernel GTP module; now long in mainline.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.4 KiB

  1. /*
  2. * linux/fs/isofs/util.c
  3. */
  4. #include "isofs.h"
  5. /*
  6. * We have to convert from a MM/DD/YY format to the Unix ctime format.
  7. * We have to take into account leap years and all of that good stuff.
  8. * Unfortunately, the kernel does not have the information on hand to
  9. * take into account daylight savings time, but it shouldn't matter.
  10. * The time stored should be localtime (with or without DST in effect),
  11. * and the timezone offset should hold the offset required to get back
  12. * to GMT. Thus we should always be correct.
  13. */
  14. int iso_date(char * p, int flag)
  15. {
  16. int year, month, day, hour, minute, second, tz;
  17. int crtime, days, i;
  18. year = p[0] - 70;
  19. month = p[1];
  20. day = p[2];
  21. hour = p[3];
  22. minute = p[4];
  23. second = p[5];
  24. if (flag == 0) tz = p[6]; /* High sierra has no time zone */
  25. else tz = 0;
  26. if (year < 0) {
  27. crtime = 0;
  28. } else {
  29. int monlen[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
  30. days = year * 365;
  31. if (year > 2)
  32. days += (year+1) / 4;
  33. for (i = 1; i < month; i++)
  34. days += monlen[i-1];
  35. if (((year+2) % 4) == 0 && month > 2)
  36. days++;
  37. days += day - 1;
  38. crtime = ((((days * 24) + hour) * 60 + minute) * 60)
  39. + second;
  40. /* sign extend */
  41. if (tz & 0x80)
  42. tz |= (-1 << 8);
  43. /*
  44. * The timezone offset is unreliable on some disks,
  45. * so we make a sanity check. In no case is it ever
  46. * more than 13 hours from GMT, which is 52*15min.
  47. * The time is always stored in localtime with the
  48. * timezone offset being what get added to GMT to
  49. * get to localtime. Thus we need to subtract the offset
  50. * to get to true GMT, which is what we store the time
  51. * as internally. On the local system, the user may set
  52. * their timezone any way they wish, of course, so GMT
  53. * gets converted back to localtime on the receiving
  54. * system.
  55. *
  56. * NOTE: mkisofs in versions prior to mkisofs-1.10 had
  57. * the sign wrong on the timezone offset. This has now
  58. * been corrected there too, but if you are getting screwy
  59. * results this may be the explanation. If enough people
  60. * complain, a user configuration option could be added
  61. * to add the timezone offset in with the wrong sign
  62. * for 'compatibility' with older discs, but I cannot see how
  63. * it will matter that much.
  64. *
  65. * Thanks to kuhlmav@elec.canterbury.ac.nz (Volker Kuhlmann)
  66. * for pointing out the sign error.
  67. */
  68. if (-52 <= tz && tz <= 52)
  69. crtime -= tz * 15 * 60;
  70. }
  71. return crtime;
  72. }