static PyObject * oe_lutimes(PyObject *self, PyObject *args) { // (str) filename, (tuple) (atime, mtime) char *path; PyObject *ftimes; if (!PyArg_ParseTuple( args, "etO:utime", Py_FileSystemDefaultEncoding, &path, &ftimes )) return NULL; struct timeval tv[2]; if (PyTuple_Check(ftimes) && PyTuple_Size(ftimes) == 2) { int i; for (i=0; i<2; i++) { if ( extract_time(PyTuple_GET_ITEM(ftimes, i), &tv[i].tv_sec, &tv[i].tv_usec) == -1 ) { PyMem_Free(path); return NULL; } } Py_BEGIN_ALLOW_THREADS i = lutimes(path, tv); Py_END_ALLOW_THREADS if (i < 0) return posix_error_with_allocated_filename(path); }
PyObject *listdir(PyObject *self, PyObject *args) { char *name = NULL; PyObject *d, *v; DIR *dirp; struct dirent *ep; int arg_is_unicode = 1; errno = 0; if (!PyArg_ParseTuple(args, "U:listdir", &v)) { arg_is_unicode = 0; PyErr_Clear(); } if (!PyArg_ParseTuple(args, "et:listdir", Py_FileSystemDefaultEncoding, &name)) return NULL; if ((dirp = opendir(name)) == NULL) { return posix_error_with_allocated_filename(name); } if ((d = PyList_New(0)) == NULL) { closedir(dirp); PyMem_Free(name); return NULL; } for (;;) { errno = 0; Py_BEGIN_ALLOW_THREADS ep = readdir(dirp); Py_END_ALLOW_THREADS if (ep == NULL) { if (errno == 0) { break; } else { closedir(dirp); Py_DECREF(d); return posix_error_with_allocated_filename(name); } } if (ep->d_name[0] == '.' && (NAMLEN(ep) == 1 || (ep->d_name[1] == '.' && NAMLEN(ep) == 2))) continue; v = PyString_FromStringAndSize(ep->d_name, NAMLEN(ep)); if (v == NULL) { Py_DECREF(d); d = NULL; break; } #ifdef Py_USING_UNICODE if (arg_is_unicode) { PyObject *w; w = PyUnicode_FromEncodedObject(v, Py_FileSystemDefaultEncoding, "strict"); if (w != NULL) { Py_DECREF(v); v = w; } else { /* fall back to the original byte string, as discussed in patch #683592 */ PyErr_Clear(); } } #endif if (PyList_Append(d, v) != 0) { Py_DECREF(v); Py_DECREF(d); d = NULL; break; } Py_DECREF(v); } closedir(dirp); PyMem_Free(name); return d; }