[Python-checkins] python/dist/src/Modules posixmodule.c,2.264,2.265

loewis@users.sourceforge.net loewis@users.sourceforge.net
Thu, 10 Oct 2002 07:27:33 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv3565/Modules

Modified Files:
	posixmodule.c 
Log Message:
Patch #569139: Implementation of major, minor and makedev.


Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.264
retrieving revision 2.265
diff -C2 -d -r2.264 -r2.265
*** posixmodule.c	7 Oct 2002 06:44:21 -0000	2.264
--- posixmodule.c	10 Oct 2002 14:27:30 -0000	2.265
***************
*** 278,284 ****
--- 278,291 ----
  #endif
  
+ #if defined(MAJOR_IN_MKDEV) 
+ #include <sys/mkdev.h>
+ #else
+ #if defined(MAJOR_IN_SYSMACROS)
+ #include <sys/sysmacros.h>
+ #endif
  #if defined(HAVE_MKNOD) && defined(HAVE_SYS_MKDEV_H)
  #include <sys/mkdev.h>
  #endif
+ #endif
  
  /* Return a dictionary corresponding to the POSIX environment table */
***************
*** 5082,5092 ****
  #if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
  PyDoc_STRVAR(posix_mknod__doc__,
! "mknod(filename, [, mode=0600, major, minor])\n\n\
  Create a filesystem node (file, device special file or named pipe)\n\
  named filename. mode specifies both the permissions to use and the\n\
  type of node to be created, being combined (bitwise OR) with one of\n\
  S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. For S_IFCHR and S_IFBLK,\n\
! major and minor define the newly created device special file, otherwise\n\
! they are ignored.");
  
  
--- 5089,5099 ----
  #if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
  PyDoc_STRVAR(posix_mknod__doc__,
! "mknod(filename, [, mode=0600, device])\n\n\
  Create a filesystem node (file, device special file or named pipe)\n\
  named filename. mode specifies both the permissions to use and the\n\
  type of node to be created, being combined (bitwise OR) with one of\n\
  S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. For S_IFCHR and S_IFBLK,\n\
! device defines the newly created device special file (probably using\n\
! os.makedev()), otherwise it is ignored.");
  
  
***************
*** 5096,5107 ****
  	char *filename;
  	int mode = 0600;
! 	int major = 0;
! 	int minor = 0;
  	int res;
! 	if (!PyArg_ParseTuple(args, "s|iii:mknod", &filename,
! 			      &mode, &major, &minor))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
! 	res = mknod(filename, mode, makedev(major, minor));
  	Py_END_ALLOW_THREADS
  	if (res < 0)
--- 5103,5112 ----
  	char *filename;
  	int mode = 0600;
! 	int device = 0;
  	int res;
! 	if (!PyArg_ParseTuple(args, "s|iii:mknod", &filename, &mode, &device))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
! 	res = mknod(filename, mode, device);
  	Py_END_ALLOW_THREADS
  	if (res < 0)
***************
*** 5112,5115 ****
--- 5117,5161 ----
  #endif
  
+ #ifdef HAVE_DEVICE_MACROS
+ PyDoc_STRVAR(posix_major__doc__,
+ "major(device) -> major number\n\
+ Extracts a device major number from a raw device number.");
+ 
+ static PyObject *
+ posix_major(PyObject *self, PyObject *args)
+ {
+ 	int device;
+ 	if (!PyArg_ParseTuple(args, "i:major", &device))
+ 		return NULL;
+ 	return PyInt_FromLong((long)major(device));
+ }
+ 
+ PyDoc_STRVAR(posix_minor__doc__,
+ "minor(device) -> minor number\n\
+ Extracts a device minor number from a raw device number.");
+ 
+ static PyObject *
+ posix_minor(PyObject *self, PyObject *args)
+ {
+ 	int device;
+ 	if (!PyArg_ParseTuple(args, "i:minor", &device))
+ 		return NULL;
+ 	return PyInt_FromLong((long)minor(device));
+ }
+ 
+ PyDoc_STRVAR(posix_makedev__doc__,
+ "makedev(major, minor) -> device number\n\
+ Composes a raw device number from the major and minor device numbers.");
+ 
+ static PyObject *
+ posix_makedev(PyObject *self, PyObject *args)
+ {
+ 	int major, minor;
+ 	if (!PyArg_ParseTuple(args, "ii:makedev", &major, &minor))
+ 		return NULL;
+ 	return PyInt_FromLong((long)makedev(major, minor));
+ }
+ #endif /* device macros */
+ 
  
  #ifdef HAVE_FTRUNCATE
***************
*** 6905,6908 ****
--- 6951,6959 ----
  #if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
  	{"mknod",	posix_mknod, METH_VARARGS, posix_mknod__doc__},
+ #endif
+ #ifdef HAVE_DEVICE_MACROS
+ 	{"major",	posix_major, METH_VARARGS, posix_major__doc__},
+ 	{"minor",	posix_minor, METH_VARARGS, posix_minor__doc__},
+ 	{"makedev",	posix_makedev, METH_VARARGS, posix_makedev__doc__},
  #endif
  #ifdef HAVE_FTRUNCATE