summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-04-08 20:59:13 (GMT)
committerGuido van Rossum <guido@python.org>1991-04-08 20:59:13 (GMT)
commit1ff6cb4f4f66de30fbdac0741cdc65f486d439fd (patch)
tree58db1ceec042a104e3a1876e8f6e69dd7bf40907 /Modules/posixmodule.c
parentd9d2c8246c238ac95057b082aa64b5db00a398a4 (diff)
downloadcpython-1ff6cb4f4f66de30fbdac0741cdc65f486d439fd.zip
cpython-1ff6cb4f4f66de30fbdac0741cdc65f486d439fd.tar.gz
cpython-1ff6cb4f4f66de30fbdac0741cdc65f486d439fd.tar.bz2
Made utime use much more portable.
Incorporated i386 mods. (Oh, BTW, the "right" python name is now posix.utime, not utimes!
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c66
1 files changed, 52 insertions, 14 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 3e7b0cd..efe1ab4 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -24,28 +24,32 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* POSIX module implementation */
+#ifdef AMOEBA
+#define NO_LSTAT
+#define SYSV
+#endif
+
#include <signal.h>
#include <string.h>
#include <setjmp.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/time.h>
#ifdef SYSV
+#define UTIME_STRUCT
#include <dirent.h>
#define direct dirent
-#else
-#include <sys/dir.h>
+#ifdef i386
+#define mode_t int
#endif
+#else /* !SYSV */
+#include <sys/dir.h>
+#endif /* !SYSV */
#include "allobjects.h"
#include "modsupport.h"
extern char *strerror PROTO((int));
-#ifdef AMOEBA
-#define NO_LSTAT
-#endif
-
/* Return a dictionary corresponding to the POSIX environment table */
@@ -258,6 +262,21 @@ posix_mkdir(self, args)
return posix_strint(args, mkdir);
}
+#ifdef i386
+int
+rename(from, to)
+ char *from;
+ char *to;
+{
+ int status;
+ /* XXX Shouldn't this unlink the destination first? */
+ status = link(from, to);
+ if (status != 0)
+ return status;
+ return unlink(from);
+}
+#endif
+
static object *
posix_rename(self, args)
object *self;
@@ -321,26 +340,44 @@ posix_unlink(self, args)
return posix_1str(args, unlink);
}
+#ifdef UTIME_STRUCT
+#include <utime.h>
+#endif
+
static object *
-posix_utimes(self, args)
+posix_utime(self, args)
object *self;
object *args;
{
object *path;
- struct timeval tv[2];
+
+#ifdef UTIME_STRUCT
+ struct utimbuf buf;
+#define ATIME buf.actime
+#define MTIME buf.modtime
+#define UTIME_ARG &buf
+
+#else
+ time_t buf[2];
+#define ATIME buf[0]
+#define MTIME buf[1]
+#define UTIME_ARG buf
+#endif
+
if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 2) {
err_badarg();
return NULL;
}
if (!getstrarg(gettupleitem(args, 0), &path) ||
- !getlonglongargs(gettupleitem(args, 1),
- &tv[0].tv_sec, &tv[1].tv_sec))
+ !getlonglongargs(gettupleitem(args, 1), &ATIME, &MTIME))
return NULL;
- tv[0].tv_usec = tv[1].tv_usec = 0;
- if (utimes(getstringvalue(path), tv) < 0)
+ if (utime(getstringvalue(path), UTIME_ARG) < 0)
return posix_error();
INCREF(None);
return None;
+#undef UTIME_ARG
+#undef ATIME
+#undef MTIME
}
@@ -396,7 +433,8 @@ static struct methodlist posix_methods[] = {
{"system", posix_system},
{"umask", posix_umask},
{"unlink", posix_unlink},
- {"utimes", posix_utimes},
+ {"utime", posix_utime},
+ {"utimes", posix_utime}, /* XXX for compatibility only */
#ifndef NO_LSTAT
{"lstat", posix_lstat},
{"readlink", posix_readlink},