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 and MS-Win. 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 '_MSC_VER'. */
34 /* See also ../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 */
54 /* Various compilers have only certain posix functions */
55 #ifdef __WATCOMC__ /* Watcom compiler */
57 #define HAVE_OPENDIR 1
65 #ifdef __BORLANDC__ /* Borland compiler */
68 #define HAVE_GETEGID 1
69 #define HAVE_GETEUID 1
71 #define HAVE_GETPPID 1
74 #define HAVE_OPENDIR 1
80 #ifdef _MSC_VER /* Microsoft compiler */
86 #else /* 16-bit Windows */
88 #else /* all other compilers */
89 /* Unix functions that the configure script doesn't check for */
93 #define HAVE_GETEGID 1
94 #define HAVE_GETEUID 1
96 #define HAVE_GETPPID 1
99 #define HAVE_OPENDIR 1
102 #define HAVE_SYSTEM 1
104 #endif /* _MSC_VER */
105 #endif /* __BORLANDC__ */
106 #endif /* ! __WATCOMC__ */
115 /* NeXT's <unistd.h> and <utime.h> aren't worth much */
118 /* #undef HAVE_GETCWD */
122 /* XXX These are for SunOS4.1.3 but shouldn't hurt elsewhere */
126 extern int symlink();
127 #else /* !HAVE_UNISTD_H */
128 #if defined(__WATCOMC__)
129 extern int mkdir
PROTO((const char *));
131 extern int mkdir
PROTO((const char *, mode_t
));
133 extern int chdir
PROTO((const char *));
134 extern int rmdir
PROTO((const char *));
135 extern int chmod
PROTO((const char *, mode_t
));
136 extern int chown
PROTO((const char *, uid_t
, gid_t
));
137 extern char *getcwd
PROTO((char *, int));
138 extern char *strerror
PROTO((int));
139 extern int link
PROTO((const char *, const char *));
140 extern int rename
PROTO((const char *, const char *));
141 extern int stat
PROTO((const char *, struct stat
*));
142 extern int unlink
PROTO((const char *));
143 extern int pclose
PROTO((FILE *));
145 extern int symlink
PROTO((const char *, const char *));
146 #endif /* HAVE_SYMLINK */
148 extern int lstat
PROTO((const char *, struct stat
*));
149 #endif /* HAVE_LSTAT */
150 #endif /* !HAVE_UNISTD_H */
152 #endif /* !_MSC_VER */
156 #endif /* HAVE_UTIME_H */
158 #ifdef HAVE_SYS_UTIME_H
159 #include <sys/utime.h>
160 #define HAVE_UTIME_H /* pretend we do for the rest of this file */
161 #endif /* HAVE_SYS_UTIME_H */
163 #ifdef HAVE_SYS_TIMES_H
164 #include <sys/times.h>
165 #endif /* HAVE_SYS_TIMES_H */
167 #ifdef HAVE_SYS_PARAM_H
168 #include <sys/param.h>
169 #endif /* HAVE_SYS_PARAM_H */
171 #ifdef HAVE_SYS_UTSNAME_H
172 #include <sys/utsname.h>
173 #endif /* HAVE_SYS_UTSNAME_H */
176 #define MAXPATHLEN 1024
177 #endif /* MAXPATHLEN */
181 #define NAMLEN(dirent) strlen((dirent)->d_name)
185 #define NAMLEN(dirent) strlen((dirent)->d_name)
187 #define dirent direct
188 #define NAMLEN(dirent) (dirent)->d_namlen
190 #ifdef HAVE_SYS_NDIR_H
191 #include <sys/ndir.h>
193 #ifdef HAVE_SYS_DIR_H
208 #define pclose _pclose
209 #else /* 16-bit Windows */
213 #endif /* _MSC_VER */
219 /* Return a dictionary corresponding to the POSIX environment table */
221 #if !defined(_MSC_VER) && !defined(__WATCOMC__)
222 extern char **environ
;
223 #endif /* !_MSC_VER */
235 /* XXX This part ignores errors */
236 for (e
= environ
; *e
!= NULL
; e
++) {
238 char *p
= strchr(*e
, '=');
241 v
= newstringobject(p
+1);
245 (void) dictinsert(d
, *e
, v
);
253 static object
*PosixError
; /* Exception posix.error */
255 /* Set a POSIX-specific error from errno, and return NULL */
257 static object
* posix_error()
259 return err_errno(PosixError
);
263 /* POSIX generic methods */
266 posix_1str(args
, func
)
268 int (*func
) FPROTO((const char *));
272 if (!getargs(args
, "s", &path1
))
275 res
= (*func
)(path1
);
278 return posix_error();
284 posix_2str(args
, func
)
286 int (*func
) FPROTO((const char *, const char *));
290 if (!getargs(args
, "(ss)", &path1
, &path2
))
293 res
= (*func
)(path1
, path2
);
296 return posix_error();
302 posix_strint(args
, func
)
304 int (*func
) FPROTO((const char *, int));
309 if (!getargs(args
, "(si)", &path
, &i
))
312 res
= (*func
)(path
, i
);
315 return posix_error();
321 posix_strintint(args
, func
)
323 int (*func
) FPROTO((const char *, int, int));
328 if (!getargs(args
, "(sii)", &path
, &i
, &i2
))
331 res
= (*func
)(path
, i
, i2
);
334 return posix_error();
340 posix_do_stat(self
, args
, statfunc
)
343 int (*statfunc
) FPROTO((const char *, struct stat
*));
348 if (!getargs(args
, "s", &path
))
351 res
= (*statfunc
)(path
, &st
);
354 return posix_error();
355 return mkvalue("(llllllllll)",
372 posix_chdir(self
, args
)
376 return posix_1str(args
, chdir
);
380 posix_chmod(self
, args
)
384 return posix_strint(args
, chmod
);
389 posix_chown(self
, args
)
393 return posix_strintint(args
, chown
);
395 #endif /* HAVE_CHOWN */
399 posix_getcwd(self
, args
)
408 res
= getcwd(buf
, sizeof buf
);
411 return posix_error();
412 return newstringobject(buf
);
418 posix_link(self
, args
)
422 return posix_2str(args
, link
);
424 #endif /* HAVE_LINK */
427 posix_listdir(self
, args
)
431 #if defined(NT) && !defined(HAVE_OPENDIR)
437 WIN32_FIND_DATA FileData
;
438 char namebuf
[MAX_PATH
+5];
440 if (!getargs(args
, "s#", &name
, &len
))
442 if (len
>= MAX_PATH
) {
443 err_setstr(ValueError
, "path too long");
446 strcpy(namebuf
, name
);
447 if (namebuf
[len
-1] != '/' && namebuf
[len
-1] != '\\')
448 namebuf
[len
++] = '/';
449 strcpy(namebuf
+ len
, "*.*");
451 if ((d
= newlistobject(0)) == NULL
)
454 hFindFile
= FindFirstFile(namebuf
, &FileData
);
455 if (hFindFile
== INVALID_HANDLE_VALUE
) {
456 errno
= GetLastError();
457 return posix_error();
460 if (FileData
.cFileName
[0] == '.' &&
461 (FileData
.cFileName
[1] == '\0' ||
462 FileData
.cFileName
[1] == '.' &&
463 FileData
.cFileName
[2] == '\0'))
465 v
= newstringobject(FileData
.cFileName
);
471 if (addlistitem(d
, v
) != 0) {
478 } while (FindNextFile(hFindFile
, &FileData
) == TRUE
);
480 if (FindClose(hFindFile
) == FALSE
) {
481 errno
= GetLastError();
482 return posix_error();
488 #ifdef _MSC_VER /* 16-bit Windows */
496 char namebuf
[MAX_PATH
+5];
499 if (!getargs(args
, "s#", &name
, &len
))
501 if (len
>= MAX_PATH
) {
502 err_setstr(ValueError
, "path too long");
505 strcpy(namebuf
, name
);
506 for (pt
= namebuf
; *pt
; pt
++)
509 if (namebuf
[len
-1] != '\\')
510 namebuf
[len
++] = '\\';
511 strcpy(namebuf
+ len
, "*.*");
513 if ((d
= newlistobject(0)) == NULL
)
516 if (_dos_findfirst(namebuf
, _A_RDONLY
|
517 _A_HIDDEN
| _A_SYSTEM
| _A_SUBDIR
, &ep
) != 0){
519 return posix_error();
522 if (ep
.name
[0] == '.' &&
523 (ep
.name
[1] == '\0' ||
527 strcpy(namebuf
, ep
.name
);
528 for (pt
= namebuf
; *pt
; pt
++)
531 v
= newstringobject(namebuf
);
537 if (addlistitem(d
, v
) != 0) {
544 } while (_dos_findnext(&ep
) == 0);
554 if (!getargs(args
, "s", &name
))
557 if ((dirp
= opendir(name
)) == NULL
) {
559 return posix_error();
561 if ((d
= newlistobject(0)) == NULL
) {
566 while ((ep
= readdir(dirp
)) != NULL
) {
567 if (ep
->d_name
[0] == '.' &&
569 ep
->d_name
[1] == '.' && NAMLEN(ep
) == 2))
571 v
= newsizedstringobject(ep
->d_name
, NAMLEN(ep
));
577 if (addlistitem(d
, v
) != 0) {
590 #endif /* !_MSC_VER */
595 posix_mkdir(self
, args
)
602 if (!newgetargs(args
, "s|i", &path
, &mode
))
605 #if defined(__WATCOMC__)
608 res
= mkdir(path
, mode
);
612 return posix_error();
619 posix_nice(self
, args
)
623 int increment
, value
;
625 if (!getargs(args
, "i", &increment
))
627 value
= nice(increment
);
629 return posix_error();
630 return newintobject((long) value
);
632 #endif /* HAVE_NICE */
635 posix_rename(self
, args
)
639 return posix_2str(args
, rename
);
643 posix_rmdir(self
, args
)
647 return posix_1str(args
, rmdir
);
651 posix_stat(self
, args
)
655 return posix_do_stat(self
, args
, stat
);
660 posix_system(self
, args
)
666 if (!getargs(args
, "s", &command
))
669 sts
= system(command
);
671 return newintobject(sts
);
676 posix_umask(self
, args
)
681 if (!getintarg(args
, &i
))
685 return posix_error();
686 return newintobject((long)i
);
690 posix_unlink(self
, args
)
694 return posix_1str(args
, unlink
);
699 posix_uname(self
, args
)
712 return posix_error();
713 return mkvalue("(sssss)",
720 #endif /* HAVE_UNAME */
723 posix_utime(self
, args
)
733 #define ATIME buf.actime
734 #define MTIME buf.modtime
735 #define UTIME_ARG &buf
736 #else /* HAVE_UTIME_H */
740 #define UTIME_ARG buf
741 #endif /* HAVE_UTIME_H */
743 if (!getargs(args
, "(s(ll))", &path
, &atime
, &mtime
))
748 res
= utime(path
, UTIME_ARG
);
751 return posix_error();
760 /* Process operations */
763 posix__exit(self
, args
)
768 if (!getintarg(args
, &sts
))
776 posix_execv(self
, args
)
784 object
*(*getitem
) PROTO((object
*, int));
786 /* execv has two arguments: (path, argv), where
787 argv is a list or tuple of strings. */
789 if (!getargs(args
, "(sO)", &path
, &argv
))
791 if (is_listobject(argv
)) {
792 argc
= getlistsize(argv
);
793 getitem
= getlistitem
;
795 else if (is_tupleobject(argv
)) {
796 argc
= gettuplesize(argv
);
797 getitem
= gettupleitem
;
805 argvlist
= NEW(char *, argc
+1);
806 if (argvlist
== NULL
)
808 for (i
= 0; i
< argc
; i
++) {
809 if (!getargs((*getitem
)(argv
, i
), "s", &argvlist
[i
])) {
814 argvlist
[argc
] = NULL
;
816 #ifdef BAD_EXEC_PROTOTYPES
817 execv(path
, (const char **) argvlist
);
818 #else /* BAD_EXEC_PROTOTYPES */
819 execv(path
, argvlist
);
820 #endif /* BAD_EXEC_PROTOTYPES */
822 /* If we get here it's definitely an error */
825 return posix_error();
829 posix_execve(self
, args
)
838 int i
, pos
, argc
, envc
;
839 object
*(*getitem
) PROTO((object
*, int));
841 /* execve has three arguments: (path, argv, env), where
842 argv is a list or tuple of strings and env is a dictionary
843 like posix.environ. */
845 if (!getargs(args
, "(sOO)", &path
, &argv
, &env
))
847 if (is_listobject(argv
)) {
848 argc
= getlistsize(argv
);
849 getitem
= getlistitem
;
851 else if (is_tupleobject(argv
)) {
852 argc
= gettuplesize(argv
);
853 getitem
= gettupleitem
;
856 err_setstr(TypeError
, "argv must be tuple or list");
859 if (!is_dictobject(env
)) {
860 err_setstr(TypeError
, "env must be dictionary");
864 argvlist
= NEW(char *, argc
+1);
865 if (argvlist
== NULL
) {
869 for (i
= 0; i
< argc
; i
++) {
870 if (!getargs((*getitem
)(argv
, i
),
871 "s;argv must be list of strings",
876 argvlist
[argc
] = NULL
;
878 i
= getmappingsize(env
);
879 envlist
= NEW(char *, i
+ 1);
880 if (envlist
== NULL
) {
886 while (mappinggetnext(env
, &pos
, &key
, &val
)) {
888 if (!getargs(key
, "s;non-string key in env", &k
) ||
889 !getargs(val
, "s;non-string value in env", &v
)) {
892 p
= NEW(char, getstringsize(key
) + getstringsize(val
) + 2);
897 sprintf(p
, "%s=%s", k
, v
);
903 #ifdef BAD_EXEC_PROTOTYPES
904 execve(path
, (const char **)argvlist
, envlist
);
905 #else /* BAD_EXEC_PROTOTYPES */
906 execve(path
, argvlist
, envlist
);
907 #endif /* BAD_EXEC_PROTOTYPES */
909 /* If we get here it's definitely an error */
911 (void) posix_error();
922 #endif /* HAVE_EXECV */
926 posix_fork(self
, args
)
935 return posix_error();
936 return newintobject((long)pid
);
942 posix_getegid(self
, args
)
948 return newintobject((long)getegid());
954 posix_geteuid(self
, args
)
960 return newintobject((long)geteuid());
966 posix_getgid(self
, args
)
972 return newintobject((long)getgid());
977 posix_getpid(self
, args
)
983 return newintobject((long)getpid());
988 posix_getpgrp(self
, args
)
994 #ifdef GETPGRP_HAVE_ARG
995 return newintobject((long)getpgrp(0));
996 #else /* GETPGRP_HAVE_ARG */
997 return newintobject((long)getpgrp());
998 #endif /* GETPGRP_HAVE_ARG */
1000 #endif /* HAVE_GETPGRP */
1004 posix_setpgrp(self
, args
)
1008 if (!getnoarg(args
))
1010 #ifdef SETPGRP_HAVE_ARG
1011 if (setpgrp(0, 0) < 0)
1012 #else /* SETPGRP_HAVE_ARG */
1014 #endif /* SETPGRP_HAVE_ARG */
1015 return posix_error();
1020 #endif /* HAVE_SETPGRP */
1024 posix_getppid(self
, args
)
1028 if (!getnoarg(args
))
1030 return newintobject((long)getppid());
1036 posix_getuid(self
, args
)
1040 if (!getnoarg(args
))
1042 return newintobject((long)getuid());
1048 posix_kill(self
, args
)
1053 if (!getargs(args
, "(ii)", &pid
, &sig
))
1055 if (kill(pid
, sig
) == -1)
1056 return posix_error();
1064 posix_popen(self
, args
)
1073 if (!newgetargs(args
, "s|si", &name
, &mode
, &bufsize
))
1076 fp
= popen(name
, mode
);
1079 return posix_error();
1080 f
= newopenfileobject(fp
, name
, mode
, pclose
);
1082 setfilebufsize(f
, bufsize
);
1085 #endif /* HAVE_POPEN */
1089 posix_setuid(self
, args
)
1094 if (!getargs(args
, "i", &uid
))
1096 if (setuid(uid
) < 0)
1097 return posix_error();
1101 #endif /* HAVE_SETUID */
1105 posix_setgid(self
, args
)
1110 if (!getargs(args
, "i", &gid
))
1112 if (setgid(gid
) < 0)
1113 return posix_error();
1117 #endif /* HAVE_SETGID */
1121 posix_waitpid(self
, args
)
1125 int pid
, options
, sts
;
1126 if (!getargs(args
, "(ii)", &pid
, &options
))
1129 pid
= waitpid(pid
, &sts
, options
);
1132 return posix_error();
1134 return mkvalue("ii", pid
, sts
);
1136 #endif /* HAVE_WAITPID */
1140 posix_wait(self
, args
)
1149 return posix_error();
1151 return mkvalue("ii", pid
, sts
);
1156 posix_lstat(self
, args
)
1161 return posix_do_stat(self
, args
, lstat
);
1162 #else /* !HAVE_LSTAT */
1163 return posix_do_stat(self
, args
, stat
);
1164 #endif /* !HAVE_LSTAT */
1167 #ifdef HAVE_READLINK
1169 posix_readlink(self
, args
)
1173 char buf
[MAXPATHLEN
];
1176 if (!getargs(args
, "s", &path
))
1179 n
= readlink(path
, buf
, (int) sizeof buf
);
1182 return posix_error();
1183 return newsizedstringobject(buf
, n
);
1185 #endif /* HAVE_READLINK */
1189 posix_symlink(self
, args
)
1193 return posix_2str(args
, symlink
);
1195 #endif /* HAVE_SYMLINK */
1199 #define HZ 60 /* Universal constant :-) */
1202 posix_times(self
, args
)
1208 if (!getnoarg(args
))
1212 if (c
== (clock_t) -1)
1213 return posix_error();
1214 return mkvalue("ddddd",
1215 (double)t
.tms_utime
/ HZ
,
1216 (double)t
.tms_stime
/ HZ
,
1217 (double)t
.tms_cutime
/ HZ
,
1218 (double)t
.tms_cstime
/ HZ
,
1221 #endif /* HAVE_TIMES */
1222 #if defined(NT) && !defined(HAVE_TIMES)
1223 #define HAVE_TIMES /* so the method table will pick it up */
1225 posix_times(self
, args
)
1229 FILETIME create
, exit
, kernel
, user
;
1231 if (!getnoarg(args
))
1233 hProc
= GetCurrentProcess();
1234 GetProcessTimes(hProc
,&create
, &exit
, &kernel
, &user
);
1235 return mkvalue("ddddd",
1236 (double)(kernel
.dwHighDateTime
*2E32
+kernel
.dwLowDateTime
) / 2E6
,
1237 (double)(user
.dwHighDateTime
*2E32
+user
.dwLowDateTime
) / 2E6
,
1246 posix_setsid(self
, args
)
1250 if (!getnoarg(args
))
1253 return posix_error();
1257 #endif /* HAVE_SETSID */
1261 posix_setpgid(self
, args
)
1266 if (!getargs(args
, "(ii)", &pid
, &pgrp
))
1268 if (setpgid(pid
, pgrp
) < 0)
1269 return posix_error();
1273 #endif /* HAVE_SETPGID */
1275 #ifdef HAVE_TCGETPGRP
1277 posix_tcgetpgrp(self
, args
)
1282 if (!getargs(args
, "i", &fd
))
1284 pgid
= tcgetpgrp(fd
);
1286 return posix_error();
1287 return newintobject((long)pgid
);
1289 #endif /* HAVE_TCGETPGRP */
1291 #ifdef HAVE_TCSETPGRP
1293 posix_tcsetpgrp(self
, args
)
1298 if (!getargs(args
, "(ii)", &fd
, &pgid
))
1300 if (tcsetpgrp(fd
, pgid
) < 0)
1301 return posix_error();
1305 #endif /* HAVE_TCSETPGRP */
1307 /* Functions acting on file descriptors */
1310 posix_open(self
, args
)
1318 if (!getargs(args
, "(si)", &file
, &flag
)) {
1320 if (!getargs(args
, "(sii)", &file
, &flag
, &mode
))
1324 fd
= open(file
, flag
, mode
);
1327 return posix_error();
1328 return newintobject((long)fd
);
1332 posix_close(self
, args
)
1337 if (!getargs(args
, "i", &fd
))
1343 return posix_error();
1349 posix_dup(self
, args
)
1354 if (!getargs(args
, "i", &fd
))
1360 return posix_error();
1361 return newintobject((long)fd
);
1365 posix_dup2(self
, args
)
1370 if (!getargs(args
, "(ii)", &fd
, &fd2
))
1373 res
= dup2(fd
, fd2
);
1376 return posix_error();
1382 posix_lseek(self
, args
)
1388 if (!getargs(args
, "(ili)", &fd
, &pos
, &how
))
1391 /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */
1393 case 0: how
= SEEK_SET
; break;
1394 case 1: how
= SEEK_CUR
; break;
1395 case 2: how
= SEEK_END
; break;
1397 #endif /* SEEK_END */
1399 res
= lseek(fd
, pos
, how
);
1402 return posix_error();
1403 return newintobject(res
);
1407 posix_read(self
, args
)
1413 if (!getargs(args
, "(ii)", &fd
, &size
))
1415 buffer
= newsizedstringobject((char *)NULL
, size
);
1419 size
= read(fd
, getstringvalue(buffer
), size
);
1423 return posix_error();
1425 resizestring(&buffer
, size
);
1430 posix_write(self
, args
)
1436 if (!getargs(args
, "(is#)", &fd
, &buffer
, &size
))
1439 size
= write(fd
, buffer
, size
);
1442 return posix_error();
1443 return newintobject((long)size
);
1447 posix_fstat(self
, args
)
1454 if (!getargs(args
, "i", &fd
))
1457 res
= fstat(fd
, &st
);
1460 return posix_error();
1461 return mkvalue("(llllllllll)",
1475 posix_fdopen(self
, args
)
1479 extern int fclose
PROTO((FILE *));
1485 if (!newgetargs(args
, "i|si", &fd
, &mode
, &bufsize
))
1488 fp
= fdopen(fd
, mode
);
1491 return posix_error();
1492 f
= newopenfileobject(fp
, "(fdopen)", mode
, fclose
);
1494 setfilebufsize(f
, bufsize
);
1500 posix_pipe(self
, args
)
1507 if (!getargs(args
, ""))
1513 return posix_error();
1514 return mkvalue("(ii)", fds
[0], fds
[1]);
1518 if (!getargs(args
, ""))
1521 ok
= CreatePipe( &read
, &write
, NULL
, 0);
1524 return posix_error();
1525 return mkvalue("(ii)", read
, write
);
1528 #endif /* HAVE_PIPE */
1532 posix_mkfifo(self
, args
)
1539 if (!newgetargs(args
, "s|i", &file
, &mode
))
1542 res
= mkfifo(file
, mode
);
1545 return posix_error();
1551 #ifdef HAVE_FTRUNCATE
1553 posix_ftruncate(self
, args
)
1554 object
*self
; /* Not used */
1561 if (!getargs(args
, "(il)", &fd
, &length
))
1565 res
= ftruncate(fd
, length
);
1576 static struct methodlist posix_methods
[] = {
1577 {"chdir", posix_chdir
},
1578 {"chmod", posix_chmod
},
1580 {"chown", posix_chown
},
1581 #endif /* HAVE_CHOWN */
1583 {"getcwd", posix_getcwd
},
1586 {"link", posix_link
},
1587 #endif /* HAVE_LINK */
1588 {"listdir", posix_listdir
},
1589 {"lstat", posix_lstat
},
1590 {"mkdir", posix_mkdir
, 1},
1592 {"nice", posix_nice
},
1593 #endif /* HAVE_NICE */
1594 #ifdef HAVE_READLINK
1595 {"readlink", posix_readlink
},
1596 #endif /* HAVE_READLINK */
1597 {"rename", posix_rename
},
1598 {"rmdir", posix_rmdir
},
1599 {"stat", posix_stat
},
1601 {"symlink", posix_symlink
},
1602 #endif /* HAVE_SYMLINK */
1604 {"system", posix_system
},
1606 {"umask", posix_umask
},
1608 {"uname", posix_uname
},
1609 #endif /* HAVE_UNAME */
1610 {"unlink", posix_unlink
},
1611 {"remove", posix_unlink
},
1612 {"utime", posix_utime
},
1614 {"times", posix_times
},
1615 #endif /* HAVE_TIMES */
1616 {"_exit", posix__exit
},
1618 {"execv", posix_execv
},
1619 {"execve", posix_execve
},
1620 #endif /* HAVE_EXECV */
1622 {"fork", posix_fork
},
1623 #endif /* HAVE_FORK */
1625 {"getegid", posix_getegid
},
1626 #endif /* HAVE_GETEGID */
1628 {"geteuid", posix_geteuid
},
1629 #endif /* HAVE_GETEUID */
1631 {"getgid", posix_getgid
},
1632 #endif /* HAVE_GETGID */
1633 {"getpid", posix_getpid
},
1635 {"getpgrp", posix_getpgrp
},
1636 #endif /* HAVE_GETPGRP */
1638 {"getppid", posix_getppid
},
1639 #endif /* HAVE_GETPPID */
1641 {"getuid", posix_getuid
},
1642 #endif /* HAVE_GETUID */
1644 {"kill", posix_kill
},
1645 #endif /* HAVE_KILL */
1647 {"popen", posix_popen
, 1},
1648 #endif /* HAVE_POPEN */
1650 {"setuid", posix_setuid
},
1651 #endif /* HAVE_SETUID */
1653 {"setgid", posix_setgid
},
1654 #endif /* HAVE_SETGID */
1656 {"setpgrp", posix_setpgrp
},
1657 #endif /* HAVE_SETPGRP */
1659 {"wait", posix_wait
},
1660 #endif /* HAVE_WAIT */
1662 {"waitpid", posix_waitpid
},
1663 #endif /* HAVE_WAITPID */
1665 {"setsid", posix_setsid
},
1666 #endif /* HAVE_SETSID */
1668 {"setpgid", posix_setpgid
},
1669 #endif /* HAVE_SETPGID */
1670 #ifdef HAVE_TCGETPGRP
1671 {"tcgetpgrp", posix_tcgetpgrp
},
1672 #endif /* HAVE_TCGETPGRP */
1673 #ifdef HAVE_TCSETPGRP
1674 {"tcsetpgrp", posix_tcsetpgrp
},
1675 #endif /* HAVE_TCSETPGRP */
1676 {"open", posix_open
},
1677 {"close", posix_close
},
1679 {"dup2", posix_dup2
},
1680 {"lseek", posix_lseek
},
1681 {"read", posix_read
},
1682 {"write", posix_write
},
1683 {"fstat", posix_fstat
},
1684 {"fdopen", posix_fdopen
, 1},
1686 {"pipe", posix_pipe
},
1689 {"mkfifo", posix_mkfifo
, 1},
1691 #ifdef HAVE_FTRUNCATE
1692 {"ftruncate", posix_ftruncate
, 1},
1694 {NULL
, NULL
} /* Sentinel */
1698 #if defined(_MSC_VER) || defined(__WATCOMC__)
1704 m
= initmodule("nt", posix_methods
);
1705 d
= getmoduledict(m
);
1707 /* Initialize nt.environ dictionary */
1708 v
= convertenviron();
1709 if (v
== NULL
|| dictinsert(d
, "environ", v
) != 0)
1710 fatal("can't define nt.environ");
1713 /* Initialize nt.error exception */
1714 PosixError
= newstringobject("nt.error");
1715 if (PosixError
== NULL
|| dictinsert(d
, "error", PosixError
) != 0)
1716 fatal("can't define nt.error");
1718 #else /* !_MSC_VER */
1724 m
= initmodule("posix", posix_methods
);
1725 d
= getmoduledict(m
);
1727 /* Initialize posix.environ dictionary */
1728 v
= convertenviron();
1729 if (v
== NULL
|| dictinsert(d
, "environ", v
) != 0)
1730 fatal("can't define posix.environ");
1734 /* Export WNOHANG symbol */
1735 v
= newintobject((long)WNOHANG
);
1736 if (v
== NULL
|| dictinsert(d
, "WNOHANG", v
) != 0)
1737 fatal("can't define posix.WNOHANG");
1741 /* Initialize posix.error exception */
1742 PosixError
= newstringobject("posix.error");
1743 if (PosixError
== NULL
|| dictinsert(d
, "error", PosixError
) != 0)
1744 fatal("can't define posix.error");
1746 #endif /* !_MSC_VER */