Ignore:
Timestamp:
Sep 3, 2010, 5:33:06 PM (15 years ago)
Author:
Yuri Dario
Message:

python: merged offline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/trunk/Modules/posixmodule.c

    r2 r10  
    3434#    include <unixio.h>
    3535#endif /* defined(__VMS) */
     36
     37#if defined(__KLIBC__)
     38#include <sys/socket.h>
     39#endif
    3640
    3741#ifdef __cplusplus
     
    132136#define fsync _commit
    133137#else
    134 #if defined(PYOS_OS2) && defined(PYCC_GCC) || defined(__VMS)
     138#if (defined(PYOS_OS2) && defined(PYCC_GCC) && !defined(__KLIBC__)) || defined(__VMS)
    135139/* Everything needed is defined in PC/os2emx/pyconfig.h or vms/pyconfig.h */
    136140#else                   /* all other compilers */
     
    428432            Py_DECREF(v);
    429433        }
     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
    430443    }
    431444#endif
     
    16501663#ifdef MS_WINDOWS
    16511664        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);
    16541665#elif defined(__VMS)
    16551666        return posix_1str(args, "et:chdir", (int (*)(const char *))chdir);
     
    19871998                        break;
    19881999                }
    1989 #if defined(PYOS_OS2) && defined(PYCC_GCC)
    1990                 res = _getcwd2(tmpbuf, bufsize);
    1991 #else
    19922000                res = getcwd(tmpbuf, bufsize);
    1993 #endif
    19942001
    19952002                if (res == NULL) {
     
    20512058
    20522059        Py_BEGIN_ALLOW_THREADS
    2053 #if defined(PYOS_OS2) && defined(PYCC_GCC)
    2054         res = _getcwd2(buf, sizeof buf);
    2055 #else
    20562060        res = getcwd(buf, sizeof buf);
    2057 #endif
    20582061        Py_END_ALLOW_THREADS
    20592062        if (res == NULL)
     
    22452248        return d;
    22462249
    2247 #elif defined(PYOS_OS2)
     2250#elif defined(PYOS_OS2_00) // YD os2 api does not support path rewriting
    22482251
    22492252#ifndef MAX_PATH
     
    31173120#if defined(PYOS_OS2)
    31183121        /* 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) {
    31203124#endif
    31213125                len = PyString_Size(key) + PyString_Size(val) + 2;
     
    42164220        char *mode = "r";
    42174221        int bufsize = -1;
     4222        int unset_emxshell = 0;
    42184223        FILE *fp;
    42194224        PyObject *f;
    42204225        if (!PyArg_ParseTuple(args, "s|si:popen", &name, &mode, &bufsize))
    42214226                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        }
    42224239        Py_BEGIN_ALLOW_THREADS
    42234240        fp = popen(name, mode);
    42244241        Py_END_ALLOW_THREADS
     4242        if (unset_emxshell)
     4243                unsetenv("EMXSHELL");
    42254244        if (fp == NULL)
    42264245                return posix_error();
     
    43724391        FILE *p_s[3];
    43734392        int file_count, i, pipe_err;
    4374         pid_t pipe_pid;
     4393        pid_t pipe_pid = -1;
    43754394        char *shell, *sh_name, *opt, *rd_mode, *wr_mode;
    43764395        PyObject *f, *p_f[3];
     
    43914410        if ((shell = getenv("EMXSHELL")) == NULL)
    43924411                if ((shell = getenv("COMSPEC")) == NULL)
     4412                        if ((shell = getenv("SHELL")) == NULL)
     4413                                if ((shell = getenv("OS2_SHELL")) == NULL)
    43934414                {
    43944415                        errno = ENOENT;
     
    44294450        i = pipe_err = 0;
    44304451        while ((pipe_err == 0) && (i < file_count))
     4452#ifndef __KLIBC__
    44314453                pipe_err = pipe((int *)&p_fd[i++]);
     4454#else
     4455                pipe_err = socketpair(AF_UNIX, SOCK_STREAM,0,(int *)&p_fd[i++]);
     4456#endif
    44324457        if (pipe_err < 0)
    44334458        {
     
    65906615posix_pipe(PyObject *self, PyObject *noargs)
    65916616{
    6592 #if defined(PYOS_OS2)
     6617#if defined(PYOS_OS2) && !defined(__KLIBC__)
    65936618    HFILE read, write;
    65946619    APIRET rc;
     
    66066631        int res;
    66076632        Py_BEGIN_ALLOW_THREADS
     6633#ifndef __KLIBC__
    66086634        res = pipe(fds);
     6635#else
     6636        res = socketpair(AF_UNIX, SOCK_STREAM,0, fds);
     6637#endif
    66096638        Py_END_ALLOW_THREADS
    66106639        if (res != 0)
     
    67966825        if (rc != NO_ERROR)
    67976826            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
    67986835    } else {
    6799 #endif
     6836#endif /* OS2 */
    68006837
    68016838        /* XXX This can leak memory -- not easy to fix :-( */
     
    84298466}
    84308467#endif
     8468
     8469#ifdef __EMX__
     8470/* Use openssl random routine */
     8471#include <openssl/rand.h>
     8472PyDoc_STRVAR(os2_urandom__doc__,
     8473"urandom(n) -> str\n\n\
     8474Return a string of n random bytes suitable for cryptographic use.");
     8475
     8476static PyObject*
     8477os2_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
    84318505
    84328506static PyMethodDef posix_methods[] = {
     
    87408814        {"urandom", vms_urandom, METH_VARARGS, vms_urandom__doc__},
    87418815 #endif
     8816 #ifdef __EMX__
     8817        {"urandom", os2_urandom, METH_VARARGS, os2_urandom__doc__},
     8818 #endif
    87428819        {NULL,          NULL}            /* Sentinel */
    87438820};
     
    87568833    APIRET    rc;
    87578834    ULONG     values[QSV_MAX+1];
    8758     PyObject *v;
    87598835    char     *ver, tmp[50];
    87608836
     
    87858861    default:
    87868862        PyOS_snprintf(tmp, sizeof(tmp),
    8787                       "%d-%d", values[QSV_VERSION_MAJOR],
     8863                      "%ld-%ld", values[QSV_VERSION_MAJOR],
    87888864                      values[QSV_VERSION_MINOR]);
    87898865        ver = &tmp[0];
Note: See TracChangeset for help on using the changeset viewer.