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.

934 lines
18 KiB

  1. package POSIX;
  2. use vars qw($VERSION @ISA %EXPORT_TAGS @EXPORT_OK $AUTOLOAD);
  3. use Carp;
  4. use AutoLoader;
  5. require Config;
  6. use Symbol;
  7. require Exporter;
  8. require DynaLoader;
  9. @ISA = qw(Exporter DynaLoader);
  10. $VERSION = "1.02" ;
  11. %EXPORT_TAGS = (
  12. assert_h => [qw(assert NDEBUG)],
  13. ctype_h => [qw(isalnum isalpha iscntrl isdigit isgraph islower
  14. isprint ispunct isspace isupper isxdigit tolower toupper)],
  15. dirent_h => [qw()],
  16. errno_h => [qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
  17. EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
  18. ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
  19. EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
  20. EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
  21. EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
  22. ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
  23. ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
  24. ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
  25. EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
  26. ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
  27. ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
  28. EUSERS EWOULDBLOCK EXDEV errno)],
  29. fcntl_h => [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
  30. F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK
  31. O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK
  32. O_RDONLY O_RDWR O_TRUNC O_WRONLY
  33. creat
  34. SEEK_CUR SEEK_END SEEK_SET
  35. S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
  36. S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID
  37. S_IWGRP S_IWOTH S_IWUSR)],
  38. float_h => [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
  39. DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
  40. DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP
  41. FLT_DIG FLT_EPSILON FLT_MANT_DIG
  42. FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
  43. FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP
  44. FLT_RADIX FLT_ROUNDS
  45. LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
  46. LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
  47. LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)],
  48. grp_h => [qw()],
  49. limits_h => [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
  50. INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON
  51. MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX
  52. PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN
  53. SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX
  54. ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX
  55. _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT
  56. _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX
  57. _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX
  58. _POSIX_STREAM_MAX _POSIX_TZNAME_MAX)],
  59. locale_h => [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC
  60. LC_TIME NULL localeconv setlocale)],
  61. math_h => [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
  62. frexp ldexp log10 modf pow sinh tan tanh)],
  63. pwd_h => [qw()],
  64. setjmp_h => [qw(longjmp setjmp siglongjmp sigsetjmp)],
  65. signal_h => [qw(SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK
  66. SA_RESETHAND SA_RESTART SA_SIGINFO SIGABRT SIGALRM
  67. SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL
  68. SIGPIPE SIGQUIT SIGSEGV SIGSTOP SIGTERM SIGTSTP SIGTTIN
  69. SIGTTOU SIGUSR1 SIGUSR2 SIG_BLOCK SIG_DFL SIG_ERR
  70. SIG_IGN SIG_SETMASK SIG_UNBLOCK raise sigaction signal
  71. sigpending sigprocmask sigsuspend)],
  72. stdarg_h => [qw()],
  73. stddef_h => [qw(NULL offsetof)],
  74. stdio_h => [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
  75. L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET
  76. STREAM_MAX TMP_MAX stderr stdin stdout
  77. clearerr fclose fdopen feof ferror fflush fgetc fgetpos
  78. fgets fopen fprintf fputc fputs fread freopen
  79. fscanf fseek fsetpos ftell fwrite getchar gets
  80. perror putc putchar puts remove rewind
  81. scanf setbuf setvbuf sscanf tmpfile tmpnam
  82. ungetc vfprintf vprintf vsprintf)],
  83. stdlib_h => [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
  84. abort atexit atof atoi atol bsearch calloc div
  85. free getenv labs ldiv malloc mblen mbstowcs mbtowc
  86. qsort realloc strtod strtol strtoul wcstombs wctomb)],
  87. string_h => [qw(NULL memchr memcmp memcpy memmove memset strcat
  88. strchr strcmp strcoll strcpy strcspn strerror strlen
  89. strncat strncmp strncpy strpbrk strrchr strspn strstr
  90. strtok strxfrm)],
  91. sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
  92. S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG
  93. S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
  94. fstat mkfifo)],
  95. sys_times_h => [qw()],
  96. sys_types_h => [qw()],
  97. sys_utsname_h => [qw(uname)],
  98. sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
  99. WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
  100. termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
  101. B300 B38400 B4800 B50 B600 B75 B9600 BRKINT CLOCAL
  102. CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB ECHO ECHOE ECHOK
  103. ECHONL HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR
  104. INLCR INPCK ISIG ISTRIP IXOFF IXON NCCS NOFLSH OPOST
  105. PARENB PARMRK PARODD TCIFLUSH TCIOFF TCIOFLUSH TCION
  106. TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW
  107. TOSTOP VEOF VEOL VERASE VINTR VKILL VMIN VQUIT VSTART
  108. VSTOP VSUSP VTIME
  109. cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
  110. tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
  111. time_h => [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
  112. difftime mktime strftime tzset tzname)],
  113. unistd_h => [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
  114. STRERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
  115. _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
  116. _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
  117. _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED
  118. _POSIX_JOB_CONTROL _POSIX_NO_TRUNC _POSIX_SAVED_IDS
  119. _POSIX_VDISABLE _POSIX_VERSION _SC_ARG_MAX
  120. _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
  121. _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_SAVED_IDS
  122. _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
  123. _exit access ctermid cuserid
  124. dup2 dup execl execle execlp execv execve execvp
  125. fpathconf getcwd getegid geteuid getgid getgroups
  126. getpid getuid isatty lseek pathconf pause setgid setpgid
  127. setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)],
  128. utime_h => [qw()],
  129. );
  130. Exporter::export_tags();
  131. @EXPORT_OK = qw(
  132. closedir opendir readdir rewinddir
  133. fcntl open
  134. getgrgid getgrnam
  135. atan2 cos exp log sin sqrt
  136. getpwnam getpwuid
  137. kill
  138. fileno getc printf rename sprintf
  139. abs exit rand srand system
  140. chmod mkdir stat umask
  141. times
  142. wait waitpid
  143. gmtime localtime time
  144. alarm chdir chown close fork getlogin getppid getpgrp link
  145. pipe read rmdir sleep unlink write
  146. utime
  147. nice
  148. );
  149. # Grandfather old foo_h form to new :foo_h form
  150. sub import {
  151. my $this = shift;
  152. my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_;
  153. local $Exporter::ExportLevel = 1;
  154. Exporter::import($this,@list);
  155. }
  156. bootstrap POSIX $VERSION;
  157. my $EINVAL = constant("EINVAL", 0);
  158. my $EAGAIN = constant("EAGAIN", 0);
  159. sub AUTOLOAD {
  160. if ($AUTOLOAD =~ /::(_?[a-z])/) {
  161. $AutoLoader::AUTOLOAD = $AUTOLOAD;
  162. goto &AutoLoader::AUTOLOAD
  163. }
  164. local $! = 0;
  165. my $constname = $AUTOLOAD;
  166. $constname =~ s/.*:://;
  167. my $val = constant($constname, @_ ? $_[0] : 0);
  168. if ($! == 0) {
  169. *$AUTOLOAD = sub { $val };
  170. }
  171. elsif ($! == $EAGAIN) { # Not really a constant, so always call.
  172. *$AUTOLOAD = sub { constant($constname, $_[0]) };
  173. }
  174. elsif ($! == $EINVAL) {
  175. croak "$constname is not a valid POSIX macro";
  176. }
  177. else {
  178. croak "Your vendor has not defined POSIX macro $constname, used";
  179. }
  180. goto &$AUTOLOAD;
  181. }
  182. sub usage {
  183. my ($mess) = @_;
  184. croak "Usage: POSIX::$mess";
  185. }
  186. sub redef {
  187. my ($mess) = @_;
  188. croak "Use method $mess instead";
  189. }
  190. sub unimpl {
  191. my ($mess) = @_;
  192. $mess =~ s/xxx//;
  193. croak "Unimplemented: POSIX::$mess";
  194. }
  195. ############################
  196. package POSIX::SigAction;
  197. sub new {
  198. bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3] || 0}, $_[0];
  199. }
  200. ############################
  201. package POSIX; # return to package POSIX so AutoSplit is happy
  202. 1;
  203. __END__
  204. sub assert {
  205. usage "assert(expr)" if @_ != 1;
  206. if (!$_[0]) {
  207. croak "Assertion failed";
  208. }
  209. }
  210. sub tolower {
  211. usage "tolower(string)" if @_ != 1;
  212. lc($_[0]);
  213. }
  214. sub toupper {
  215. usage "toupper(string)" if @_ != 1;
  216. uc($_[0]);
  217. }
  218. sub closedir {
  219. usage "closedir(dirhandle)" if @_ != 1;
  220. CORE::closedir($_[0]);
  221. }
  222. sub opendir {
  223. usage "opendir(directory)" if @_ != 1;
  224. my $dirhandle = gensym;
  225. CORE::opendir($dirhandle, $_[0])
  226. ? $dirhandle
  227. : undef;
  228. }
  229. sub readdir {
  230. usage "readdir(dirhandle)" if @_ != 1;
  231. CORE::readdir($_[0]);
  232. }
  233. sub rewinddir {
  234. usage "rewinddir(dirhandle)" if @_ != 1;
  235. CORE::rewinddir($_[0]);
  236. }
  237. sub errno {
  238. usage "errno()" if @_ != 0;
  239. $! + 0;
  240. }
  241. sub creat {
  242. usage "creat(filename, mode)" if @_ != 2;
  243. &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
  244. }
  245. sub fcntl {
  246. usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
  247. CORE::fcntl($_[0], $_[1], $_[2]);
  248. }
  249. sub getgrgid {
  250. usage "getgrgid(gid)" if @_ != 1;
  251. CORE::getgrgid($_[0]);
  252. }
  253. sub getgrnam {
  254. usage "getgrnam(name)" if @_ != 1;
  255. CORE::getgrnam($_[0]);
  256. }
  257. sub atan2 {
  258. usage "atan2(x,y)" if @_ != 2;
  259. CORE::atan2($_[0], $_[1]);
  260. }
  261. sub cos {
  262. usage "cos(x)" if @_ != 1;
  263. CORE::cos($_[0]);
  264. }
  265. sub exp {
  266. usage "exp(x)" if @_ != 1;
  267. CORE::exp($_[0]);
  268. }
  269. sub fabs {
  270. usage "fabs(x)" if @_ != 1;
  271. CORE::abs($_[0]);
  272. }
  273. sub log {
  274. usage "log(x)" if @_ != 1;
  275. CORE::log($_[0]);
  276. }
  277. sub pow {
  278. usage "pow(x,exponent)" if @_ != 2;
  279. $_[0] ** $_[1];
  280. }
  281. sub sin {
  282. usage "sin(x)" if @_ != 1;
  283. CORE::sin($_[0]);
  284. }
  285. sub sqrt {
  286. usage "sqrt(x)" if @_ != 1;
  287. CORE::sqrt($_[0]);
  288. }
  289. sub getpwnam {
  290. usage "getpwnam(name)" if @_ != 1;
  291. CORE::getpwnam($_[0]);
  292. }
  293. sub getpwuid {
  294. usage "getpwuid(uid)" if @_ != 1;
  295. CORE::getpwuid($_[0]);
  296. }
  297. sub longjmp {
  298. unimpl "longjmp() is C-specific: use die instead";
  299. }
  300. sub setjmp {
  301. unimpl "setjmp() is C-specific: use eval {} instead";
  302. }
  303. sub siglongjmp {
  304. unimpl "siglongjmp() is C-specific: use die instead";
  305. }
  306. sub sigsetjmp {
  307. unimpl "sigsetjmp() is C-specific: use eval {} instead";
  308. }
  309. sub kill {
  310. usage "kill(pid, sig)" if @_ != 2;
  311. CORE::kill $_[1], $_[0];
  312. }
  313. sub raise {
  314. usage "raise(sig)" if @_ != 1;
  315. CORE::kill $_[0], $$; # Is this good enough?
  316. }
  317. sub offsetof {
  318. unimpl "offsetof() is C-specific, stopped";
  319. }
  320. sub clearerr {
  321. redef "IO::Handle::clearerr()";
  322. }
  323. sub fclose {
  324. redef "IO::Handle::close()";
  325. }
  326. sub fdopen {
  327. redef "IO::Handle::new_from_fd()";
  328. }
  329. sub feof {
  330. redef "IO::Handle::eof()";
  331. }
  332. sub fgetc {
  333. redef "IO::Handle::getc()";
  334. }
  335. sub fgets {
  336. redef "IO::Handle::gets()";
  337. }
  338. sub fileno {
  339. redef "IO::Handle::fileno()";
  340. }
  341. sub fopen {
  342. redef "IO::File::open()";
  343. }
  344. sub fprintf {
  345. unimpl "fprintf() is C-specific--use printf instead";
  346. }
  347. sub fputc {
  348. unimpl "fputc() is C-specific--use print instead";
  349. }
  350. sub fputs {
  351. unimpl "fputs() is C-specific--use print instead";
  352. }
  353. sub fread {
  354. unimpl "fread() is C-specific--use read instead";
  355. }
  356. sub freopen {
  357. unimpl "freopen() is C-specific--use open instead";
  358. }
  359. sub fscanf {
  360. unimpl "fscanf() is C-specific--use <> and regular expressions instead";
  361. }
  362. sub fseek {
  363. redef "IO::Seekable::seek()";
  364. }
  365. sub ferror {
  366. redef "IO::Handle::error()";
  367. }
  368. sub fflush {
  369. redef "IO::Handle::flush()";
  370. }
  371. sub fgetpos {
  372. redef "IO::Seekable::getpos()";
  373. }
  374. sub fsetpos {
  375. redef "IO::Seekable::setpos()";
  376. }
  377. sub ftell {
  378. redef "IO::Seekable::tell()";
  379. }
  380. sub fwrite {
  381. unimpl "fwrite() is C-specific--use print instead";
  382. }
  383. sub getc {
  384. usage "getc(handle)" if @_ != 1;
  385. CORE::getc($_[0]);
  386. }
  387. sub getchar {
  388. usage "getchar()" if @_ != 0;
  389. CORE::getc(STDIN);
  390. }
  391. sub gets {
  392. usage "gets()" if @_ != 0;
  393. scalar <STDIN>;
  394. }
  395. sub perror {
  396. print STDERR "@_: " if @_;
  397. print STDERR $!,"\n";
  398. }
  399. sub printf {
  400. usage "printf(pattern, args...)" if @_ < 1;
  401. CORE::printf STDOUT @_;
  402. }
  403. sub putc {
  404. unimpl "putc() is C-specific--use print instead";
  405. }
  406. sub putchar {
  407. unimpl "putchar() is C-specific--use print instead";
  408. }
  409. sub puts {
  410. unimpl "puts() is C-specific--use print instead";
  411. }
  412. sub remove {
  413. usage "remove(filename)" if @_ != 1;
  414. CORE::unlink($_[0]);
  415. }
  416. sub rename {
  417. usage "rename(oldfilename, newfilename)" if @_ != 2;
  418. CORE::rename($_[0], $_[1]);
  419. }
  420. sub rewind {
  421. usage "rewind(filehandle)" if @_ != 1;
  422. CORE::seek($_[0],0,0);
  423. }
  424. sub scanf {
  425. unimpl "scanf() is C-specific--use <> and regular expressions instead";
  426. }
  427. sub sprintf {
  428. usage "sprintf(pattern,args)" if @_ == 0;
  429. CORE::sprintf(shift,@_);
  430. }
  431. sub sscanf {
  432. unimpl "sscanf() is C-specific--use regular expressions instead";
  433. }
  434. sub tmpfile {
  435. redef "IO::File::new_tmpfile()";
  436. }
  437. sub ungetc {
  438. redef "IO::Handle::ungetc()";
  439. }
  440. sub vfprintf {
  441. unimpl "vfprintf() is C-specific";
  442. }
  443. sub vprintf {
  444. unimpl "vprintf() is C-specific";
  445. }
  446. sub vsprintf {
  447. unimpl "vsprintf() is C-specific";
  448. }
  449. sub abs {
  450. usage "abs(x)" if @_ != 1;
  451. CORE::abs($_[0]);
  452. }
  453. sub atexit {
  454. unimpl "atexit() is C-specific: use END {} instead";
  455. }
  456. sub atof {
  457. unimpl "atof() is C-specific, stopped";
  458. }
  459. sub atoi {
  460. unimpl "atoi() is C-specific, stopped";
  461. }
  462. sub atol {
  463. unimpl "atol() is C-specific, stopped";
  464. }
  465. sub bsearch {
  466. unimpl "bsearch() not supplied";
  467. }
  468. sub calloc {
  469. unimpl "calloc() is C-specific, stopped";
  470. }
  471. sub div {
  472. unimpl "div() is C-specific, stopped";
  473. }
  474. sub exit {
  475. usage "exit(status)" if @_ != 1;
  476. CORE::exit($_[0]);
  477. }
  478. sub free {
  479. unimpl "free() is C-specific, stopped";
  480. }
  481. sub getenv {
  482. usage "getenv(name)" if @_ != 1;
  483. $ENV{$_[0]};
  484. }
  485. sub labs {
  486. unimpl "labs() is C-specific, use abs instead";
  487. }
  488. sub ldiv {
  489. unimpl "ldiv() is C-specific, use / and int instead";
  490. }
  491. sub malloc {
  492. unimpl "malloc() is C-specific, stopped";
  493. }
  494. sub qsort {
  495. unimpl "qsort() is C-specific, use sort instead";
  496. }
  497. sub rand {
  498. unimpl "rand() is non-portable, use Perl's rand instead";
  499. }
  500. sub realloc {
  501. unimpl "realloc() is C-specific, stopped";
  502. }
  503. sub srand {
  504. unimpl "srand()";
  505. }
  506. sub system {
  507. usage "system(command)" if @_ != 1;
  508. CORE::system($_[0]);
  509. }
  510. sub memchr {
  511. unimpl "memchr() is C-specific, use index() instead";
  512. }
  513. sub memcmp {
  514. unimpl "memcmp() is C-specific, use eq instead";
  515. }
  516. sub memcpy {
  517. unimpl "memcpy() is C-specific, use = instead";
  518. }
  519. sub memmove {
  520. unimpl "memmove() is C-specific, use = instead";
  521. }
  522. sub memset {
  523. unimpl "memset() is C-specific, use x instead";
  524. }
  525. sub strcat {
  526. unimpl "strcat() is C-specific, use .= instead";
  527. }
  528. sub strchr {
  529. unimpl "strchr() is C-specific, use index() instead";
  530. }
  531. sub strcmp {
  532. unimpl "strcmp() is C-specific, use eq instead";
  533. }
  534. sub strcpy {
  535. unimpl "strcpy() is C-specific, use = instead";
  536. }
  537. sub strcspn {
  538. unimpl "strcspn() is C-specific, use regular expressions instead";
  539. }
  540. sub strerror {
  541. usage "strerror(errno)" if @_ != 1;
  542. local $! = $_[0];
  543. $! . "";
  544. }
  545. sub strlen {
  546. unimpl "strlen() is C-specific, use length instead";
  547. }
  548. sub strncat {
  549. unimpl "strncat() is C-specific, use .= instead";
  550. }
  551. sub strncmp {
  552. unimpl "strncmp() is C-specific, use eq instead";
  553. }
  554. sub strncpy {
  555. unimpl "strncpy() is C-specific, use = instead";
  556. }
  557. sub strpbrk {
  558. unimpl "strpbrk() is C-specific, stopped";
  559. }
  560. sub strrchr {
  561. unimpl "strrchr() is C-specific, use rindex() instead";
  562. }
  563. sub strspn {
  564. unimpl "strspn() is C-specific, stopped";
  565. }
  566. sub strstr {
  567. usage "strstr(big, little)" if @_ != 2;
  568. CORE::index($_[0], $_[1]);
  569. }
  570. sub strtok {
  571. unimpl "strtok() is C-specific, stopped";
  572. }
  573. sub chmod {
  574. usage "chmod(mode, filename)" if @_ != 2;
  575. CORE::chmod($_[0], $_[1]);
  576. }
  577. sub fstat {
  578. usage "fstat(fd)" if @_ != 1;
  579. local *TMP;
  580. open(TMP, "<&$_[0]"); # Gross.
  581. my @l = CORE::stat(TMP);
  582. close(TMP);
  583. @l;
  584. }
  585. sub mkdir {
  586. usage "mkdir(directoryname, mode)" if @_ != 2;
  587. CORE::mkdir($_[0], $_[1]);
  588. }
  589. sub stat {
  590. usage "stat(filename)" if @_ != 1;
  591. CORE::stat($_[0]);
  592. }
  593. sub umask {
  594. usage "umask(mask)" if @_ != 1;
  595. CORE::umask($_[0]);
  596. }
  597. sub wait {
  598. usage "wait()" if @_ != 0;
  599. CORE::wait();
  600. }
  601. sub waitpid {
  602. usage "waitpid(pid, options)" if @_ != 2;
  603. CORE::waitpid($_[0], $_[1]);
  604. }
  605. sub gmtime {
  606. usage "gmtime(time)" if @_ != 1;
  607. CORE::gmtime($_[0]);
  608. }
  609. sub localtime {
  610. usage "localtime(time)" if @_ != 1;
  611. CORE::localtime($_[0]);
  612. }
  613. sub time {
  614. usage "time()" if @_ != 0;
  615. CORE::time;
  616. }
  617. sub alarm {
  618. usage "alarm(seconds)" if @_ != 1;
  619. CORE::alarm($_[0]);
  620. }
  621. sub chdir {
  622. usage "chdir(directory)" if @_ != 1;
  623. CORE::chdir($_[0]);
  624. }
  625. sub chown {
  626. usage "chown(filename, uid, gid)" if @_ != 3;
  627. CORE::chown($_[0], $_[1], $_[2]);
  628. }
  629. sub execl {
  630. unimpl "execl() is C-specific, stopped";
  631. }
  632. sub execle {
  633. unimpl "execle() is C-specific, stopped";
  634. }
  635. sub execlp {
  636. unimpl "execlp() is C-specific, stopped";
  637. }
  638. sub execv {
  639. unimpl "execv() is C-specific, stopped";
  640. }
  641. sub execve {
  642. unimpl "execve() is C-specific, stopped";
  643. }
  644. sub execvp {
  645. unimpl "execvp() is C-specific, stopped";
  646. }
  647. sub fork {
  648. usage "fork()" if @_ != 0;
  649. CORE::fork;
  650. }
  651. sub getcwd
  652. {
  653. usage "getcwd()" if @_ != 0;
  654. if ($^O eq 'MSWin32') {
  655. # this perhaps applies to everyone else also?
  656. require Cwd;
  657. $cwd = &Cwd::cwd;
  658. }
  659. else {
  660. chop($cwd = `pwd`);
  661. }
  662. $cwd;
  663. }
  664. sub getegid {
  665. usage "getegid()" if @_ != 0;
  666. $) + 0;
  667. }
  668. sub geteuid {
  669. usage "geteuid()" if @_ != 0;
  670. $> + 0;
  671. }
  672. sub getgid {
  673. usage "getgid()" if @_ != 0;
  674. $( + 0;
  675. }
  676. sub getgroups {
  677. usage "getgroups()" if @_ != 0;
  678. my %seen;
  679. grep(!$seen{$_}++, split(' ', $) ));
  680. }
  681. sub getlogin {
  682. usage "getlogin()" if @_ != 0;
  683. CORE::getlogin();
  684. }
  685. sub getpgrp {
  686. usage "getpgrp()" if @_ != 0;
  687. CORE::getpgrp;
  688. }
  689. sub getpid {
  690. usage "getpid()" if @_ != 0;
  691. $$;
  692. }
  693. sub getppid {
  694. usage "getppid()" if @_ != 0;
  695. CORE::getppid;
  696. }
  697. sub getuid {
  698. usage "getuid()" if @_ != 0;
  699. $<;
  700. }
  701. sub isatty {
  702. usage "isatty(filehandle)" if @_ != 1;
  703. -t $_[0];
  704. }
  705. sub link {
  706. usage "link(oldfilename, newfilename)" if @_ != 2;
  707. CORE::link($_[0], $_[1]);
  708. }
  709. sub rmdir {
  710. usage "rmdir(directoryname)" if @_ != 1;
  711. CORE::rmdir($_[0]);
  712. }
  713. sub setbuf {
  714. redef "IO::Handle::setbuf()";
  715. }
  716. sub setgid {
  717. usage "setgid(gid)" if @_ != 1;
  718. $( = $_[0];
  719. }
  720. sub setuid {
  721. usage "setuid(uid)" if @_ != 1;
  722. $< = $_[0];
  723. }
  724. sub setvbuf {
  725. redef "IO::Handle::setvbuf()";
  726. }
  727. sub sleep {
  728. usage "sleep(seconds)" if @_ != 1;
  729. CORE::sleep($_[0]);
  730. }
  731. sub unlink {
  732. usage "unlink(filename)" if @_ != 1;
  733. CORE::unlink($_[0]);
  734. }
  735. sub utime {
  736. usage "utime(filename, atime, mtime)" if @_ != 3;
  737. CORE::utime($_[1], $_[2], $_[0]);
  738. }