summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-06-04 19:40:25 (GMT)
committerGuido van Rossum <guido@python.org>1991-06-04 19:40:25 (GMT)
commit3b06619e1cbb2dfc4da4992bc648304e48af1701 (patch)
treee62a2cedadc778b32b0e17d7b09f6fc0944e35e7 /Modules/posixmodule.c
parentc405b7b2fa2b18aa8f3fc62ca422cdee90138583 (diff)
downloadcpython-3b06619e1cbb2dfc4da4992bc648304e48af1701.zip
cpython-3b06619e1cbb2dfc4da4992bc648304e48af1701.tar.gz
cpython-3b06619e1cbb2dfc4da4992bc648304e48af1701.tar.bz2
Added popen().
Added getmtime() function for use by ".pyc" processing.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index ad46b66..3a1d4ba 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -427,7 +427,7 @@ posix_utime(self, args)
#ifndef MSDOS
-/* Process Primitives */
+/* Process operations */
static object *
posix__exit(self, args)
@@ -545,6 +545,26 @@ posix_kill(self, args)
}
static object *
+posix_popen(self, args)
+ object *self;
+ object *args;
+{
+ extern int pclose PROTO((FILE *));
+ object *name, *mode;
+ FILE *fp;
+ if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 2 ||
+ !is_stringobject(name = gettupleitem(args, 0)) ||
+ !is_stringobject(mode = gettupleitem(args, 1))) {
+ err_setstr(TypeError, "open() requires 2 string arguments");
+ return NULL;
+ }
+ fp = popen(getstringvalue(name), getstringvalue(mode));
+ if (fp == NULL)
+ return posix_error();
+ return newopenfileobject(fp, name, mode, pclose);
+}
+
+static object *
posix_wait(self, args) /* Also waitpid() */
object *self;
object *args;
@@ -644,6 +664,7 @@ static struct methodlist posix_methods[] = {
{"getpid", posix_getpid},
{"getppid", posix_getppid},
{"kill", posix_kill},
+ {"popen", posix_popen},
{"wait", posix_wait},
#endif
#ifndef NO_LSTAT
@@ -675,6 +696,21 @@ initposix()
fatal("can't define posix.error");
}
+
+/* Function used elsewhere to get a file's modification time */
+
+long
+getmtime(path)
+ char *path;
+{
+ struct stat st;
+ if (stat(path, &st) != 0)
+ return -1;
+ else
+ return st.st_mtime;
+}
+
+
#ifdef MSDOS
/* A small "compatibility library" for TurboC under MS-DOS */