mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Made utime use much more portable.
Incorporated i386 mods. (Oh, BTW, the "right" python name is now posix.utime, not utimes!
This commit is contained in:
parent
d9d2c8246c
commit
1ff6cb4f4f
1 changed files with 52 additions and 14 deletions
|
@ -24,28 +24,32 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
/* POSIX module implementation */
|
/* POSIX module implementation */
|
||||||
|
|
||||||
|
#ifdef AMOEBA
|
||||||
|
#define NO_LSTAT
|
||||||
|
#define SYSV
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
|
||||||
#ifdef SYSV
|
#ifdef SYSV
|
||||||
|
#define UTIME_STRUCT
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#define direct dirent
|
#define direct dirent
|
||||||
#else
|
#ifdef i386
|
||||||
#include <sys/dir.h>
|
#define mode_t int
|
||||||
#endif
|
#endif
|
||||||
|
#else /* !SYSV */
|
||||||
|
#include <sys/dir.h>
|
||||||
|
#endif /* !SYSV */
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
|
|
||||||
extern char *strerror PROTO((int));
|
extern char *strerror PROTO((int));
|
||||||
|
|
||||||
#ifdef AMOEBA
|
|
||||||
#define NO_LSTAT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* Return a dictionary corresponding to the POSIX environment table */
|
/* Return a dictionary corresponding to the POSIX environment table */
|
||||||
|
|
||||||
|
@ -258,6 +262,21 @@ posix_mkdir(self, args)
|
||||||
return posix_strint(args, mkdir);
|
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 *
|
static object *
|
||||||
posix_rename(self, args)
|
posix_rename(self, args)
|
||||||
object *self;
|
object *self;
|
||||||
|
@ -321,26 +340,44 @@ posix_unlink(self, args)
|
||||||
return posix_1str(args, unlink);
|
return posix_1str(args, unlink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef UTIME_STRUCT
|
||||||
|
#include <utime.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
posix_utimes(self, args)
|
posix_utime(self, args)
|
||||||
object *self;
|
object *self;
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
object *path;
|
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) {
|
if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 2) {
|
||||||
err_badarg();
|
err_badarg();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!getstrarg(gettupleitem(args, 0), &path) ||
|
if (!getstrarg(gettupleitem(args, 0), &path) ||
|
||||||
!getlonglongargs(gettupleitem(args, 1),
|
!getlonglongargs(gettupleitem(args, 1), &ATIME, &MTIME))
|
||||||
&tv[0].tv_sec, &tv[1].tv_sec))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
tv[0].tv_usec = tv[1].tv_usec = 0;
|
if (utime(getstringvalue(path), UTIME_ARG) < 0)
|
||||||
if (utimes(getstringvalue(path), tv) < 0)
|
|
||||||
return posix_error();
|
return posix_error();
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
|
#undef UTIME_ARG
|
||||||
|
#undef ATIME
|
||||||
|
#undef MTIME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -396,7 +433,8 @@ static struct methodlist posix_methods[] = {
|
||||||
{"system", posix_system},
|
{"system", posix_system},
|
||||||
{"umask", posix_umask},
|
{"umask", posix_umask},
|
||||||
{"unlink", posix_unlink},
|
{"unlink", posix_unlink},
|
||||||
{"utimes", posix_utimes},
|
{"utime", posix_utime},
|
||||||
|
{"utimes", posix_utime}, /* XXX for compatibility only */
|
||||||
#ifndef NO_LSTAT
|
#ifndef NO_LSTAT
|
||||||
{"lstat", posix_lstat},
|
{"lstat", posix_lstat},
|
||||||
{"readlink", posix_readlink},
|
{"readlink", posix_readlink},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue