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.

148 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. spbasefile.c
  5. Abstract:
  6. see also
  7. .\spcab.c
  8. .\spbasefile.c
  9. .\spbasefile.h
  10. windows\winstate\...\cablib.c
  11. windows\winstate\cobra\utils\main\basefile.c
  12. windows\winstate\cobra\utils\inc\basefile.h
  13. Author:
  14. Jay Krell (a-JayK) November 2000
  15. Revision History:
  16. --*/
  17. #include "spprecmp.h"
  18. #include "spstrings.h"
  19. #include "spbasefile.h"
  20. #include "spbasefilep.h"
  21. #include "spwin.h"
  22. #include "spcab.h"
  23. #include "spcabp.h"
  24. HANDLE
  25. SpCreateFile1A(
  26. IN PCSTR FileName
  27. )
  28. {
  29. HANDLE Handle;
  30. Handle = SpWin32CreateFileA(
  31. FileName,
  32. GENERIC_READ|GENERIC_WRITE,
  33. 0,
  34. NULL,
  35. CREATE_ALWAYS,
  36. FILE_ATTRIBUTE_NORMAL,
  37. NULL
  38. );
  39. if (Handle == INVALID_HANDLE_VALUE) {
  40. Handle = NULL;
  41. }
  42. return Handle;
  43. }
  44. PSTR
  45. SpJoinPathsA(
  46. PCSTR a,
  47. PCSTR b
  48. )
  49. {
  50. // UNDONE find code elsewhere in setup that does this already
  51. PSTR Result = NULL;
  52. SIZE_T alen = 0;
  53. SIZE_T blen = 0;
  54. if (a == NULL)
  55. goto Exit;
  56. if (b == NULL)
  57. goto Exit;
  58. alen = strlen(a);
  59. blen = strlen(b);
  60. Result = SpMemAlloc((alen + blen + 2) * sizeof(*Result));
  61. if (Result == NULL) {
  62. SpSetLastWin32ErrorAndNtStatusFromNtStatus(STATUS_NO_MEMORY);
  63. goto Exit;
  64. }
  65. if (alen != 0) {
  66. strcpy(Result, a);
  67. if (a[alen - 1] != '\\')
  68. strcat(Result, "\\");
  69. }
  70. strcat(Result, b);
  71. Exit:
  72. KdPrintEx((DPFLTR_SETUP_ID, SpPointerToDbgPrintLevel(Result), "SETUP:"__FUNCTION__" exiting\n"));
  73. return Result;
  74. }
  75. HANDLE
  76. SpOpenFile1A(
  77. IN PCSTR Ansi
  78. )
  79. {
  80. NTSTATUS Status = STATUS_SUCCESS;
  81. BOOL Success = FALSE;
  82. ANSI_STRING AnsiString = { 0 };
  83. UNICODE_STRING UnicodeString = { 0 };
  84. HANDLE Handle = NULL;
  85. RtlInitAnsiString(&AnsiString, Ansi);
  86. AnsiString.Length = AnsiString.MaximumLength; // include terminal nul
  87. if (!NT_SUCCESS(Status = SpAnsiStringToUnicodeString(&UnicodeString, &AnsiString, TRUE)))
  88. goto NtExit;
  89. Handle = SpOpenFile1W(UnicodeString.Buffer);
  90. if (Handle == NULL || Handle == INVALID_HANDLE_VALUE)
  91. goto Exit;
  92. Exit:
  93. SpFreeStringW(&UnicodeString);
  94. KdPrintEx((
  95. DPFLTR_SETUP_ID,
  96. SpHandleToDbgPrintLevel(Handle),
  97. "SETUP:"__FUNCTION__"(%s) exiting %p\n", Ansi, Handle
  98. ));
  99. return Handle;
  100. NtExit:
  101. SpSetLastWin32ErrorAndNtStatusFromNtStatus(Status);
  102. goto Exit;
  103. }
  104. HANDLE
  105. SpOpenFile1W(
  106. IN PCWSTR FileName
  107. )
  108. {
  109. HANDLE Handle;
  110. Handle = SpWin32CreateFileW(
  111. FileName,
  112. GENERIC_READ|GENERIC_WRITE,
  113. 0, // no share
  114. NULL,
  115. OPEN_EXISTING,
  116. FILE_ATTRIBUTE_NORMAL,
  117. NULL
  118. );
  119. if (Handle == INVALID_HANDLE_VALUE) {
  120. Handle = NULL;
  121. }
  122. return Handle;
  123. }