1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 /* POSIX module implementation */
27 /* This file is also used for Windows NT. In that case the module
28 actually calls itself 'nt', not 'posix', and a few functions are
29 either unimplemented or implemented differently. The source
30 assumes that for Windows NT, the macro 'NT' is defined independent
31 of the compiler used. Different compilers define their own feature
32 test macro, e.g. '__BORLANDC__' or '_MSCVER'. */
34 /* For MS-DOS and Windows 3.x, use ../Dos/dosmodule.c */
36 #include "allobjects.h"
37 #include "modsupport.h"
42 #include <sys/types.h>
44 #ifdef HAVE_SYS_WAIT_H
45 #include <sys/wait.h> /* For WNOHANG */
48 #include "mytime.h" /* For clock_t on some systems */
52 #endif /* HAVE_FCNTL_H */
58 #if !defined(NT) || defined(__BORLANDC__)
59 /* Unix functions that the configure script doesn't check for
60 and that aren't easily available under NT except with Borland C */
61 #define HAVE_GETEGID 1
62 #define HAVE_GETEUID 1
64 #define HAVE_GETPPID 1
68 #define HAVE_OPENDIR 1
80 /* NeXT's <unistd.h> and <utime.h> aren't worth much */
83 /* #undef HAVE_GETCWD */
87 /* XXX These are for SunOS4.1.3 but shouldn't hurt elsewhere */
92 #else /* !HAVE_UNISTD_H */
93 extern int mkdir
PROTO((const char *, mode_t
));
94 extern int chdir
PROTO((const char *));
95 extern int rmdir
PROTO((const char *));
96 extern int chmod
PROTO((const char *, mode_t
));
97 extern int chown
PROTO((const char *, uid_t
, gid_t
));
98 extern char *getcwd
PROTO((char *, int));
99 extern char *strerror
PROTO((int));
100 extern int link
PROTO((const char *, const char *));
101 extern int rename
PROTO((const char *, const char *));
102 extern int stat
PROTO((const char *, struct stat
*));
103 extern int unlink
PROTO((const char *));
104 extern int pclose
PROTO((FILE *));
106 extern int symlink
PROTO((const char *, const char *));
107 #endif /* HAVE_SYMLINK */
109 extern int lstat
PROTO((const char *, struct stat
*));
110 #endif /* HAVE_LSTAT */
111 #endif /* !HAVE_UNISTD_H */
117 #endif /* HAVE_UTIME_H */
119 #ifdef HAVE_SYS_UTIME_H
120 #include <sys/utime.h>
121 #define HAVE_UTIME_H /* pretend we do for the rest of this file */
122 #endif /* HAVE_SYS_UTIME_H */
124 #ifdef HAVE_SYS_TIMES_H
125 #include <sys/times.h>
126 #endif /* HAVE_SYS_TIMES_H */
128 #ifdef HAVE_SYS_PARAM_H
129 #include <sys/param.h>
130 #endif /* HAVE_SYS_PARAM_H */
132 #ifdef HAVE_SYS_UTSNAME_H
133 #include <sys/utsname.h>
134 #endif /* HAVE_SYS_UTSNAME_H */
137 #define MAXPATHLEN 1024
138 #endif /* MAXPATHLEN */
142 #define NAMLEN(dirent) strlen((dirent)->d_name)
144 #define dirent direct
145 #define NAMLEN(dirent) (dirent)->d_namlen
146 #ifdef HAVE_SYS_NDIR_H
147 #include <sys/ndir.h>
149 #ifdef HAVE_SYS_DIR_H
163 #define pclose _pclose
170 /* Return a dictionary corresponding to the POSIX environment table */
173 extern char **environ
;
186 /* XXX This part ignores errors */
187 for (e
= environ
; *e
!= NULL
; e
++) {
189 char *p
= strchr(*e
, '=');
192 v
= newstringobject(p
+1);
196 (void) dictinsert(d
, *e
, v
);
204 static object
*PosixError
; /* Exception posix.error */
206 /* Set a POSIX-specific error from errno, and return NULL */
208 static object
* posix_error()
210 return err_errno(PosixError
);
214 /* POSIX generic methods */
217 posix_1str(args
, func
)
219 int (*func
) FPROTO((const char *));
223 if (!getargs(args
, "s", &path1
))
226 res
= (*func
)(path1
);
229 return posix_error();
235 posix_2str(args
, func
)
237 int (*func
) FPROTO((const char *, const char *));
241 if (!getargs(args
, "(ss)", &path1
, &path2
))
244 res
= (*func
)(path1
, path2
);
247 return posix_error();
253 posix_strint(args
, func
)
255 int (*func
) FPROTO((const char *, int));
260 if (!getargs(args
, "(si)", &path
, &i
))
263 res
= (*func
)(path
, i
);
266 return posix_error();
272 posix_strintint(args
, func
)
274 int (*func
) FPROTO((const char *, int, int));
279 if (!getargs(args
, "(sii)", &path
, &i
, &i2
))
282 res
= (*func
)(path
, i
, i2
);
285 return posix_error();
291 posix_do_stat(self
, args
, statfunc
)
294 int (*statfunc
) FPROTO((const char *, struct stat
*));
299 if (!getargs(args
, "s", &path
))
302 res
= (*statfunc
)(path
, &st
);
305 return posix_error();
306 return mkvalue("(llllllllll)",
323 posix_chdir(self
, args
)
327 return posix_1str(args
, chdir
);
331 posix_chmod(self
, args
)
335 return posix_strint(args
, chmod
);
340 posix_chown(self
, args
)
344 return posix_strintint(args
, chown
);
346 #endif /* HAVE_CHOWN */
350 posix_getcwd(self
, args
)
359 res
= getcwd(buf
, sizeof buf
);
362 return posix_error();
363 return newstringobject(buf
);
369 posix_link(self
, args
)
373 return posix_2str(args
, link
);
375 #endif /* HAVE_LINK */
378 posix_listdir(self
, args
)
382 #if defined(NT) && !defined(HAVE_OPENDIR)
388 WIN32_FIND_DATA FileData
;
389 char namebuf
[MAX_PATH
+5];
391 if (!getargs(args
, "s#", &name
, &len
))
393 if (len
>= MAX_PATH
) {
394 err_setstr(ValueError
, "path too long");
397 strcpy(namebuf
, name
);
398 if (namebuf
[len
-1] != '/' && namebuf
[len
-1] != '\\')
399 namebuf
[len
++] = '/';
400 strcpy(namebuf
+ len
, "*.*");
402 if ((d
= newlistobject(0)) == NULL
)
405 hFindFile
= FindFirstFile(namebuf
, &FileData
);
406 if (hFindFile
== INVALID_HANDLE_VALUE
) {
407 errno
= GetLastError();
408 return posix_error();
411 v
= newstringobject(FileData
.cFileName
);
417 if (addlistitem(d
, v
) != 0) {
424 } while (FindNextFile(hFindFile
, &FileData
) == TRUE
);
426 if (FindClose(hFindFile
) == FALSE
) {
427 errno
= GetLastError();
428 return posix_error();
439 if (!getargs(args
, "s", &name
))
442 if ((dirp
= opendir(name
)) == NULL
) {
444 return posix_error();
446 if ((d
= newlistobject(0)) == NULL
) {
451 while ((ep
= readdir(dirp
)) != NULL
) {
452 v
= newsizedstringobject(ep
->d_name
, NAMLEN(ep
));
458 if (addlistitem(d
, v
) != 0) {
475 posix_mkdir(self
, args
)
479 return posix_strint(args
, mkdir
);
484 posix_nice(self
, args
)
488 int increment
, value
;
490 if (!getargs(args
, "i", &increment
))
492 value
= nice(increment
);
494 return posix_error();
495 return newintobject((long) value
);
497 #endif /* HAVE_NICE */
500 posix_rename(self
, args
)
504 return posix_2str(args
, rename
);
508 posix_rmdir(self
, args
)
512 return posix_1str(args
, rmdir
);
516 posix_stat(self
, args
)
520 return posix_do_stat(self
, args
, stat
);
524 posix_system(self
, args
)
530 if (!getargs(args
, "s", &command
))
533 sts
= system(command
);
535 return newintobject(sts
);
539 posix_umask(self
, args
)
544 if (!getintarg(args
, &i
))
548 return posix_error();
549 return newintobject((long)i
);
553 posix_unlink(self
, args
)
557 return posix_1str(args
, unlink
);
562 posix_uname(self
, args
)
575 return posix_error();
576 return mkvalue("(sssss)",
583 #endif /* HAVE_UNAME */
586 posix_utime(self
, args
)
596 #define ATIME buf.actime
597 #define MTIME buf.modtime
598 #define UTIME_ARG &buf
599 #else /* HAVE_UTIME_H */
603 #define UTIME_ARG buf
604 #endif /* HAVE_UTIME_H */
606 if (!getargs(args
, "(s(ll))", &path
, &atime
, &mtime
))
611 res
= utime(path
, UTIME_ARG
);
614 return posix_error();
623 /* Process operations */
626 posix__exit(self
, args
)
631 if (!getintarg(args
, &sts
))
638 posix_execv(self
, args
)
646 object
*(*getitem
) PROTO((object
*, int));
648 /* execv has two arguments: (path, argv), where
649 argv is a list or tuple of strings. */
651 if (!getargs(args
, "(sO)", &path
, &argv
))
653 if (is_listobject(argv
)) {
654 argc
= getlistsize(argv
);
655 getitem
= getlistitem
;
657 else if (is_tupleobject(argv
)) {
658 argc
= gettuplesize(argv
);
659 getitem
= gettupleitem
;
667 argvlist
= NEW(char *, argc
+1);
668 if (argvlist
== NULL
)
670 for (i
= 0; i
< argc
; i
++) {
671 if (!getargs((*getitem
)(argv
, i
), "s", &argvlist
[i
])) {
676 argvlist
[argc
] = NULL
;
678 #ifdef BAD_EXEC_PROTOTYPES
679 execv(path
, (const char **) argvlist
);
680 #else /* BAD_EXEC_PROTOTYPES */
681 execv(path
, argvlist
);
682 #endif /* BAD_EXEC_PROTOTYPES */
684 /* If we get here it's definitely an error */
687 return posix_error();
691 posix_execve(self
, args
)
700 int i
, pos
, argc
, envc
;
701 object
*(*getitem
) PROTO((object
*, int));
703 /* execve has three arguments: (path, argv, env), where
704 argv is a list or tuple of strings and env is a dictionary
705 like posix.environ. */
707 if (!getargs(args
, "(sOO)", &path
, &argv
, &env
))
709 if (is_listobject(argv
)) {
710 argc
= getlistsize(argv
);
711 getitem
= getlistitem
;
713 else if (is_tupleobject(argv
)) {
714 argc
= gettuplesize(argv
);
715 getitem
= gettupleitem
;
718 err_setstr(TypeError
, "argv must be tuple or list");
721 if (!is_dictobject(env
)) {
722 err_setstr(TypeError
, "env must be dictionary");
726 argvlist
= NEW(char *, argc
+1);
727 if (argvlist
== NULL
) {
731 for (i
= 0; i
< argc
; i
++) {
732 if (!getargs((*getitem
)(argv
, i
),
733 "s;argv must be list of strings",
738 argvlist
[argc
] = NULL
;
740 i
= getmappingsize(env
);
741 envlist
= NEW(char *, i
+ 1);
742 if (envlist
== NULL
) {
748 while (mappinggetnext(env
, &pos
, &key
, &val
)) {
750 if (!getargs(key
, "s;non-string key in env", &k
) ||
751 !getargs(val
, "s;non-string value in env", &v
)) {
754 p
= NEW(char, getstringsize(key
) + getstringsize(val
) + 2);
759 sprintf(p
, "%s=%s", k
, v
);
765 #ifdef BAD_EXEC_PROTOTYPES
766 execve(path
, (const char **)argvlist
, envlist
);
767 #else /* BAD_EXEC_PROTOTYPES */
768 execve(path
, argvlist
, envlist
);
769 #endif /* BAD_EXEC_PROTOTYPES */
771 /* If we get here it's definitely an error */
773 (void) posix_error();
787 posix_fork(self
, args
)
796 return posix_error();
797 return newintobject((long)pid
);
803 posix_getegid(self
, args
)
809 return newintobject((long)getegid());
815 posix_geteuid(self
, args
)
821 return newintobject((long)geteuid());
827 posix_getgid(self
, args
)
833 return newintobject((long)getgid());
838 posix_getpid(self
, args
)
844 return newintobject((long)getpid());
849 posix_getpgrp(self
, args
)
855 #ifdef GETPGRP_HAVE_ARG
856 return newintobject((long)getpgrp(0));
857 #else /* GETPGRP_HAVE_ARG */
858 return newintobject((long)getpgrp());
859 #endif /* GETPGRP_HAVE_ARG */
861 #endif /* HAVE_GETPGRP */
865 posix_setpgrp(self
, args
)
871 #ifdef SETPGRP_HAVE_ARG
872 if (setpgrp(0, 0) < 0)
873 #else /* SETPGRP_HAVE_ARG */
875 #endif /* SETPGRP_HAVE_ARG */
876 return posix_error();
881 #endif /* HAVE_SETPGRP */
885 posix_getppid(self
, args
)
891 return newintobject((long)getppid());
897 posix_getuid(self
, args
)
903 return newintobject((long)getuid());
909 posix_kill(self
, args
)
914 if (!getargs(args
, "(ii)", &pid
, &sig
))
916 if (kill(pid
, sig
) == -1)
917 return posix_error();
924 posix_popen(self
, args
)
933 if (!newgetargs(args
, "s|si", &name
, &mode
, &bufsize
))
936 fp
= popen(name
, mode
);
939 return posix_error();
940 f
= newopenfileobject(fp
, name
, mode
, pclose
);
942 setfilebufsize(f
, bufsize
);
948 posix_setuid(self
, args
)
953 if (!getargs(args
, "i", &uid
))
956 return posix_error();
960 #endif /* HAVE_SETUID */
964 posix_setgid(self
, args
)
969 if (!getargs(args
, "i", &gid
))
972 return posix_error();
976 #endif /* HAVE_SETGID */
980 posix_waitpid(self
, args
)
984 int pid
, options
, sts
;
985 if (!getargs(args
, "(ii)", &pid
, &options
))
988 pid
= waitpid(pid
, &sts
, options
);
991 return posix_error();
993 return mkvalue("ii", pid
, sts
);
995 #endif /* HAVE_WAITPID */
999 posix_wait(self
, args
)
1008 return posix_error();
1010 return mkvalue("ii", pid
, sts
);
1015 posix_lstat(self
, args
)
1020 return posix_do_stat(self
, args
, lstat
);
1021 #else /* !HAVE_LSTAT */
1022 return posix_do_stat(self
, args
, stat
);
1023 #endif /* !HAVE_LSTAT */
1026 #ifdef HAVE_READLINK
1028 posix_readlink(self
, args
)
1032 char buf
[MAXPATHLEN
];
1035 if (!getargs(args
, "s", &path
))
1038 n
= readlink(path
, buf
, (int) sizeof buf
);
1041 return posix_error();
1042 return newsizedstringobject(buf
, n
);
1044 #endif /* HAVE_READLINK */
1048 posix_symlink(self
, args
)
1052 return posix_2str(args
, symlink
);
1054 #endif /* HAVE_SYMLINK */
1058 #define HZ 60 /* Universal constant :-) */
1061 posix_times(self
, args
)
1067 if (!getnoarg(args
))
1071 if (c
== (clock_t) -1)
1072 return posix_error();
1073 return mkvalue("dddd",
1074 (double)t
.tms_utime
/ HZ
,
1075 (double)t
.tms_stime
/ HZ
,
1076 (double)t
.tms_cutime
/ HZ
,
1077 (double)t
.tms_cstime
/ HZ
);
1079 #endif /* HAVE_TIMES */
1080 #if defined(NT) && !defined(HAVE_TIMES)
1081 #define HAVE_TIMES /* so the method table will pick it up */
1083 posix_times(self
, args
)
1087 FILETIME create
, exit
, kernel
, user
;
1089 if (!getnoarg(args
))
1091 hProc
= GetCurrentProcess();
1092 GetProcessTimes(hProc
,&create
, &exit
, &kernel
, &user
);
1093 return mkvalue("dddd",
1094 (double)(kernel
.dwHighDateTime
*2E32
+kernel
.dwLowDateTime
) / 2E6
,
1095 (double)(user
.dwHighDateTime
*2E32
+user
.dwLowDateTime
) / 2E6
,
1103 posix_setsid(self
, args
)
1107 if (!getnoarg(args
))
1110 return posix_error();
1114 #endif /* HAVE_SETSID */
1118 posix_setpgid(self
, args
)
1123 if (!getargs(args
, "(ii)", &pid
, &pgrp
))
1125 if (setpgid(pid
, pgrp
) < 0)
1126 return posix_error();
1130 #endif /* HAVE_SETPGID */
1132 #ifdef HAVE_TCGETPGRP
1134 posix_tcgetpgrp(self
, args
)
1139 if (!getargs(args
, "i", &fd
))
1141 pgid
= tcgetpgrp(fd
);
1143 return posix_error();
1144 return newintobject((long)pgid
);
1146 #endif /* HAVE_TCGETPGRP */
1148 #ifdef HAVE_TCSETPGRP
1150 posix_tcsetpgrp(self
, args
)
1155 if (!getargs(args
, "(ii)", &fd
, &pgid
))
1157 if (tcsetpgrp(fd
, pgid
) < 0)
1158 return posix_error();
1162 #endif /* HAVE_TCSETPGRP */
1164 /* Functions acting on file descriptors */
1167 posix_open(self
, args
)
1175 if (!getargs(args
, "(si)", &file
, &flag
)) {
1177 if (!getargs(args
, "(sii)", &file
, &flag
, &mode
))
1181 fd
= open(file
, flag
, mode
);
1184 return posix_error();
1185 return newintobject((long)fd
);
1189 posix_close(self
, args
)
1194 if (!getargs(args
, "i", &fd
))
1200 return posix_error();
1206 posix_dup(self
, args
)
1211 if (!getargs(args
, "i", &fd
))
1217 return posix_error();
1218 return newintobject((long)fd
);
1222 posix_dup2(self
, args
)
1227 if (!getargs(args
, "(ii)", &fd
, &fd2
))
1230 res
= dup2(fd
, fd2
);
1233 return posix_error();
1239 posix_lseek(self
, args
)
1245 if (!getargs(args
, "(ili)", &fd
, &pos
, &how
))
1248 /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */
1250 case 0: how
= SEEK_SET
; break;
1251 case 1: how
= SEEK_CUR
; break;
1252 case 2: how
= SEEK_END
; break;
1254 #endif /* SEEK_END */
1256 res
= lseek(fd
, pos
, how
);
1259 return posix_error();
1260 return newintobject(res
);
1264 posix_read(self
, args
)
1270 if (!getargs(args
, "(ii)", &fd
, &size
))
1272 buffer
= newsizedstringobject((char *)NULL
, size
);
1276 size
= read(fd
, getstringvalue(buffer
), size
);
1280 return posix_error();
1282 resizestring(&buffer
, size
);
1287 posix_write(self
, args
)
1293 if (!getargs(args
, "(is#)", &fd
, &buffer
, &size
))
1296 size
= write(fd
, buffer
, size
);
1299 return posix_error();
1300 return newintobject((long)size
);
1304 posix_fstat(self
, args
)
1311 if (!getargs(args
, "i", &fd
))
1314 res
= fstat(fd
, &st
);
1317 return posix_error();
1318 return mkvalue("(llllllllll)",
1332 posix_fdopen(self
, args
)
1336 extern int fclose
PROTO((FILE *));
1342 if (!newgetargs(args
, "i|si", &fd
, &mode
, &bufsize
))
1345 fp
= fdopen(fd
, mode
);
1348 return posix_error();
1349 f
= newopenfileobject(fp
, "(fdopen)", mode
, fclose
);
1351 setfilebufsize(f
, bufsize
);
1356 posix_pipe(self
, args
)
1360 #if !defined(NT) || defined(HAVE_PIPE)
1363 if (!getargs(args
, ""))
1369 return posix_error();
1370 return mkvalue("(ii)", fds
[0], fds
[1]);
1374 if (!getargs(args
, ""))
1377 ok
= CreatePipe( &read
, &write
, NULL
, 0);
1380 return posix_error();
1381 return mkvalue("(ii)", read
, write
);
1385 static struct methodlist posix_methods
[] = {
1386 {"chdir", posix_chdir
},
1387 {"chmod", posix_chmod
},
1389 {"chown", posix_chown
},
1390 #endif /* HAVE_CHOWN */
1392 {"getcwd", posix_getcwd
},
1395 {"link", posix_link
},
1396 #endif /* HAVE_LINK */
1397 {"listdir", posix_listdir
},
1398 {"lstat", posix_lstat
},
1399 {"mkdir", posix_mkdir
},
1401 {"nice", posix_nice
},
1402 #endif /* HAVE_NICE */
1403 #ifdef HAVE_READLINK
1404 {"readlink", posix_readlink
},
1405 #endif /* HAVE_READLINK */
1406 {"rename", posix_rename
},
1407 {"rmdir", posix_rmdir
},
1408 {"stat", posix_stat
},
1410 {"symlink", posix_symlink
},
1411 #endif /* HAVE_SYMLINK */
1412 {"system", posix_system
},
1413 {"umask", posix_umask
},
1415 {"uname", posix_uname
},
1416 #endif /* HAVE_UNAME */
1417 {"unlink", posix_unlink
},
1418 {"utime", posix_utime
},
1420 {"times", posix_times
},
1421 #endif /* HAVE_TIMES */
1422 {"_exit", posix__exit
},
1423 {"execv", posix_execv
},
1424 {"execve", posix_execve
},
1426 {"fork", posix_fork
},
1427 #endif /* HAVE_FORK */
1429 {"getegid", posix_getegid
},
1430 #endif /* HAVE_GETEGID */
1432 {"geteuid", posix_geteuid
},
1433 #endif /* HAVE_GETEUID */
1435 {"getgid", posix_getgid
},
1436 #endif /* HAVE_GETGID */
1437 {"getpid", posix_getpid
},
1439 {"getpgrp", posix_getpgrp
},
1440 #endif /* HAVE_GETPGRP */
1442 {"getppid", posix_getppid
},
1443 #endif /* HAVE_GETPPID */
1445 {"getuid", posix_getuid
},
1446 #endif /* HAVE_GETUID */
1448 {"kill", posix_kill
},
1449 #endif /* HAVE_KILL */
1450 {"popen", posix_popen
, 1},
1452 {"setuid", posix_setuid
},
1453 #endif /* HAVE_SETUID */
1455 {"setgid", posix_setgid
},
1456 #endif /* HAVE_SETGID */
1458 {"setpgrp", posix_setpgrp
},
1459 #endif /* HAVE_SETPGRP */
1461 {"wait", posix_wait
},
1462 #endif /* HAVE_WAIT */
1464 {"waitpid", posix_waitpid
},
1465 #endif /* HAVE_WAITPID */
1467 {"setsid", posix_setsid
},
1468 #endif /* HAVE_SETSID */
1470 {"setpgid", posix_setpgid
},
1471 #endif /* HAVE_SETPGID */
1472 #ifdef HAVE_TCGETPGRP
1473 {"tcgetpgrp", posix_tcgetpgrp
},
1474 #endif /* HAVE_TCGETPGRP */
1475 #ifdef HAVE_TCSETPGRP
1476 {"tcsetpgrp", posix_tcsetpgrp
},
1477 #endif /* HAVE_TCSETPGRP */
1478 {"open", posix_open
},
1479 {"close", posix_close
},
1481 {"dup2", posix_dup2
},
1482 {"lseek", posix_lseek
},
1483 {"read", posix_read
},
1484 {"write", posix_write
},
1485 {"fstat", posix_fstat
},
1486 {"fdopen", posix_fdopen
, 1},
1487 {"pipe", posix_pipe
},
1488 {NULL
, NULL
} /* Sentinel */
1498 m
= initmodule("nt", posix_methods
);
1499 d
= getmoduledict(m
);
1501 /* Initialize nt.environ dictionary */
1502 v
= convertenviron();
1503 if (v
== NULL
|| dictinsert(d
, "environ", v
) != 0)
1504 fatal("can't define nt.environ");
1507 /* Initialize nt.error exception */
1508 PosixError
= newstringobject("nt.error");
1509 if (PosixError
== NULL
|| dictinsert(d
, "error", PosixError
) != 0)
1510 fatal("can't define nt.error");
1518 m
= initmodule("posix", posix_methods
);
1519 d
= getmoduledict(m
);
1521 /* Initialize posix.environ dictionary */
1522 v
= convertenviron();
1523 if (v
== NULL
|| dictinsert(d
, "environ", v
) != 0)
1524 fatal("can't define posix.environ");
1528 /* Export WNOHANG symbol */
1529 v
= newintobject((long)WNOHANG
);
1530 if (v
== NULL
|| dictinsert(d
, "WNOHANG", v
) != 0)
1531 fatal("can't define posix.WNOHANG");
1535 /* Initialize posix.error exception */
1536 PosixError
= newstringobject("posix.error");
1537 if (PosixError
== NULL
|| dictinsert(d
, "error", PosixError
) != 0)
1538 fatal("can't define posix.error");