chiark / gitweb /
systemd-python: add wrappers for easy functions in sd-login
[elogind.git] / src / python-systemd / pyutil.c
index 79065a11c0db80af63bf8633c7c5007908dc7b5c..9510acdddbcc76a6dfb072b19dc8c9ac30c102e3 100644 (file)
@@ -28,3 +28,19 @@ void cleanup_Py_DECREFp(PyObject **p) {
 
         Py_DECREF(*p);
 }
 
         Py_DECREF(*p);
 }
+
+PyObject* absolute_timeout(uint64_t t) {
+    if (t == (uint64_t) -1)
+        return PyLong_FromLong(-1);
+    else {
+        struct timespec ts;
+        uint64_t n;
+        int msec;
+
+        clock_gettime(CLOCK_MONOTONIC, &ts);
+        n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
+        msec = t > n ? (int) ((t - n + 999) / 1000) : 0;
+
+        return PyLong_FromLong(msec);
+    }
+}