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.

195 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. stubs.c
  5. Abstract:
  6. TEMPORARY - stubs for unimplemented functions
  7. Author:
  8. Ellen Aycock-Wright (ellena) 15-Jul-1991
  9. Revision History:
  10. --*/
  11. #include <unistd.h>
  12. #include <signal.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <pwd.h>
  16. #include <setjmpex.h>
  17. #include <termios.h>
  18. #include <sys/stat.h>
  19. #include "psxdll.h"
  20. char *
  21. __cdecl
  22. ctermid(char *s)
  23. {
  24. static char returnspace[L_ctermid];
  25. if (NULL == s) {
  26. return strcpy(returnspace, "");
  27. }
  28. return strcpy(s, "");
  29. }
  30. int
  31. __cdecl
  32. setgid(gid_t gid)
  33. {
  34. if (gid == getgid()) {
  35. return 0;
  36. }
  37. errno = EPERM;
  38. return -1;
  39. }
  40. int
  41. __cdecl
  42. setuid(uid_t uid)
  43. {
  44. if (uid == getuid()) {
  45. return 0;
  46. }
  47. errno = EPERM;
  48. return -1;
  49. }
  50. char *
  51. __cdecl
  52. ttyname(int fildes)
  53. {
  54. static char s[7];
  55. s[0] = 0;
  56. return NULL;
  57. }
  58. _JBTYPE * __cdecl
  59. _sigjmp_store_mask(sigjmp_buf env, int save)
  60. {
  61. if (save) {
  62. env[_JBLEN] = 1;
  63. sigprocmask(SIG_SETMASK, 0, (void *)&env[_JBLEN + 1]);
  64. } else {
  65. env[_JBLEN] = 0;
  66. }
  67. return env;
  68. }
  69. void
  70. __cdecl
  71. siglongjmp(sigjmp_buf j, int val)
  72. {
  73. if (j[_JBLEN]) {
  74. (void)sigprocmask(SIG_SETMASK, (PVOID)&j[_JBLEN + 1], NULL);
  75. }
  76. longjmp((void *)&j[0], val);
  77. //NOTREACHED
  78. }
  79. int
  80. __cdecl
  81. cfsetispeed(struct termios *termios_p, speed_t speed)
  82. {
  83. termios_p->c_ispeed = speed;
  84. return 0;
  85. }
  86. int
  87. __cdecl
  88. cfsetospeed(struct termios *termios_p, speed_t speed)
  89. {
  90. termios_p->c_ospeed = speed;
  91. return 0;
  92. }
  93. speed_t
  94. __cdecl
  95. cfgetispeed(const struct termios *termios_p)
  96. {
  97. return termios_p->c_ispeed;
  98. }
  99. speed_t
  100. __cdecl
  101. cfgetospeed(const struct termios *termios_p)
  102. {
  103. return termios_p->c_ospeed;
  104. }
  105. int
  106. __cdecl
  107. system(const char *command)
  108. {
  109. pid_t pid;
  110. int status;
  111. char *shell;
  112. sigset_t saveblock;
  113. struct sigaction sa, saveintr, savequit;
  114. if (NULL == command) {
  115. return 0;
  116. }
  117. // XXX.mjb: should use an absolute path to sh, if there
  118. // was one, instead of $SHELL.
  119. shell = getenv("SHELL");
  120. if (NULL == shell) {
  121. return 0;
  122. }
  123. sa.sa_handler = SIG_IGN;
  124. sigemptyset(&sa.sa_mask);
  125. sa.sa_flags = 0;
  126. sigaction(SIGINT, &sa, &saveintr);
  127. sigaction(SIGQUIT, &sa, &savequit);
  128. sigaddset(&sa.sa_mask, SIGCHLD);
  129. sigprocmask(SIG_BLOCK, &sa.sa_mask, &saveblock);
  130. pid = fork();
  131. if (-1 == pid) {
  132. return -1;
  133. }
  134. if (0 == pid) {
  135. sigaction(SIGINT, &saveintr, NULL);
  136. sigaction(SIGQUIT, &savequit, NULL);
  137. sigprocmask(SIG_SETMASK, &saveblock, NULL);
  138. execl(shell, "sh", "-c", command, NULL);
  139. _exit(127);
  140. }
  141. if (-1 == waitpid(pid, &status, 0))
  142. status = -1;
  143. sigaction(SIGINT, &saveintr, NULL);
  144. sigaction(SIGQUIT, &savequit, NULL);
  145. sigprocmask(SIG_SETMASK, &saveblock, NULL);
  146. return status;
  147. }
  148. int __cdecl
  149. remove(const char *path)
  150. {
  151. struct stat st_buf;
  152. if (-1 == stat(path, &st_buf))
  153. return unlink(path);
  154. if (S_ISDIR(st_buf.st_mode)) {
  155. return rmdir(path);
  156. }
  157. return unlink(path);
  158. }