Changeset 10 for python/trunk/Modules/posixmodule.c
- Timestamp:
- Sep 3, 2010, 5:33:06 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk/Modules/posixmodule.c
r2 r10 34 34 # include <unixio.h> 35 35 #endif /* defined(__VMS) */ 36 37 #if defined(__KLIBC__) 38 #include <sys/socket.h> 39 #endif 36 40 37 41 #ifdef __cplusplus … … 132 136 #define fsync _commit 133 137 #else 134 #if defined(PYOS_OS2) && defined(PYCC_GCC) || defined(__VMS)138 #if (defined(PYOS_OS2) && defined(PYCC_GCC) && !defined(__KLIBC__)) || defined(__VMS) 135 139 /* Everything needed is defined in PC/os2emx/pyconfig.h or vms/pyconfig.h */ 136 140 #else /* all other compilers */ … … 428 432 Py_DECREF(v); 429 433 } 434 #ifdef LIBPATHSTRICT 435 buffer[0] = buffer[1] = buffer[2] = buffer[3] = '\0'; 436 rc = DosQueryExtLIBPATH(buffer, LIBPATHSTRICT); 437 if (rc == NO_ERROR) { /* (not a typo, envname is NOT 'LIBPATH_STRICT') */ 438 PyObject *v = PyString_FromString(buffer); 439 PyDict_SetItemString(d, "LIBPATHSTRICT", v); 440 Py_DECREF(v); 441 } 442 #endif 430 443 } 431 444 #endif … … 1650 1663 #ifdef MS_WINDOWS 1651 1664 return win32_1str(args, "chdir", "s:chdir", win32_chdir, "U:chdir", win32_wchdir); 1652 #elif defined(PYOS_OS2) && defined(PYCC_GCC)1653 return posix_1str(args, "et:chdir", _chdir2);1654 1665 #elif defined(__VMS) 1655 1666 return posix_1str(args, "et:chdir", (int (*)(const char *))chdir); … … 1987 1998 break; 1988 1999 } 1989 #if defined(PYOS_OS2) && defined(PYCC_GCC)1990 res = _getcwd2(tmpbuf, bufsize);1991 #else1992 2000 res = getcwd(tmpbuf, bufsize); 1993 #endif1994 2001 1995 2002 if (res == NULL) { … … 2051 2058 2052 2059 Py_BEGIN_ALLOW_THREADS 2053 #if defined(PYOS_OS2) && defined(PYCC_GCC)2054 res = _getcwd2(buf, sizeof buf);2055 #else2056 2060 res = getcwd(buf, sizeof buf); 2057 #endif2058 2061 Py_END_ALLOW_THREADS 2059 2062 if (res == NULL) … … 2245 2248 return d; 2246 2249 2247 #elif defined(PYOS_OS2 )2250 #elif defined(PYOS_OS2_00) // YD os2 api does not support path rewriting 2248 2251 2249 2252 #ifndef MAX_PATH … … 3117 3120 #if defined(PYOS_OS2) 3118 3121 /* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */ 3119 if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) { 3122 if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0 3123 && stricmp(k, "LIBPATHSTRICT") != 0) { 3120 3124 #endif 3121 3125 len = PyString_Size(key) + PyString_Size(val) + 2; … … 4216 4220 char *mode = "r"; 4217 4221 int bufsize = -1; 4222 int unset_emxshell = 0; 4218 4223 FILE *fp; 4219 4224 PyObject *f; 4220 4225 if (!PyArg_ParseTuple(args, "s|si:popen", &name, &mode, &bufsize)) 4221 4226 return NULL; 4227 /* a little hack for making sure commands.getstatusoutput works 4228 * (ASSUMES that COMSPEC isn't a posix shell.) */ 4229 if (name[0] == '{' && !getenv("EMXSHELL")) { 4230 char path[512]; 4231 _searchenv("sh.exe", "PATH", path); 4232 if (!path[0]) 4233 _searchenv("ash.exe", "PATH", path); 4234 if (!path[0]) 4235 _searchenv("bash.exe", "PATH", path); 4236 if (path[0]) 4237 unset_emxshell = setenv("EMXSHELL", path, 0) == 0; 4238 } 4222 4239 Py_BEGIN_ALLOW_THREADS 4223 4240 fp = popen(name, mode); 4224 4241 Py_END_ALLOW_THREADS 4242 if (unset_emxshell) 4243 unsetenv("EMXSHELL"); 4225 4244 if (fp == NULL) 4226 4245 return posix_error(); … … 4372 4391 FILE *p_s[3]; 4373 4392 int file_count, i, pipe_err; 4374 pid_t pipe_pid ;4393 pid_t pipe_pid = -1; 4375 4394 char *shell, *sh_name, *opt, *rd_mode, *wr_mode; 4376 4395 PyObject *f, *p_f[3]; … … 4391 4410 if ((shell = getenv("EMXSHELL")) == NULL) 4392 4411 if ((shell = getenv("COMSPEC")) == NULL) 4412 if ((shell = getenv("SHELL")) == NULL) 4413 if ((shell = getenv("OS2_SHELL")) == NULL) 4393 4414 { 4394 4415 errno = ENOENT; … … 4429 4450 i = pipe_err = 0; 4430 4451 while ((pipe_err == 0) && (i < file_count)) 4452 #ifndef __KLIBC__ 4431 4453 pipe_err = pipe((int *)&p_fd[i++]); 4454 #else 4455 pipe_err = socketpair(AF_UNIX, SOCK_STREAM,0,(int *)&p_fd[i++]); 4456 #endif 4432 4457 if (pipe_err < 0) 4433 4458 { … … 6590 6615 posix_pipe(PyObject *self, PyObject *noargs) 6591 6616 { 6592 #if defined(PYOS_OS2) 6617 #if defined(PYOS_OS2) && !defined(__KLIBC__) 6593 6618 HFILE read, write; 6594 6619 APIRET rc; … … 6606 6631 int res; 6607 6632 Py_BEGIN_ALLOW_THREADS 6633 #ifndef __KLIBC__ 6608 6634 res = pipe(fds); 6635 #else 6636 res = socketpair(AF_UNIX, SOCK_STREAM,0, fds); 6637 #endif 6609 6638 Py_END_ALLOW_THREADS 6610 6639 if (res != 0) … … 6796 6825 if (rc != NO_ERROR) 6797 6826 return os2_error(rc); 6827 #ifdef LIBPATHSTRICT 6828 } else if (stricmp(s1, "LIBPATHSTRICT") == 0) { 6829 APIRET rc; 6830 6831 rc = DosSetExtLIBPATH(s2, LIBPATHSTRICT); 6832 if (rc != NO_ERROR) 6833 return os2_error(rc); 6834 #endif 6798 6835 } else { 6799 #endif 6836 #endif /* OS2 */ 6800 6837 6801 6838 /* XXX This can leak memory -- not easy to fix :-( */ … … 8429 8466 } 8430 8467 #endif 8468 8469 #ifdef __EMX__ 8470 /* Use openssl random routine */ 8471 #include <openssl/rand.h> 8472 PyDoc_STRVAR(os2_urandom__doc__, 8473 "urandom(n) -> str\n\n\ 8474 Return a string of n random bytes suitable for cryptographic use."); 8475 8476 static PyObject* 8477 os2_urandom(PyObject *self, PyObject *args) 8478 { 8479 int howMany; 8480 PyObject* result; 8481 8482 /* Read arguments */ 8483 if (! PyArg_ParseTuple(args, "i:urandom", &howMany)) 8484 return NULL; 8485 if (howMany < 0) 8486 return PyErr_Format(PyExc_ValueError, 8487 "negative argument not allowed"); 8488 8489 /* Allocate bytes */ 8490 result = PyString_FromStringAndSize(NULL, howMany); 8491 if (result != NULL) { 8492 /* Get random data */ 8493 if (RAND_pseudo_bytes((unsigned char*) 8494 PyString_AS_STRING(result), 8495 howMany) < 0) { 8496 Py_DECREF(result); 8497 return PyErr_Format(PyExc_ValueError, 8498 "RAND_pseudo_bytes"); 8499 } 8500 } 8501 return result; 8502 } 8503 #endif 8504 8431 8505 8432 8506 static PyMethodDef posix_methods[] = { … … 8740 8814 {"urandom", vms_urandom, METH_VARARGS, vms_urandom__doc__}, 8741 8815 #endif 8816 #ifdef __EMX__ 8817 {"urandom", os2_urandom, METH_VARARGS, os2_urandom__doc__}, 8818 #endif 8742 8819 {NULL, NULL} /* Sentinel */ 8743 8820 }; … … 8756 8833 APIRET rc; 8757 8834 ULONG values[QSV_MAX+1]; 8758 PyObject *v;8759 8835 char *ver, tmp[50]; 8760 8836 … … 8785 8861 default: 8786 8862 PyOS_snprintf(tmp, sizeof(tmp), 8787 "% d-%d", values[QSV_VERSION_MAJOR],8863 "%ld-%ld", values[QSV_VERSION_MAJOR], 8788 8864 values[QSV_VERSION_MINOR]); 8789 8865 ver = &tmp[0];
Note:
See TracChangeset
for help on using the changeset viewer.