@@ -277,9 +277,16 @@ extern int lstat(const char *, struct stat *);
277277# define STRUCT_STAT struct stat
278278#endif
279279
280+ #if defined(MAJOR_IN_MKDEV )
281+ #include <sys/mkdev.h>
282+ #else
283+ #if defined(MAJOR_IN_SYSMACROS )
284+ #include <sys/sysmacros.h>
285+ #endif
280286#if defined(HAVE_MKNOD ) && defined(HAVE_SYS_MKDEV_H )
281287#include <sys/mkdev.h>
282288#endif
289+ #endif
283290
284291/* Return a dictionary corresponding to the POSIX environment table */
285292#ifdef WITH_NEXT_FRAMEWORK
@@ -5081,28 +5088,26 @@ posix_mkfifo(PyObject *self, PyObject *args)
50815088
50825089#if defined(HAVE_MKNOD ) && defined(HAVE_MAKEDEV )
50835090PyDoc_STRVAR (posix_mknod__doc__ ,
5084- "mknod(filename, [, mode=0600, major, minor ])\n\n\
5091+ "mknod(filename, [, mode=0600, device ])\n\n\
50855092Create a filesystem node (file, device special file or named pipe)\n\
50865093named filename. mode specifies both the permissions to use and the\n\
50875094type of node to be created, being combined (bitwise OR) with one of\n\
50885095S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. For S_IFCHR and S_IFBLK,\n\
5089- major and minor define the newly created device special file, otherwise \n\
5090- they are ignored." );
5096+ device defines the newly created device special file (probably using \n\
5097+ os.makedev()), otherwise it is ignored." );
50915098
50925099
50935100static PyObject *
50945101posix_mknod (PyObject * self , PyObject * args )
50955102{
50965103 char * filename ;
50975104 int mode = 0600 ;
5098- int major = 0 ;
5099- int minor = 0 ;
5105+ int device = 0 ;
51005106 int res ;
5101- if (!PyArg_ParseTuple (args , "s|iii:mknod" , & filename ,
5102- & mode , & major , & minor ))
5107+ if (!PyArg_ParseTuple (args , "s|iii:mknod" , & filename , & mode , & device ))
51035108 return NULL ;
51045109 Py_BEGIN_ALLOW_THREADS
5105- res = mknod (filename , mode , makedev ( major , minor ) );
5110+ res = mknod (filename , mode , device );
51065111 Py_END_ALLOW_THREADS
51075112 if (res < 0 )
51085113 return posix_error ();
@@ -5111,6 +5116,47 @@ posix_mknod(PyObject *self, PyObject *args)
51115116}
51125117#endif
51135118
5119+ #ifdef HAVE_DEVICE_MACROS
5120+ PyDoc_STRVAR (posix_major__doc__ ,
5121+ "major (device ) -> major number \n \
5122+ Extracts a device major number from a raw device number .");
5123+
5124+ static PyObject *
5125+ posix_major (PyObject * self , PyObject * args )
5126+ {
5127+ int device ;
5128+ if (!PyArg_ParseTuple (args , "i:major" , & device ))
5129+ return NULL ;
5130+ return PyInt_FromLong ((long )major (device ));
5131+ }
5132+
5133+ PyDoc_STRVAR (posix_minor__doc__ ,
5134+ "minor(device) -> minor number\n\
5135+ Extracts a device minor number from a raw device number." );
5136+
5137+ static PyObject *
5138+ posix_minor (PyObject * self , PyObject * args )
5139+ {
5140+ int device ;
5141+ if (!PyArg_ParseTuple (args , "i:minor" , & device ))
5142+ return NULL ;
5143+ return PyInt_FromLong ((long )minor (device ));
5144+ }
5145+
5146+ PyDoc_STRVAR (posix_makedev__doc__ ,
5147+ "makedev(major, minor) -> device number\n\
5148+ Composes a raw device number from the major and minor device numbers." );
5149+
5150+ static PyObject *
5151+ posix_makedev (PyObject * self , PyObject * args )
5152+ {
5153+ int major , minor ;
5154+ if (!PyArg_ParseTuple (args , "ii:makedev" , & major , & minor ))
5155+ return NULL ;
5156+ return PyInt_FromLong ((long )makedev (major , minor ));
5157+ }
5158+ #endif /* device macros */
5159+
51145160
51155161#ifdef HAVE_FTRUNCATE
51165162PyDoc_STRVAR (posix_ftruncate__doc__ ,
@@ -6905,6 +6951,11 @@ static PyMethodDef posix_methods[] = {
69056951#if defined(HAVE_MKNOD ) && defined (HAVE_MAKEDEV )
69066952 {"mknod" , posix_mknod , METH_VARARGS , posix_mknod__doc__ },
69076953#endif
6954+ #ifdef HAVE_DEVICE_MACROS
6955+ {"major" , posix_major , METH_VARARGS , posix_major__doc__ },
6956+ {"minor" , posix_minor , METH_VARARGS , posix_minor__doc__ },
6957+ {"makedev" , posix_makedev , METH_VARARGS , posix_makedev__doc__ },
6958+ #endif
69086959#ifdef HAVE_FTRUNCATE
69096960 {"ftruncate" , posix_ftruncate , METH_VARARGS , posix_ftruncate__doc__ },
69106961#endif
0 commit comments