summaryrefslogtreecommitdiff
path: root/Modules/timemodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2012-04-03 00:45:07 +0200
committerVictor Stinner <victor.stinner@gmail.com>2012-04-03 00:45:07 +0200
commitd7873671627c8423c2053bc74e4cae84300ccc4f (patch)
tree7938d959cef0f14544edb9eb0ee20d4ade1ea78f /Modules/timemodule.c
parentd6171c62f5419e891c1f89f2b1c2db2687f11cec (diff)
downloadcpython-d7873671627c8423c2053bc74e4cae84300ccc4f.tar.gz
Expose clock_settime() as time.clock_settime()
Diffstat (limited to 'Modules/timemodule.c')
-rw-r--r--Modules/timemodule.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 0fe1b17dd4..23f3ddd765 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -158,6 +158,33 @@ PyDoc_STRVAR(clock_gettime_doc,
"clock_gettime(clk_id) -> floating point number\n\
\n\
Return the time of the specified clock clk_id.");
+
+static PyObject *
+time_clock_settime(PyObject *self, PyObject *args)
+{
+ clockid_t clk_id;
+ PyObject *obj;
+ struct timespec tp;
+ int ret;
+
+ if (!PyArg_ParseTuple(args, "iO:clock_settime", &clk_id, &obj))
+ return NULL;
+
+ if (_PyTime_ObjectToTimespec(obj, &tp.tv_sec, &tp.tv_nsec) == -1)
+ return NULL;
+
+ ret = clock_settime((clockid_t)clk_id, &tp);
+ if (ret != 0) {
+ PyErr_SetFromErrno(PyExc_IOError);
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(clock_settime_doc,
+"clock_settime(clk_id, time)\n\
+\n\
+Set the time of the specified clock clk_id.");
#endif
#ifdef HAVE_CLOCK_GETRES
@@ -983,6 +1010,9 @@ static PyMethodDef time_methods[] = {
#ifdef HAVE_CLOCK_GETTIME
{"clock_gettime", time_clock_gettime, METH_VARARGS, clock_gettime_doc},
#endif
+#ifdef HAVE_CLOCK_GETTIME
+ {"clock_settime", time_clock_settime, METH_VARARGS, clock_settime_doc},
+#endif
#ifdef HAVE_CLOCK_GETRES
{"clock_getres", time_clock_getres, METH_VARARGS, clock_getres_doc},
#endif