{
/* XXX We should pass the function name along in the future.
(_winreg.c also wants to pass the function name.)
- This would however require an additional param to the
+ This would however require an additional param to the
Windows error object, which is non-trivial.
*/
errno = GetLastError();
{
char *path1 = NULL;
int res;
- if (!PyArg_ParseTuple(args, format,
+ if (!PyArg_ParseTuple(args, format,
Py_FileSystemDefaultEncoding, &path1))
return NULL;
Py_BEGIN_ALLOW_THREADS
char *path1 = NULL, *path2 = NULL;
int res;
if (!PyArg_ParseTuple(args, format,
- Py_FileSystemDefaultEncoding, &path1,
+ Py_FileSystemDefaultEncoding, &path1,
Py_FileSystemDefaultEncoding, &path2))
return NULL;
Py_BEGIN_ALLOW_THREADS
return Py_None;
}
-static char stat_result__doc__[] =
+static char stat_result__doc__[] =
"stat_result: Result from stat or lstat.\n\n\
This object may be accessed either as a tuple of\n\
(mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)\n\
10
};
-static char statvfs_result__doc__[] =
+static char statvfs_result__doc__[] =
"statvfs_result: Result from statvfs or fstatvfs.\n\n\
This object may be accessed either as a tuple of\n\
(bsize,frsize,blocks,bfree,bavail,files,ffree,favail,flag,namemax),\n\
static PyTypeObject StatResultType;
static PyTypeObject StatVFSResultType;
-/* pack a system stat C structure into the Python stat tuple
+/* pack a system stat C structure into the Python stat tuple
(used by posix_stat() and posix_fstat()) */
static PyObject*
_pystat_fromstructstat(STRUCT_STAT st)
PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long)st.st_mode));
#ifdef HAVE_LARGEFILE_SUPPORT
- PyStructSequence_SET_ITEM(v, 1,
+ PyStructSequence_SET_ITEM(v, 1,
PyLong_FromLongLong((LONG_LONG)st.st_ino));
#else
PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long)st.st_ino));
#endif
#if defined(HAVE_LONG_LONG) && !defined(MS_WINDOWS)
- PyStructSequence_SET_ITEM(v, 2,
+ PyStructSequence_SET_ITEM(v, 2,
PyLong_FromLongLong((LONG_LONG)st.st_dev));
#else
PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long)st.st_dev));
PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long)st.st_uid));
PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long)st.st_gid));
#ifdef HAVE_LARGEFILE_SUPPORT
- PyStructSequence_SET_ITEM(v, 6,
+ PyStructSequence_SET_ITEM(v, 6,
PyLong_FromLongLong((LONG_LONG)st.st_size));
#else
PyStructSequence_SET_ITEM(v, 6, PyInt_FromLong(st.st_size));
#endif
#if SIZEOF_TIME_T > SIZEOF_LONG
- PyStructSequence_SET_ITEM(v, 7,
+ PyStructSequence_SET_ITEM(v, 7,
PyLong_FromLongLong((LONG_LONG)st.st_atime));
- PyStructSequence_SET_ITEM(v, 8,
+ PyStructSequence_SET_ITEM(v, 8,
PyLong_FromLongLong((LONG_LONG)st.st_mtime));
- PyStructSequence_SET_ITEM(v, 9,
+ PyStructSequence_SET_ITEM(v, 9,
PyLong_FromLongLong((LONG_LONG)st.st_ctime));
#else
PyStructSequence_SET_ITEM(v, 7, PyInt_FromLong((long)st.st_atime));
#endif
#ifdef HAVE_ST_BLKSIZE
- PyStructSequence_SET_ITEM(v, ST_BLKSIZE_IDX,
+ PyStructSequence_SET_ITEM(v, ST_BLKSIZE_IDX,
PyInt_FromLong((long)st.st_blksize));
#endif
#ifdef HAVE_ST_BLOCKS
- PyStructSequence_SET_ITEM(v, ST_BLOCKS_IDX,
+ PyStructSequence_SET_ITEM(v, ST_BLOCKS_IDX,
PyInt_FromLong((long)st.st_blocks));
#endif
#ifdef HAVE_ST_RDEV
char pathcopy[MAX_PATH];
#endif /* MS_WIN32 */
- if (!PyArg_ParseTuple(args, format,
+ if (!PyArg_ParseTuple(args, format,
Py_FileSystemDefaultEncoding, &path))
return NULL;
pathfree = path;
char *path = NULL;
int i;
int res;
- if (!PyArg_ParseTuple(args, "eti", Py_FileSystemDefaultEncoding,
+ if (!PyArg_ParseTuple(args, "eti", Py_FileSystemDefaultEncoding,
&path, &i))
return NULL;
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_CHROOT
-static char posix_chroot__doc__[] =
+static char posix_chroot__doc__[] =
"chroot(path) -> None\n\
Change root directory to path.";
char *path = NULL;
int uid, gid;
int res;
- if (!PyArg_ParseTuple(args, "etii:chown",
- Py_FileSystemDefaultEncoding, &path,
+ if (!PyArg_ParseTuple(args, "etii:chown",
+ Py_FileSystemDefaultEncoding, &path,
&uid, &gid))
return NULL;
Py_BEGIN_ALLOW_THREADS
int len = sizeof(namebuf)/sizeof(namebuf[0]);
char ch;
- if (!PyArg_ParseTuple(args, "et#:listdir",
+ if (!PyArg_ParseTuple(args, "et#:listdir",
Py_FileSystemDefaultEncoding, &bufptr, &len))
return NULL;
ch = namebuf[len-1];
int insize = sizeof(inbuf)/sizeof(inbuf[0]);
char outbuf[MAX_PATH*2];
char *temp;
- if (!PyArg_ParseTuple (args, "et#:_getfullpathname",
- Py_FileSystemDefaultEncoding, &inbufp,
+ if (!PyArg_ParseTuple (args, "et#:_getfullpathname",
+ Py_FileSystemDefaultEncoding, &inbufp,
&insize))
return NULL;
if (!GetFullPathName(inbuf, sizeof(outbuf)/sizeof(outbuf[0]),
int res;
char *path = NULL;
int mode = 0777;
- if (!PyArg_ParseTuple(args, "et|i:mkdir",
+ if (!PyArg_ParseTuple(args, "et|i:mkdir",
Py_FileSystemDefaultEncoding, &path, &mode))
return NULL;
Py_BEGIN_ALLOW_THREADS
priority (as required by almost all standards out there) and the
Linux/FreeBSD/BSDI one, which returns '0' on success and advices
the use of getpriority() to get the new priority.
-
+
If we are of the nice family that returns the new priority, we
need to clear errno before the call, and check if errno is filled
before calling posix_error() on a returnvalue of -1, because the
for (i = 0; i < argc; i++) {
if (!PyArg_Parse((*getitem)(argv, i), "s", &argvlist[i])) {
PyMem_DEL(argvlist);
- PyErr_SetString(PyExc_TypeError,
+ PyErr_SetString(PyExc_TypeError,
"execv() arg 2 must contain only strings");
return NULL;
-
+
}
}
argvlist[argc] = NULL;
}
if (argc == 0) {
- PyErr_SetString(PyExc_ValueError,
+ PyErr_SetString(PyExc_ValueError,
"execve() arg 2 must not be empty");
return NULL;
}
vals = PyMapping_Values(env);
if (!keys || !vals)
goto fail_2;
-
+
for (pos = 0; pos < i; pos++) {
char *p, *k, *v;
size_t len;
val = PyList_GetItem(vals, pos);
if (!key || !val)
goto fail_2;
-
+
if (!PyArg_Parse(key, "s;execve() arg 3 contains a non-string key", &k) ||
!PyArg_Parse(val, "s;execve() arg 3 contains a non-string value", &v))
{
#else /* BAD_EXEC_PROTOTYPES */
execve(path, argvlist, envlist);
#endif /* BAD_EXEC_PROTOTYPES */
-
+
/* If we get here it's definitely an error */
(void) posix_error();
for (i = 0; i < argc; i++) {
if (!PyArg_Parse((*getitem)(argv, i), "s", &argvlist[i])) {
PyMem_DEL(argvlist);
- PyErr_SetString(PyExc_TypeError,
+ PyErr_SetString(PyExc_TypeError,
"spawnv() arg 2 must contain only strings");
return NULL;
}
if (mode == _OLD_P_OVERLAY)
mode = _P_OVERLAY;
-
+
Py_BEGIN_ALLOW_THREADS
spawnval = _spawnv(mode, path, argvlist);
Py_END_ALLOW_THREADS
-
+
PyMem_DEL(argvlist);
if (spawnval == -1)
vals = PyMapping_Values(env);
if (!keys || !vals)
goto fail_2;
-
+
for (pos = 0; pos < i; pos++) {
char *p, *k, *v;
size_t len;
val = PyList_GetItem(vals, pos);
if (!key || !val)
goto fail_2;
-
+
if (!PyArg_Parse(key, "s;spawnve() arg 3 contains a non-string key", &k) ||
!PyArg_Parse(val, "s;spawnve() arg 3 contains a non-string value", &v))
{
posix_forkpty(PyObject *self, PyObject *args)
{
int master_fd, pid;
-
+
if (!PyArg_ParseTuple(args, ":forkpty"))
return NULL;
pid = forkpty(&master_fd, NULL, NULL, NULL);
{
PyObject *f, *s;
int tm = 0;
-
+
char *cmdstring;
char *mode = "r";
int bufsize = -1;
return NULL;
s = PyTuple_New(0);
-
+
if (*mode == 'r')
tm = _O_RDONLY;
else if (*mode != 'w') {
return NULL;
} else
tm = _O_WRONLY;
-
+
if (bufsize != -1) {
PyErr_SetString(PyExc_ValueError, "popen() arg 3 must be -1");
return NULL;
{
PyObject *f;
int tm=0;
-
+
char *cmdstring;
char *mode = "t";
int bufsize = -1;
if (!PyArg_ParseTuple(args, "s|si:popen2", &cmdstring, &mode, &bufsize))
return NULL;
-
+
if (*mode == 't')
tm = _O_TEXT;
else if (*mode != 'b') {
return NULL;
} else
tm = _O_BINARY;
-
+
if (bufsize != -1) {
PyErr_SetString(PyExc_ValueError, "popen2() arg 3 must be -1");
return NULL;
}
f = _PyPopen(cmdstring, tm, POPEN_2);
-
+
return f;
}
{
PyObject *f;
int tm = 0;
-
+
char *cmdstring;
char *mode = "t";
int bufsize = -1;
if (!PyArg_ParseTuple(args, "s|si:popen3", &cmdstring, &mode, &bufsize))
return NULL;
-
+
if (*mode == 't')
tm = _O_TEXT;
else if (*mode != 'b') {
return NULL;
} else
tm = _O_BINARY;
-
+
if (bufsize != -1) {
PyErr_SetString(PyExc_ValueError, "popen3() arg 3 must be -1");
return NULL;
}
f = _PyPopen(cmdstring, tm, POPEN_3);
-
+
return f;
}
/*
* Variation on win32pipe.popen
*
- * The result of this function is 2 pipes - the processes stdin,
+ * The result of this function is 2 pipes - the processes stdin,
* and stdout+stderr combined as a single pipe.
*/
{
PyObject *f;
int tm = 0;
-
+
char *cmdstring;
char *mode = "t";
int bufsize = -1;
if (!PyArg_ParseTuple(args, "s|si:popen4", &cmdstring, &mode, &bufsize))
return NULL;
-
+
if (*mode == 't')
tm = _O_TEXT;
else if (*mode != 'b') {
x = i+1;
modulepath[x] = '\0';
/* Create the full-name to w9xpopen, so we can test it exists */
- strncat(modulepath,
- szConsoleSpawn,
+ strncat(modulepath,
+ szConsoleSpawn,
(sizeof(modulepath)/sizeof(modulepath[0]))
-strlen(modulepath));
if (stat(modulepath, &statinfo) != 0) {
- /* Eeek - file-not-found - possibly an embedding
- situation - see if we can locate it in sys.prefix
+ /* Eeek - file-not-found - possibly an embedding
+ situation - see if we can locate it in sys.prefix
*/
- strncpy(modulepath,
- Py_GetExecPrefix(),
+ strncpy(modulepath,
+ Py_GetExecPrefix(),
sizeof(modulepath)/sizeof(modulepath[0]));
if (modulepath[strlen(modulepath)-1] != '\\')
strcat(modulepath, "\\");
- strncat(modulepath,
- szConsoleSpawn,
+ strncat(modulepath,
+ szConsoleSpawn,
(sizeof(modulepath)/sizeof(modulepath[0]))
-strlen(modulepath));
/* No where else to look - raise an easily identifiable
(well, it confused me for a while ;-)
*/
if (stat(modulepath, &statinfo) != 0) {
- PyErr_Format(PyExc_RuntimeError,
+ PyErr_Format(PyExc_RuntimeError,
"Can not locate '%s' which is needed "
"for popen to work with your shell "
"or platform.",
}
}
x = i + strlen(s3) + strlen(cmdstring) + 1 +
- strlen(modulepath) +
+ strlen(modulepath) +
strlen(szConsoleSpawn) + 1;
s2 = (char *)_alloca(x);
"use as the shell");
return FALSE;
}
-
+
ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
siStartInfo.cb = sizeof(STARTUPINFO);
siStartInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
HANDLE hChildStdinRd, hChildStdinWr, hChildStdoutRd, hChildStdoutWr,
hChildStderrRd, hChildStderrWr, hChildStdinWrDup, hChildStdoutRdDup,
hChildStderrRdDup, hProcess; /* hChildStdoutWrDup; */
-
+
SECURITY_ATTRIBUTES saAttr;
BOOL fSuccess;
int fd1, fd2, fd3;
/* Close the inheritable version of ChildStdErr that we're using. */
CloseHandle(hChildStderrRd);
}
-
+
switch (n) {
case POPEN_1:
switch (mode & (_O_RDONLY | _O_TEXT | _O_BINARY | _O_WRONLY)) {
}
file_count = 1;
break;
-
+
case POPEN_2:
case POPEN_4:
{
char *m1, *m2;
PyObject *p1, *p2;
-
+
if (mode && _O_TEXT) {
m1 = "r";
m2 = "w";
file_count = 2;
break;
}
-
+
case POPEN_3:
{
char *m1, *m2;
PyObject *p1, *p2, *p3;
-
+
if (mode && _O_TEXT) {
m1 = "r";
m2 = "w";
}
}
}
-
+
/*
* Clean up our localized references for the dictionary keys
* and value since PyDict_SetItem will Py_INCREF any copies
if (!CloseHandle(hChildStdinRd))
return win32_error("CloseHandle", NULL);
-
+
if (!CloseHandle(hChildStdoutWr))
return win32_error("CloseHandle", NULL);
-
+
if ((n != 4) && (!CloseHandle(hChildStderrWr)))
return win32_error("CloseHandle", NULL);
PyObject *groups;
int i, len;
gid_t grouplist[MAX_GROUPS];
-
+
if (!PyArg_ParseTuple(args, "O:setgid", &groups))
return NULL;
if (!PySequence_Check(groups)) {
#ifndef HZ
#define HZ 60 /* Universal constant :-) */
#endif /* HZ */
-
+
#if defined(PYCC_VACPP) && defined(PYOS_OS2)
static long
system_uptime(void)
int flag;
int mode = 0777;
int fd;
- if (!PyArg_ParseTuple(args, "eti|i",
+ if (!PyArg_ParseTuple(args, "eti|i",
Py_FileSystemDefaultEncoding, &file,
&flag, &mode))
return NULL;
Py_END_ALLOW_THREADS
if (res != 0)
return posix_error();
-
+
return _pystat_fromstructstat(st);
}
char **newenv;
if (!(newenv = malloc(esiz * sizeof(char *))))
return 1;
-
+
for (ep=environ, epp=newenv ; *ep ;)
*epp++ = *ep++;
*epp++ = newval;
* get re-set with another call for the same key. */
static PyObject *posix_putenv_garbage;
-static PyObject *
+static PyObject *
posix_putenv(PyObject *self, PyObject *args)
{
char *s1, *s2;
/* Remove the key from posix_putenv_garbage;
* this will cause it to be collected. This has to
- * happen after the real unsetenv() call because the
+ * happen after the real unsetenv() call because the
* old value was still accessible until then.
*/
if (PyDict_DelItem(posix_putenv_garbage,
#define status_i status
#endif
status_i = 0;
-
+
if (!PyArg_ParseTuple(args, "i:WIFSTOPPED", &status_i))
{
return NULL;
}
-
+
return Py_BuildValue("i", WIFSTOPPED(status));
#undef status_i
}
#define status_i status
#endif
status_i = 0;
-
+
if (!PyArg_ParseTuple(args, "i:WIFSIGNALED", &status_i))
{
return NULL;
}
-
+
return Py_BuildValue("i", WIFSIGNALED(status));
#undef status_i
}
#define status_i status
#endif
status_i = 0;
-
+
if (!PyArg_ParseTuple(args, "i:WIFEXITED", &status_i))
{
return NULL;
}
-
+
return Py_BuildValue("i", WIFEXITED(status));
#undef status_i
}
#define status_i status
#endif
status_i = 0;
-
+
if (!PyArg_ParseTuple(args, "i:WEXITSTATUS", &status_i))
{
return NULL;
}
-
+
return Py_BuildValue("i", WEXITSTATUS(status));
#undef status_i
}
#define status_i status
#endif
status_i = 0;
-
+
if (!PyArg_ParseTuple(args, "i:WTERMSIG", &status_i))
{
return NULL;
}
-
+
return Py_BuildValue("i", WTERMSIG(status));
#undef status_i
}
#define status_i status
#endif
status_i = 0;
-
+
if (!PyArg_ParseTuple(args, "i:WSTOPSIG", &status_i))
{
return NULL;
}
-
+
return Py_BuildValue("i", WSTOPSIG(status));
#undef status_i
}
#else
PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long) st.f_bsize));
PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) st.f_frsize));
- PyStructSequence_SET_ITEM(v, 2,
+ PyStructSequence_SET_ITEM(v, 2,
PyLong_FromLongLong((LONG_LONG) st.f_blocks));
- PyStructSequence_SET_ITEM(v, 3,
+ PyStructSequence_SET_ITEM(v, 3,
PyLong_FromLongLong((LONG_LONG) st.f_bfree));
PyStructSequence_SET_ITEM(v, 4,
PyLong_FromLongLong((LONG_LONG) st.f_bavail));
- PyStructSequence_SET_ITEM(v, 5,
+ PyStructSequence_SET_ITEM(v, 5,
PyLong_FromLongLong((LONG_LONG) st.f_files));
- PyStructSequence_SET_ITEM(v, 6,
+ PyStructSequence_SET_ITEM(v, 6,
PyLong_FromLongLong((LONG_LONG) st.f_ffree));
- PyStructSequence_SET_ITEM(v, 7,
+ PyStructSequence_SET_ITEM(v, 7,
PyLong_FromLongLong((LONG_LONG) st.f_favail));
PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) st.f_flag));
PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) st.f_namemax));
{
#ifdef F_OK
if (ins(d, "F_OK", (long)F_OK)) return -1;
-#endif
+#endif
#ifdef R_OK
if (ins(d, "R_OK", (long)R_OK)) return -1;
-#endif
+#endif
#ifdef W_OK
if (ins(d, "W_OK", (long)W_OK)) return -1;
-#endif
+#endif
#ifdef X_OK
if (ins(d, "X_OK", (long)X_OK)) return -1;
-#endif
+#endif
#ifdef NGROUPS_MAX
if (ins(d, "NGROUPS_MAX", (long)NGROUPS_MAX)) return -1;
#endif
#endif
#ifdef WNOHANG
if (ins(d, "WNOHANG", (long)WNOHANG)) return -1;
-#endif
+#endif
#ifdef O_RDONLY
if (ins(d, "O_RDONLY", (long)O_RDONLY)) return -1;
#endif
if (ins(d, "O_LARGEFILE", (long)O_LARGEFILE)) return -1;
#endif
+/* MS Windows */
+#ifdef O_NOINHERIT
+ /* Don't inherit in child processes. */
+ if (ins(d, "O_NOINHERIT", (long)O_NOINHERIT)) return -1;
+#endif
+#ifdef _O_SHORT_LIVED
+ /* Optimize for short life (keep in memory). */
+ /* MS forgot to define this one with a non-underscore form too. */
+ if (ins(d, "O_SHORT_LIVED", (long)_O_SHORT_LIVED)) return -1;
+#endif
+#ifdef O_TEMPORARY
+ /* Automatically delete when last handle is closed. */
+ if (ins(d, "O_TEMPORARY", (long)O_TEMPORARY)) return -1;
+#endif
+#ifdef O_RANDOM
+ /* Optimize for random access. */
+ if (ins(d, "O_RANDOM", (long)O_RANDOM)) return -1;
+#endif
+#ifdef O_SEQUENTIAL
+ /* Optimize for sequential access. */
+ if (ins(d, "O_SEQUENTIAL", (long)O_SEQUENTIAL)) return -1;
+#endif
+
/* GNU extensions. */
#ifdef O_DIRECT
/* Direct disk access. */
}
-#if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__)
+#if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__)
#define INITFUNC initnt
#define MODNAME "nt"
INITFUNC(void)
{
PyObject *m, *d, *v;
-
+
m = Py_InitModule4(MODNAME,
posix_methods,
posix__doc__,
(PyObject *)NULL,
PYTHON_API_VERSION);
d = PyModule_GetDict(m);
-
+
/* Initialize environ dictionary */
v = convertenviron();
if (v == NULL || PyDict_SetItemString(d, "environ", v) != 0)