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.

359 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. util.h
  5. Abstract:
  6. Interface for utility functions
  7. Author:
  8. Ovidiu Temereanca (ovidiut) 08-Nov-2000
  9. Revision History:
  10. <alias> <date> <comment>
  11. --*/
  12. typedef struct tagGENERIC_LIST {
  13. struct tagGENERIC_LIST* Next;
  14. } GENERIC_LIST, *PGENERIC_LIST;
  15. typedef struct tagSTRINGLIST {
  16. struct tagSTRINGLIST* Next;
  17. PTSTR String;
  18. } STRINGLIST, *PSTRINGLIST;
  19. typedef struct tagSDLIST {
  20. struct tagSDLIST* Next;
  21. PTSTR String;
  22. DWORD_PTR Data;
  23. } SDLIST, *PSDLIST;
  24. typedef struct {
  25. PTSTR FileName;
  26. TCHAR FullPath[MAX_PATH];
  27. WIN32_FIND_DATA FindData;
  28. //
  29. // private data
  30. //
  31. HANDLE Handle;
  32. } FILEPATTERN_ENUM, *PFILEPATTERN_ENUM;
  33. #define ENUM_FIRSTFILE 1
  34. #define ENUM_NEXTFILE 2
  35. #define ENUM_SUBDIRS 3
  36. #define ENUM_SUBDIR 4
  37. typedef struct tagFILEENUMLIST {
  38. struct tagFILEENUMLIST* Next;
  39. PTSTR Dir;
  40. DWORD EnumState;
  41. FILEPATTERN_ENUM Enum;
  42. } FILEENUMLIST, *PFILEENUMLIST;
  43. #define ECF_ENUM_SUBDIRS 0x0001
  44. #define ECF_ABORT_ENUM_DIR 0x0002
  45. #define ECF_STOP_ON_LONG_PATHS 0x0004
  46. typedef struct {
  47. PTSTR FileName;
  48. PTSTR SubPath;
  49. PTSTR FullPath;
  50. PWIN32_FIND_DATA FindData;
  51. DWORD ControlFlags;
  52. //
  53. // private data
  54. //
  55. PCTSTR FilePattern;
  56. DWORD RootLen;
  57. PFILEENUMLIST DirCurrent;
  58. HANDLE Handle;
  59. } FILEPATTERNREC_ENUM, *PFILEPATTERNREC_ENUM;
  60. PTSTR
  61. BuildPathEx (
  62. IN PTSTR DestPath,
  63. IN DWORD Chars,
  64. IN PCTSTR Path1,
  65. IN PCTSTR Path2
  66. );
  67. #define BuildPath(d,p1,p2) BuildPathEx(d,ARRAYSIZE(d),p1,p2)
  68. PTSTR
  69. DupString (
  70. IN PCTSTR String
  71. );
  72. PTSTR
  73. DupMultiSz (
  74. IN PCTSTR MultiSz
  75. );
  76. PTSTR
  77. CreatePrintableString (
  78. IN PCTSTR MultiSz
  79. );
  80. PWSTR
  81. AnsiToUnicode (
  82. IN PCSTR SzAnsi
  83. );
  84. PWSTR
  85. MultiSzAnsiToUnicode (
  86. IN PCSTR MultiSzAnsi
  87. );
  88. PSTR
  89. UnicodeToAnsi (
  90. IN PCWSTR Unicode
  91. );
  92. BOOL
  93. EnumFirstFilePattern (
  94. OUT PFILEPATTERN_ENUM Enum,
  95. IN PCTSTR Dir,
  96. IN PCTSTR FilePattern
  97. );
  98. BOOL
  99. EnumNextFilePattern (
  100. IN OUT PFILEPATTERN_ENUM Enum
  101. );
  102. VOID
  103. AbortEnumFilePattern (
  104. IN OUT PFILEPATTERN_ENUM Enum
  105. );
  106. BOOL
  107. EnumFirstFilePatternRecursive (
  108. OUT PFILEPATTERNREC_ENUM Enum,
  109. IN PCTSTR Dir,
  110. IN PCTSTR FilePattern,
  111. IN DWORD ControlFlags
  112. );
  113. BOOL
  114. EnumNextFilePatternRecursive (
  115. IN OUT PFILEPATTERNREC_ENUM Enum
  116. );
  117. VOID
  118. AbortEnumFilePatternRecursive (
  119. IN OUT PFILEPATTERNREC_ENUM Enum
  120. );
  121. BOOL
  122. CreateDir (
  123. IN PCTSTR DirName
  124. );
  125. PSTRINGLIST
  126. CreateStringCell (
  127. IN PCTSTR String
  128. );
  129. VOID
  130. DeleteStringCell (
  131. IN PSTRINGLIST Cell
  132. );
  133. BOOL
  134. FindStringCell (
  135. IN PSTRINGLIST StringList,
  136. IN PCTSTR String,
  137. IN BOOL CaseSensitive
  138. );
  139. VOID
  140. DeleteStringList (
  141. IN PSTRINGLIST List
  142. );
  143. PFILEENUMLIST
  144. CreateFileEnumCell (
  145. IN PCTSTR Dir,
  146. IN PCTSTR FilePattern,
  147. IN DWORD Attributes,
  148. IN DWORD EnumState
  149. );
  150. VOID
  151. DeleteFileEnumCell (
  152. IN PFILEENUMLIST Cell
  153. );
  154. BOOL
  155. InsertList (
  156. IN OUT PGENERIC_LIST* List,
  157. IN PGENERIC_LIST NewList
  158. );
  159. VOID
  160. DeleteFileEnumList (
  161. IN PFILEENUMLIST NewList
  162. );
  163. PCTSTR
  164. FindSubString (
  165. IN PCTSTR String,
  166. IN TCHAR Separator,
  167. IN PCTSTR SubStr,
  168. IN BOOL CaseSensitive
  169. );
  170. VOID
  171. GetCurrentWinnt32RegKey (
  172. OUT PTSTR Key,
  173. IN INT Chars
  174. );
  175. BOOL
  176. IsFileVersionLesser (
  177. IN PCTSTR FileToCompare,
  178. IN PCTSTR FileToCompareWith
  179. );
  180. BOOL
  181. CopyTree (
  182. IN PCTSTR SourceRoot,
  183. IN PCTSTR DestRoot
  184. );
  185. BOOL
  186. StringToInt (
  187. IN PCTSTR Field,
  188. OUT PINT IntegerValue
  189. );
  190. BOOL
  191. CheckForFileVersionEx (
  192. LPCTSTR FileName,
  193. LPCTSTR FileVer, OPTIONAL
  194. LPCTSTR BinProductVer, OPTIONAL
  195. LPCTSTR LinkDate OPTIONAL
  196. );
  197. BOOL
  198. GetLinkDate (
  199. IN PCTSTR FilePath,
  200. OUT PDWORD LinkDate
  201. );
  202. VOID
  203. FixMissingKnownDlls (
  204. OUT PSTRINGLIST* MissingKnownDlls,
  205. IN PCTSTR RestrictedCheckList OPTIONAL
  206. );
  207. VOID
  208. UndoFixMissingKnownDlls (
  209. IN PSTRINGLIST MissingKnownDlls
  210. );
  211. BOOL
  212. IsPatternMatchA (
  213. IN PCSTR strPattern,
  214. IN PCSTR strStr
  215. );
  216. BOOL
  217. IsPatternMatchW (
  218. IN PCWSTR wstrPattern,
  219. IN PCWSTR wstrStr
  220. );
  221. #ifdef UNICODE
  222. #define IsPatternMatch(pattern,string) IsPatternMatchW(pattern,string)
  223. #else
  224. #define IsPatternMatch(pattern,string) IsPatternMatchA(pattern,string)
  225. #endif
  226. BOOL
  227. Winnt32GetDiskFreeSpaceNewA(
  228. IN PCSTR DriveName,
  229. OUT DWORD * OutSectorsPerCluster,
  230. OUT DWORD * OutBytesPerSector,
  231. OUT ULARGE_INTEGER * OutNumberOfFreeClusters,
  232. OUT ULARGE_INTEGER * OutTotalNumberOfClusters
  233. );
  234. BOOL
  235. Winnt32GetDiskFreeSpaceNewW(
  236. IN PCWSTR DriveName,
  237. OUT DWORD * OutSectorsPerCluster,
  238. OUT DWORD * OutBytesPerSector,
  239. OUT ULARGE_INTEGER * OutNumberOfFreeClusters,
  240. OUT ULARGE_INTEGER * OutTotalNumberOfClusters
  241. );
  242. BOOL
  243. ReplaceSubStr(
  244. IN OUT LPTSTR SrcStr,
  245. IN LPTSTR SrcSubStr,
  246. IN LPTSTR DestSubStr
  247. );
  248. #ifdef UNICODE
  249. #define Winnt32GetDiskFreeSpaceNew Winnt32GetDiskFreeSpaceNewW
  250. #else
  251. #define Winnt32GetDiskFreeSpaceNew Winnt32GetDiskFreeSpaceNewA
  252. #endif
  253. VOID
  254. RemoveTrailingWack (
  255. PTSTR String
  256. );
  257. ULONGLONG
  258. SystemTimeToFileTime64 (
  259. IN PSYSTEMTIME SystemTime
  260. );
  261. DWORD
  262. MyGetFullPathName (
  263. IN PCTSTR FileName, // file name
  264. IN DWORD BufferLength, // size of path buffer
  265. IN PTSTR Buffer, // path buffer
  266. OUT PTSTR* FilePart // address of file name in path
  267. );
  268. DWORD
  269. MyGetModuleFileName (
  270. IN HMODULE Module,
  271. OUT PTSTR Buffer,
  272. IN DWORD BufferLength
  273. );
  274. //
  275. // Macro to make ansi vs unicode string handling
  276. // a little easier
  277. //
  278. #ifdef UNICODE
  279. #define NewAnsiString(x) UnicodeToAnsi(x)
  280. #define NewPortableString(x) AnsiToUnicode(x)
  281. #else
  282. #define NewAnsiString(x) DupString(x)
  283. #define NewPortableString(x) DupString(x)
  284. #endif