From dbe3f76270d8bc22f1201e6ac1d63dbe3124dc3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Thu, 10 Oct 2002 14:27:30 +0000 Subject: Patch #569139: Implementation of major, minor and makedev. --- Doc/lib/libos.tex | 31 ++++- Modules/posixmodule.c | 67 ++++++++-- configure | 339 +++++++++++++++++++++++++++++++++++++++++++++++++- configure.in | 19 +++ pyconfig.h.in | 11 ++ 5 files changed, 450 insertions(+), 17 deletions(-) diff --git a/Doc/lib/libos.tex b/Doc/lib/libos.tex index afbea54..45354bc 100644 --- a/Doc/lib/libos.tex +++ b/Doc/lib/libos.tex @@ -700,13 +700,32 @@ the client opens it for writing. Note that \function{mkfifo()} doesn't open the FIFO --- it just creates the rendezvous point. \end{funcdesc} -\begin{funcdesc}{mknod}{path\optional{, mode=0600, major, minor}} +\begin{funcdesc}{mknod}{path\optional{, mode=0600, device}} Create a filesystem node (file, device special file or named pipe) -named filename. mode specifies both the permissions to use and the -type of node to be created, being combined (bitwise OR) with one of -S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO (those constants are available -in \module{stat}). For S_IFCHR and S_IFBLK, major and minor define the -newly created device special file, otherwise they are ignored. +named filename. \var{mode} specifies both the permissions to use and +the type of node to be created, being combined (bitwise OR) with one +of S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO (those constants are +available in \module{stat}). For S_IFCHR and S_IFBLK, \var{device} +defines the newly created device special file (probably using +\function{os.makedev()}), otherwise it is ignored. + +\versionadded{2.3} +\end{funcdesc} + +\begin{funcdesc}{major}{device} +Extracts a device major number from a raw device number. + +\versionadded{2.3} +\end{funcdesc} + +\begin{funcdesc}{minor}{device} +Extracts a device minor number from a raw device number. + +\versionadded{2.3} +\end{funcdesc} + +\begin{funcdesc}{makedev}{major, minor} +Composes a raw device number from the major and minor device numbers. \versionadded{2.3} \end{funcdesc} diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 93f4a93..c611b07 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -277,9 +277,16 @@ extern int lstat(const char *, struct stat *); # define STRUCT_STAT struct stat #endif +#if defined(MAJOR_IN_MKDEV) +#include +#else +#if defined(MAJOR_IN_SYSMACROS) +#include +#endif #if defined(HAVE_MKNOD) && defined(HAVE_SYS_MKDEV_H) #include #endif +#endif /* Return a dictionary corresponding to the POSIX environment table */ #ifdef WITH_NEXT_FRAMEWORK @@ -5081,13 +5088,13 @@ posix_mkfifo(PyObject *self, PyObject *args) #if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV) PyDoc_STRVAR(posix_mknod__doc__, -"mknod(filename, [, mode=0600, major, minor])\n\n\ +"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\ -major and minor define the newly created device special file, otherwise\n\ -they are ignored."); +device defines the newly created device special file (probably using\n\ +os.makedev()), otherwise it is ignored."); static PyObject * @@ -5095,14 +5102,12 @@ posix_mknod(PyObject *self, PyObject *args) { char *filename; int mode = 0600; - int major = 0; - int minor = 0; + int device = 0; int res; - if (!PyArg_ParseTuple(args, "s|iii:mknod", &filename, - &mode, &major, &minor)) + if (!PyArg_ParseTuple(args, "s|iii:mknod", &filename, &mode, &device)) return NULL; Py_BEGIN_ALLOW_THREADS - res = mknod(filename, mode, makedev(major, minor)); + res = mknod(filename, mode, device); Py_END_ALLOW_THREADS if (res < 0) return posix_error(); @@ -5111,6 +5116,47 @@ posix_mknod(PyObject *self, PyObject *args) } #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 PyDoc_STRVAR(posix_ftruncate__doc__, @@ -6905,6 +6951,11 @@ static PyMethodDef posix_methods[] = { #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 {"ftruncate", posix_ftruncate, METH_VARARGS, posix_ftruncate__doc__}, #endif diff --git a/configure b/configure index 7758d78..517caab 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 1.354 . +# From configure.in Revision: 1.355 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.53. # @@ -901,7 +901,7 @@ esac # Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be # absolute. ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd` -ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd` +ac_abs_top_builddir=`cd "$ac_dir" && cd $ac_top_builddir && pwd` ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd` ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd` @@ -4296,6 +4296,279 @@ fi fi +echo "$as_me:$LINENO: checking whether sys/types.h defines makedev" >&5 +echo $ECHO_N "checking whether sys/types.h defines makedev... $ECHO_C" >&6 +if test "${ac_cv_header_sys_types_h_makedev+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" +#include +#ifdef F77_DUMMY_MAIN +# ifdef __cplusplus + extern "C" +# endif + int F77_DUMMY_MAIN() { return 1; } +#endif +int +main () +{ +return makedev(0, 0); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_header_sys_types_h_makedev=yes +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +ac_cv_header_sys_types_h_makedev=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext + +fi +echo "$as_me:$LINENO: result: $ac_cv_header_sys_types_h_makedev" >&5 +echo "${ECHO_T}$ac_cv_header_sys_types_h_makedev" >&6 + +if test $ac_cv_header_sys_types_h_makedev = no; then +if test "${ac_cv_header_sys_mkdev_h+set}" = set; then + echo "$as_me:$LINENO: checking for sys/mkdev.h" >&5 +echo $ECHO_N "checking for sys/mkdev.h... $ECHO_C" >&6 +if test "${ac_cv_header_sys_mkdev_h+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +echo "$as_me:$LINENO: result: $ac_cv_header_sys_mkdev_h" >&5 +echo "${ECHO_T}$ac_cv_header_sys_mkdev_h" >&6 +else + # Is the header compilable? +echo "$as_me:$LINENO: checking sys/mkdev.h usability" >&5 +echo $ECHO_N "checking sys/mkdev.h usability... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" +$ac_includes_default +#include +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +ac_header_compiler=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6 + +# Is the header present? +echo "$as_me:$LINENO: checking sys/mkdev.h presence" >&5 +echo $ECHO_N "checking sys/mkdev.h presence... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" +#include +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + egrep -v '^ *\+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 + cat conftest.$ac_ext >&5 + ac_header_preproc=no +fi +rm -f conftest.err conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6 + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc in + yes:no ) + { echo "$as_me:$LINENO: WARNING: sys/mkdev.h: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: sys/mkdev.h: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: sys/mkdev.h: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: sys/mkdev.h: proceeding with the preprocessor's result" >&2;};; + no:yes ) + { echo "$as_me:$LINENO: WARNING: sys/mkdev.h: present but cannot be compiled" >&5 +echo "$as_me: WARNING: sys/mkdev.h: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: sys/mkdev.h: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: sys/mkdev.h: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: sys/mkdev.h: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: sys/mkdev.h: proceeding with the preprocessor's result" >&2;};; +esac +echo "$as_me:$LINENO: checking for sys/mkdev.h" >&5 +echo $ECHO_N "checking for sys/mkdev.h... $ECHO_C" >&6 +if test "${ac_cv_header_sys_mkdev_h+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_header_sys_mkdev_h=$ac_header_preproc +fi +echo "$as_me:$LINENO: result: $ac_cv_header_sys_mkdev_h" >&5 +echo "${ECHO_T}$ac_cv_header_sys_mkdev_h" >&6 + +fi +if test $ac_cv_header_sys_mkdev_h = yes; then + +cat >>confdefs.h <<\_ACEOF +#define MAJOR_IN_MKDEV 1 +_ACEOF + +fi + + + + if test $ac_cv_header_sys_mkdev_h = no; then + if test "${ac_cv_header_sys_sysmacros_h+set}" = set; then + echo "$as_me:$LINENO: checking for sys/sysmacros.h" >&5 +echo $ECHO_N "checking for sys/sysmacros.h... $ECHO_C" >&6 +if test "${ac_cv_header_sys_sysmacros_h+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +echo "$as_me:$LINENO: result: $ac_cv_header_sys_sysmacros_h" >&5 +echo "${ECHO_T}$ac_cv_header_sys_sysmacros_h" >&6 +else + # Is the header compilable? +echo "$as_me:$LINENO: checking sys/sysmacros.h usability" >&5 +echo $ECHO_N "checking sys/sysmacros.h usability... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" +$ac_includes_default +#include +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +ac_header_compiler=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6 + +# Is the header present? +echo "$as_me:$LINENO: checking sys/sysmacros.h presence" >&5 +echo $ECHO_N "checking sys/sysmacros.h presence... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" +#include +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + egrep -v '^ *\+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 + cat conftest.$ac_ext >&5 + ac_header_preproc=no +fi +rm -f conftest.err conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6 + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc in + yes:no ) + { echo "$as_me:$LINENO: WARNING: sys/sysmacros.h: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: sys/sysmacros.h: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: sys/sysmacros.h: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: sys/sysmacros.h: proceeding with the preprocessor's result" >&2;};; + no:yes ) + { echo "$as_me:$LINENO: WARNING: sys/sysmacros.h: present but cannot be compiled" >&5 +echo "$as_me: WARNING: sys/sysmacros.h: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: sys/sysmacros.h: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: sys/sysmacros.h: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: sys/sysmacros.h: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: sys/sysmacros.h: proceeding with the preprocessor's result" >&2;};; +esac +echo "$as_me:$LINENO: checking for sys/sysmacros.h" >&5 +echo $ECHO_N "checking for sys/sysmacros.h... $ECHO_C" >&6 +if test "${ac_cv_header_sys_sysmacros_h+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_header_sys_sysmacros_h=$ac_header_preproc +fi +echo "$as_me:$LINENO: result: $ac_cv_header_sys_sysmacros_h" >&5 +echo "${ECHO_T}$ac_cv_header_sys_sysmacros_h" >&6 + +fi +if test $ac_cv_header_sys_sysmacros_h = yes; then + +cat >>confdefs.h <<\_ACEOF +#define MAJOR_IN_SYSMACROS 1 +_ACEOF + +fi + + + fi +fi + # checks for typedefs was_it_defined=no @@ -12498,6 +12771,66 @@ fi done +echo "$as_me:$LINENO: checking for major" >&5 +echo $ECHO_N "checking for major... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" + + #if defined(MAJOR_IN_MKDEV) + #include + #elif defined(MAJOR_IN_SYSMACROS) + #include + #else + #include + #endif + +#ifdef F77_DUMMY_MAIN +# ifdef __cplusplus + extern "C" +# endif + int F77_DUMMY_MAIN() { return 1; } +#endif +int +main () +{ + + makedev(major(0),minor(0)); + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + + +cat >>confdefs.h <<\_ACEOF +#define HAVE_DEVICE_MACROS 1 +_ACEOF + + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 + + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + +fi +rm -f conftest.$ac_objext conftest.$ac_ext # On OSF/1 V5.1, getaddrinfo is available, but a define # for [no]getaddrinfo in netdb.h. @@ -16842,7 +17175,7 @@ esac # Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be # absolute. ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd` -ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd` +ac_abs_top_builddir=`cd "$ac_dir" && cd $ac_top_builddir && pwd` ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd` ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd` diff --git a/configure.in b/configure.in index 4f4f03a..94a0d1f 100644 --- a/configure.in +++ b/configure.in @@ -621,6 +621,7 @@ sys/param.h sys/poll.h sys/select.h sys/socket.h sys/time.h sys/times.h \ sys/un.h sys/utsname.h sys/wait.h pty.h term.h wctype.h libutil.h \ sys/resource.h netpacket/packet.h) AC_HEADER_DIRENT +AC_HEADER_MAJOR # checks for typedefs was_it_defined=no @@ -1716,6 +1717,24 @@ AC_CHECK_FUNCS(gettimeofday, ) ) +AC_MSG_CHECKING(for major, minor, and makedev) +AC_TRY_COMPILE([ + #if defined(MAJOR_IN_MKDEV) + #include + #elif defined(MAJOR_IN_SYSMACROS) + #include + #else + #include + #endif +],[ + makedev(major(0),minor(0)); +],[ + AC_DEFINE(HAVE_DEVICE_MACROS, 1, + [Define to 1 if you have the device macros.]) + AC_MSG_RESULT(yes) +],[ + AC_MSG_RESULT(no) +]) # On OSF/1 V5.1, getaddrinfo is available, but a define # for [no]getaddrinfo in netdb.h. diff --git a/pyconfig.h.in b/pyconfig.h.in index 903f8d2..193a9ca 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -57,6 +57,9 @@ /* Define to 1 if you have the `ctermid_r' function. */ #undef HAVE_CTERMID_R +/* Define to 1 if you have the device macros. */ +#undef HAVE_DEVICE_MACROS + /* Define to 1 if you have the header file, and it defines `DIR'. */ #undef HAVE_DIRENT_H @@ -604,6 +607,14 @@ /* Define if you are using Mach cthreads under mach / */ #undef MACH_C_THREADS +/* Define to 1 if `major', `minor', and `makedev' are declared in . + */ +#undef MAJOR_IN_MKDEV + +/* Define to 1 if `major', `minor', and `makedev' are declared in + . */ +#undef MAJOR_IN_SYSMACROS + /* Define if malloc(0) returns a NULL pointer. */ #undef MALLOC_ZERO_RETURNS_NULL -- cgit v0.12