Leaked source code of windows server 2003
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.

134 lines
4.0 KiB

  1. // FILE.C -- Utilities for File handling
  2. //
  3. // Copyright (c) 1989, Microsoft Corporation. All rights reserved.
  4. //
  5. // Purpose:
  6. // This module contains routines that help in file handling. These routines
  7. // have a behaviour which depends upon the Operating System Version.
  8. //
  9. // Revision History:
  10. // 08-Jun-1992 SS Port to DOSX32
  11. // 20-Apr-1989 SB Created
  12. //
  13. // Notes: Created to give OS/2 Version 1.2 filename support.
  14. #include "precomp.h"
  15. #pragma hdrstop
  16. #define bitsin(type) sizeof(type) * 8
  17. // getFileName -- get file name from struct
  18. //
  19. // Purpose: returns filename from file search structure passed to it.
  20. //
  21. // Input: findBuf -- address of pointer to structure
  22. //
  23. // Output: Returns a pointer to filename in the file search structure.
  24. //
  25. // Assumes:
  26. // That the structure of appropriate size is given to it. This means that the
  27. // size is as per --
  28. // find_t : DOS Real Mode
  29. // _finddata_t : FLAT Protect Mode
  30. //
  31. // Notes: The functionality depends upon the OS version and mode
  32. char *
  33. getFileName(
  34. void *findBuf
  35. )
  36. {
  37. char *fileName;
  38. fileName = ((struct _finddata_t *) findBuf)->name;
  39. return(fileName);
  40. }
  41. // getDateTime -- get file timestamp from struct
  42. //
  43. // Purpose: returns timestamp from the file search structure passed to it.
  44. //
  45. // Input: findBuf -- address of pointer to structure
  46. //
  47. // Output: Returns timestamp of the file in the structure
  48. //
  49. // Assumes:
  50. // That the structure of appropriate size is given to it. This means that the
  51. // size is as per --
  52. // find_t : DOS Real Mode
  53. // _finddata_t : FLAT Protect Mode
  54. //
  55. // Notes:
  56. // The timestamp is an unsigned long value that gives the date and time of last
  57. // change to the file. If the date is high byte then two times of creation of
  58. // two files can be compared by comparing their timestamps. This is easy in the
  59. // DOS struct but becomes complex for the OS/2 structs because the order of date
  60. // and time has been reversed (for some unexplicable reason).
  61. //
  62. // The functionality depends upon the OS version and mode.
  63. time_t
  64. getDateTime(
  65. const _finddata_t *pfd
  66. )
  67. {
  68. time_t dateTime;
  69. if( pfd->attrib & _A_SUBDIR ) {
  70. // subdir return create date
  71. if (pfd->time_create == -1) {
  72. // except on FAT
  73. dateTime = pfd->time_write;
  74. }
  75. else {
  76. dateTime = pfd->time_create;
  77. }
  78. }
  79. else {
  80. dateTime = pfd->time_write ;
  81. }
  82. return dateTime;
  83. }
  84. // putDateTime -- change the timestamp in the struct
  85. //
  86. // Purpose: changes timestamp in the file search structure passed to it.
  87. //
  88. // Input: findBuf -- address of pointer to structure
  89. // lDateTime -- new value of timestamp
  90. //
  91. // Assumes:
  92. // That the structure of appropriate size is given to it. This means that the
  93. // size is as per --
  94. // find_t : DOS Real Mode
  95. // FileFindBuf : OS/2 (upto Ver 1.10) Protect Mode
  96. // _FILEFINDBUF : OS/2 (Ver 1.20 & later) Protect Mode
  97. //
  98. // Notes:
  99. // The timestamp is a time_t value that gives the date and time of last
  100. // change to the file. If the date is high byte then two times of creation of
  101. // two files can be compared by comparing their timestamps. This is easy in the
  102. // DOS struct but becomes complex for the OS/2 structs because the order of date
  103. // and time has been reversed (for some unexplicable reason).
  104. //
  105. // The functionality depends upon the OS version and mode.
  106. //
  107. // Efficient method to get a long with high and low bytes reversed is
  108. // (long)high << 16 | (long)low //high, low being short
  109. void
  110. putDateTime(
  111. _finddata_t *pfd,
  112. time_t lDateTime
  113. )
  114. {
  115. if (pfd->attrib & _A_SUBDIR) {
  116. // return the creation date on directories
  117. pfd->time_create = lDateTime;
  118. }
  119. else {
  120. pfd->time_write = lDateTime;
  121. }
  122. }