[Python-checkins] CVS: python/dist/src/Modules posixmodule.c,2.118,2.119

Fred L. Drake fdrake@weyr.cnri.reston.va.us
Tue, 14 Dec 1999 16:25:06 -0500 (EST)


Update of /projects/cvsroot/python/dist/src/Modules
In directory weyr:/home/fdrake/projects/python/Modules

Modified Files:
	posixmodule.c 
Log Message:

Added support for getlogin(); does *not* use getlogin_r() where
available since the interface is poorly defined on at least one major
platform (Solaris).

Moved table of constant names for fpathconf() & pathconf() into the
conditional that defines the conv_path_confname() helper; Mark Hammond 
reported that defining the table when none of the constants were
defined causes the compiler to complain (won't allow 0-length array,
imagine that!).

In posix_fpathconf(), use conv_path_confname() as the O& conversion
function, instead of the conv_confname() helper, which has the wrong
signature (posix_pathconf() already used the right thing).


Index: posixmodule.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.118
retrieving revision 2.119
diff -C2 -r2.118 -r2.119
*** posixmodule.c	1999/12/13 16:55:24	2.118
--- posixmodule.c	1999/12/14 21:25:03	2.119
***************
*** 1831,1834 ****
--- 1831,1858 ----
  
  
+ #ifdef HAVE_GETLOGIN
+ static char posix_getlogin__doc__[] = "\
+ getlogin() -> string\n\
+ Return the actual login name.";
+ 
+ static PyObject *
+ posix_getlogin(self, args)
+ 	PyObject *self;
+ 	PyObject *args;
+ {
+     PyObject *result = NULL;
+ 
+     if (PyArg_ParseTuple(args, ":getlogin")) {
+         char *name = getlogin();
+ 
+         if (name == NULL)
+             posix_error();
+         else
+             result = PyString_FromString(name);
+     }
+     return result;
+ }
+ #endif
+ 
  #ifdef HAVE_GETUID
  static char posix_getuid__doc__[] =
***************
*** 3344,3348 ****
   * integer values, allowing those functions to be called with the
   * magic names instead of poluting the module's namespace with tons of
!  * rarely-used constants.
   */
  struct constdef {
--- 3368,3373 ----
   * integer values, allowing those functions to be called with the
   * magic names instead of poluting the module's namespace with tons of
!  * rarely-used constants.  There are three separate tables that use
!  * these definitions.
   */
  struct constdef {
***************
*** 3350,3355 ****
      long value;
  };
  
! static struct constdef posix_constants_pathconf[] = {
  #ifdef _PC_ASYNC_IO
      {"PC_ASYNC_IO",	_PC_ASYNC_IO},
--- 3375,3419 ----
      long value;
  };
+ 
+ static int
+ conv_confname(arg, valuep, table, tablesize)
+      PyObject *arg;
+      int *valuep;
+      struct constdef *table;
+      size_t tablesize;
+ {
+     if (PyInt_Check(arg)) {
+         *valuep = PyInt_AS_LONG(arg);
+         return 1;
+     }
+     if (PyString_Check(arg)) {
+         /* look up the value in the table using a binary search */
+         int lo = 0;
+         int hi = tablesize;
+         int cmp, mid;
+         char *confname = PyString_AS_STRING(arg);
+         while (lo < hi) {
+             mid = (lo + hi) / 2;
+             cmp = strcmp(confname, table[mid].name);
+             if (cmp < 0)
+                 hi = mid;
+             else if (cmp > 0)
+                 lo = mid + 1;
+             else {
+                 *valuep = table[mid].value;
+                 return 1;
+             }
+         }
+         PyErr_SetString(PyExc_ValueError, "unrecognized configuration name");
+     }
+     else
+         PyErr_SetString(PyExc_TypeError,
+                         "configuration names must be strings or integers");
+     return 0;
+ }
+ 
  
! #if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF)
! static struct constdef  posix_constants_pathconf[] = {
  #ifdef _PC_ASYNC_IO
      {"PC_ASYNC_IO",	_PC_ASYNC_IO},
***************
*** 3399,3443 ****
  };
  
- 
  static int
- conv_confname(arg, valuep, table, tablesize)
-      PyObject *arg;
-      int *valuep;
-      struct constdef *table;
-      size_t tablesize;
- {
-     if (PyInt_Check(arg)) {
-         *valuep = PyInt_AS_LONG(arg);
-         return 1;
-     }
-     if (PyString_Check(arg)) {
-         /* look up the value in the table using a binary search */
-         int lo = 0;
-         int hi = tablesize;
-         int cmp, mid;
-         char *confname = PyString_AS_STRING(arg);
-         while (lo < hi) {
-             mid = (lo + hi) / 2;
-             cmp = strcmp(confname, table[mid].name);
-             if (cmp < 0)
-                 hi = mid;
-             else if (cmp > 0)
-                 lo = mid + 1;
-             else {
-                 *valuep = table[mid].value;
-                 return 1;
-             }
-         }
-         PyErr_SetString(PyExc_ValueError, "unrecognized configuration name");
-     }
-     else
-         PyErr_SetString(PyExc_TypeError,
-                         "configuration names must be strings or integers");
-     return 0;
- }
- 
- 
- #if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF)
- static int
  conv_path_confname(arg, valuep)
       PyObject *arg;
--- 3463,3467 ----
***************
*** 3464,3468 ****
      int name, fd;
  
!     if (PyArg_ParseTuple(args, "iO&:fpathconf", &fd, conv_confname, &name)) {
          long limit;
  
--- 3488,3493 ----
      int name, fd;
  
!     if (PyArg_ParseTuple(args, "iO&:fpathconf", &fd,
!                          conv_path_confname, &name)) {
          long limit;
  
***************
*** 3500,3504 ****
          errno = 0;
          limit = pathconf(path, name);
!         if (limit == -1 && errno != 0)
              if (errno == EINVAL)
                  /* could be a path or name problem */
--- 3525,3529 ----
          errno = 0;
          limit = pathconf(path, name);
!         if (limit == -1 && errno != 0) {
              if (errno == EINVAL)
                  /* could be a path or name problem */
***************
*** 3506,3509 ****
--- 3531,3535 ----
              else
                  posix_error_with_filename(path);
+         }
          else
              result = PyInt_FromLong(limit);
***************
*** 4234,4237 ****
--- 4260,4266 ----
  	{"getuid",	posix_getuid, METH_VARARGS, posix_getuid__doc__},
  #endif /* HAVE_GETUID */
+ #ifdef HAVE_GETLOGIN
+ 	{"getlogin",	posix_getlogin, METH_VARARGS, posix_getlogin__doc__},
+ #endif
  #ifdef HAVE_KILL
  	{"kill",	posix_kill, METH_VARARGS, posix_kill__doc__},