summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2000-05-01 16:17:24 (GMT)
committerBarry Warsaw <barry@python.org>2000-05-01 16:17:24 (GMT)
commit3cef856dd9db9e998d4fa3395b466f2ed42f7fc9 (patch)
treecba358758c855240a2e9f0505eb4d7c861722efe /Modules
parent6650320349185a9e2f06fba56a3bd3142fb6f8d5 (diff)
downloadcpython-3cef856dd9db9e998d4fa3395b466f2ed42f7fc9.zip
cpython-3cef856dd9db9e998d4fa3395b466f2ed42f7fc9.tar.gz
cpython-3cef856dd9db9e998d4fa3395b466f2ed42f7fc9.tar.bz2
posix_utime(): Allow the second argument to be None, which invokes the
utime(path, NULL) call, setting the atime and mtime of the file to the current time. The previous signature utime(path, (atime, mtime)) is of course still allowed.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 2c5274a..b62cce0 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1250,7 +1250,9 @@ posix_uname(self, args)
static char posix_utime__doc__[] =
"utime(path, (atime, utime)) -> None\n\
-Set the access and modified time of the file to the given values.";
+utime(path, None) -> None\n\
+Set the access and modified time of the file to the given values. If the\n\
+second form is used, set the access and modified times to the current time.";
static PyObject *
posix_utime(self, args)
@@ -1260,6 +1262,7 @@ posix_utime(self, args)
char *path;
long atime, mtime;
int res;
+ PyObject* arg;
/* XXX should define struct utimbuf instead, above */
#ifdef HAVE_UTIME_H
@@ -1274,13 +1277,26 @@ posix_utime(self, args)
#define UTIME_ARG buf
#endif /* HAVE_UTIME_H */
- if (!PyArg_ParseTuple(args, "s(ll):utime", &path, &atime, &mtime))
+ if (!PyArg_ParseTuple(args, "sO:utime", &path, &arg))
return NULL;
- ATIME = atime;
- MTIME = mtime;
- Py_BEGIN_ALLOW_THREADS
- res = utime(path, UTIME_ARG);
- Py_END_ALLOW_THREADS
+ if (arg == Py_None) {
+ /* optional time values not given */
+ Py_BEGIN_ALLOW_THREADS
+ res = utime(path, NULL);
+ Py_END_ALLOW_THREADS
+ }
+ else if (!PyArg_Parse(arg, "(ll)", &atime, &mtime)) {
+ PyErr_SetString(PyExc_TypeError,
+ "Second argument must be a 2-tuple of numbers.");
+ return NULL;
+ }
+ else {
+ ATIME = atime;
+ MTIME = mtime;
+ Py_BEGIN_ALLOW_THREADS
+ res = utime(path, UTIME_ARG);
+ Py_END_ALLOW_THREADS
+ }
if (res < 0)
return posix_error_with_filename(path);
Py_INCREF(Py_None);