+static PyObject *open_noatime(PyObject *self, PyObject *args)
+{
+ char *filename = NULL;
+ int attrs, attrs_noatime, fd;
+ if (!PyArg_ParseTuple(args, "s", &filename))
+ return NULL;
+ attrs = O_RDONLY;
+#ifdef O_NOFOLLOW
+ attrs |= O_NOFOLLOW;
+#endif
+#ifdef O_LARGEFILE
+ attrs |= O_LARGEFILE;
+#endif
+ attrs_noatime = attrs;
+#ifdef O_NOATIME
+ attrs_noatime |= O_NOATIME;
+#endif
+ fd = open(filename, attrs_noatime);
+ if (fd < 0 && errno == EPERM)
+ {
+ // older Linux kernels would return EPERM if you used O_NOATIME
+ // and weren't the file's owner. This pointless restriction was
+ // relaxed eventually, but we have to handle it anyway.
+ // (VERY old kernels didn't recognized O_NOATIME, but they would
+ // just harmlessly ignore it, so this branch won't trigger)
+ fd = open(filename, attrs);
+ }
+ if (fd < 0)
+ return PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename);
+ return Py_BuildValue("i", fd);
+}
+
+