Source code of Windows XP (NT5)
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.

235 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. crtsup.c
  5. Abstract:
  6. This module contains support routines used by the Posix C runtimes.
  7. Author:
  8. Ellen Aycock-Wright (ellena) 07-Aug-1991
  9. Environment:
  10. User Mode only
  11. Revision History:
  12. --*/
  13. #include "psxmsg.h"
  14. #include "psxdll.h"
  15. char *
  16. __cdecl
  17. __PdxGetCmdLine(
  18. VOID
  19. )
  20. /*++
  21. Routine Description:
  22. The command line of the current process is available using this
  23. API.
  24. Arguments:
  25. None.
  26. Return Value:
  27. The address of the current processes command line is returned. The
  28. return value is a pointer to null terminate string.
  29. --*/
  30. {
  31. return PsxAnsiCommandLine.Buffer;
  32. }
  33. int
  34. PdxStatusToErrno(
  35. IN NTSTATUS Status
  36. )
  37. /*++
  38. Routine Description:
  39. This procedure converts an NT status code to an
  40. equivalent errno value. BUG BUG it is duplicated in the
  41. server as PsxStatusToErrno to avoid calling the server.
  42. The conversion is a function of the status code class.
  43. Arguments:
  44. Class - Supplies the status code class to use.
  45. Status - Supplies the status code to convert.
  46. Return Value:
  47. Returns an equivalent error code to the supplied status code.
  48. --*/
  49. {
  50. ULONG Error;
  51. switch (Status) {
  52. case STATUS_INVALID_PARAMETER:
  53. Error = EINVAL;
  54. break;
  55. case STATUS_DIRECTORY_NOT_EMPTY:
  56. // Error = ENOTEMPTY;
  57. Error = EEXIST;
  58. break;
  59. case STATUS_OBJECT_PATH_INVALID:
  60. case STATUS_NOT_A_DIRECTORY:
  61. Error = ENOTDIR;
  62. break;
  63. case STATUS_OBJECT_PATH_SYNTAX_BAD:
  64. // this for the rename test; 'old' has component too long.
  65. Error = ENAMETOOLONG;
  66. break;
  67. case STATUS_OBJECT_NAME_COLLISION:
  68. Error = EEXIST;
  69. break;
  70. case STATUS_OBJECT_PATH_NOT_FOUND:
  71. case STATUS_OBJECT_NAME_NOT_FOUND:
  72. case STATUS_DELETE_PENDING:
  73. Error = ENOENT;
  74. break;
  75. case STATUS_NO_MEMORY:
  76. case STATUS_INSUFFICIENT_RESOURCES:
  77. Error = ENOMEM;
  78. break;
  79. case STATUS_CANNOT_DELETE:
  80. Error = ETXTBUSY;
  81. break;
  82. case STATUS_DISK_FULL:
  83. Error = ENOSPC;
  84. break;
  85. case STATUS_MEDIA_WRITE_PROTECTED:
  86. Error = EROFS;
  87. break;
  88. case STATUS_OBJECT_NAME_INVALID:
  89. Error = ENAMETOOLONG;
  90. break;
  91. case STATUS_FILE_IS_A_DIRECTORY:
  92. Error = EISDIR;
  93. break;
  94. case STATUS_NOT_SAME_DEVICE:
  95. Error = EXDEV;
  96. break;
  97. default :
  98. Error = EACCES;
  99. }
  100. return Error;
  101. }
  102. //
  103. // Copied from the server side.
  104. //
  105. int
  106. PdxStatusToErrnoPath(
  107. PUNICODE_STRING Path
  108. )
  109. {
  110. NTSTATUS Status;
  111. OBJECT_ATTRIBUTES Obj;
  112. HANDLE FileHandle;
  113. ULONG DesiredAccess;
  114. IO_STATUS_BLOCK Iosb;
  115. ULONG Options;
  116. PWCHAR pwc, pwcSav;
  117. ULONG MinLen;
  118. PSX_GET_SIZEOF(DOSDEVICE_X_W,MinLen);
  119. DesiredAccess = SYNCHRONIZE;
  120. Options = FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE;
  121. pwcSav = NULL;
  122. for (;;) {
  123. //
  124. // Remove trailing component.
  125. //
  126. pwc = wcsrchr(Path->Buffer, L'\\');
  127. if (pwcSav)
  128. *pwcSav = L'\\';
  129. if (NULL == pwc) {
  130. break;
  131. }
  132. *pwc = UNICODE_NULL;
  133. pwcSav = pwc;
  134. Path->Length = wcslen(Path->Buffer) * sizeof(WCHAR);
  135. if (Path->Length <= MinLen) {
  136. *pwcSav = L'\\';
  137. break;
  138. }
  139. InitializeObjectAttributes(&Obj, Path, 0, NULL, NULL);
  140. Status = NtOpenFile(&FileHandle, DesiredAccess, &Obj,
  141. &Iosb,
  142. FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
  143. Options);
  144. if (NT_SUCCESS(Status)) {
  145. NtClose(FileHandle);\
  146. }
  147. if (STATUS_NOT_A_DIRECTORY == Status) {
  148. *pwcSav = L'\\';
  149. Path->Length = wcslen(Path->Buffer) * sizeof(WCHAR);
  150. return ENOTDIR;
  151. }
  152. }
  153. Path->Length = wcslen(Path->Buffer) * sizeof(WCHAR);
  154. return ENOENT;
  155. }
  156. int __cdecl
  157. raise(int sig)
  158. {
  159. return kill(getpid(), sig);
  160. }
  161. /*
  162. * This routine is called by heapinit(), in crt32psx/winheap. We
  163. * would have a reference forwarder in psxdll.def, except RtlProcessHeap
  164. * is a macro and can't be forwarded.
  165. */
  166. void *
  167. GetProcessHeap(void)
  168. {
  169. return (void *)RtlProcessHeap();
  170. }