Patch #1516912: improve Modules support for OpenVMS.

This commit is contained in:
Neal Norwitz 2006-07-10 01:18:57 +00:00
parent 4a5fbda66d
commit 2a30cd0ef0
9 changed files with 154 additions and 63 deletions

View file

@ -7882,6 +7882,42 @@ win32_urandom(PyObject *self, PyObject *args)
}
#endif
#ifdef __VMS
/* Use openssl random routine */
#include <openssl/rand.h>
PyDoc_STRVAR(vms_urandom__doc__,
"urandom(n) -> str\n\n\
Return a string of n random bytes suitable for cryptographic use.");
static PyObject*
vms_urandom(PyObject *self, PyObject *args)
{
int howMany;
PyObject* result;
/* Read arguments */
if (! PyArg_ParseTuple(args, "i:urandom", &howMany))
return NULL;
if (howMany < 0)
return PyErr_Format(PyExc_ValueError,
"negative argument not allowed");
/* Allocate bytes */
result = PyString_FromStringAndSize(NULL, howMany);
if (result != NULL) {
/* Get random data */
if (RAND_pseudo_bytes((unsigned char*)
PyString_AS_STRING(result),
howMany) < 0) {
Py_DECREF(result);
return PyErr_Format(PyExc_ValueError,
"RAND_pseudo_bytes");
}
}
return result;
}
#endif
static PyMethodDef posix_methods[] = {
{"access", posix_access, METH_VARARGS, posix_access__doc__},
#ifdef HAVE_TTYNAME
@ -8174,6 +8210,9 @@ static PyMethodDef posix_methods[] = {
#endif
#ifdef MS_WINDOWS
{"urandom", win32_urandom, METH_VARARGS, win32_urandom__doc__},
#endif
#ifdef __VMS
{"urandom", vms_urandom, METH_VARARGS, vms_urandom__doc__},
#endif
{NULL, NULL} /* Sentinel */
};