Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06a83e9

Browse files
committed
Patch #543447: Add posix.mknod.
1 parent 314fc79 commit 06a83e9

6 files changed

Lines changed: 60 additions & 7 deletions

File tree

Doc/lib/libos.tex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,17 @@ \subsection{Files and Directories \label{os-file-dir}}
644644
doesn't open the FIFO --- it just creates the rendezvous point.
645645
\end{funcdesc}
646646

647+
\begin{funcdesc}{mknod}{path\optional{, mode=0600, major, minor}}
648+
Create a filesystem node (file, device special file or named pipe)
649+
named filename. mode specifies both the permissions to use and the
650+
type of node to be created, being combined (bitwise OR) with one of
651+
S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO (those constants are available
652+
in \module{stat}). For S_IFCHR and S_IFBLK, major and minor define the
653+
newly created device special file, otherwise they are ignored.
654+
655+
\versionadded{2.3}
656+
\end{funcdesc}
657+
647658
\begin{funcdesc}{mkdir}{path\optional{, mode}}
648659
Create a directory named \var{path} with numeric mode \var{mode}.
649660
The default \var{mode} is \code{0777} (octal). On some systems,

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Core and builtins
5656

5757
Extension modules
5858

59+
- posix.mknod was added.
60+
5961
- The locale module now exposes the C library's gettext interface.
6062

6163
- A security hole ("double free") was found in zlib-1.1.3, a popular

Modules/posixmodule.c

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4582,19 +4582,52 @@ posix_pipe(PyObject *self, PyObject *args)
45824582

45834583
#ifdef HAVE_MKFIFO
45844584
static char posix_mkfifo__doc__[] =
4585-
"mkfifo(file, [, mode=0666]) -> None\n\
4585+
"mkfifo(filename, [, mode=0666]) -> None\n\
45864586
Create a FIFO (a POSIX named pipe).";
45874587

45884588
static PyObject *
45894589
posix_mkfifo(PyObject *self, PyObject *args)
45904590
{
4591-
char *file;
4591+
char *filename;
45924592
int mode = 0666;
45934593
int res;
4594-
if (!PyArg_ParseTuple(args, "s|i:mkfifo", &file, &mode))
4594+
if (!PyArg_ParseTuple(args, "s|i:mkfifo", &filename, &mode))
45954595
return NULL;
45964596
Py_BEGIN_ALLOW_THREADS
4597-
res = mkfifo(file, mode);
4597+
res = mkfifo(filename, mode);
4598+
Py_END_ALLOW_THREADS
4599+
if (res < 0)
4600+
return posix_error();
4601+
Py_INCREF(Py_None);
4602+
return Py_None;
4603+
}
4604+
#endif
4605+
4606+
4607+
#ifdef HAVE_MKNOD
4608+
static char posix_mknod__doc__[] =
4609+
"mknod(filename, [, mode=0600, major, minor]) -> None\n\
4610+
Create a filesystem node (file, device special file or named pipe)\n\
4611+
named filename. mode specifies both the permissions to use and the\n\
4612+
type of node to be created, being combined (bitwise OR) with one of\n\
4613+
S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. For S_IFCHR and S_IFBLK,\n\
4614+
major and minor define the newly created device special file, otherwise\n\
4615+
they are ignored.";
4616+
4617+
4618+
static PyObject *
4619+
posix_mknod(PyObject *self, PyObject *args)
4620+
{
4621+
char *filename;
4622+
int mode = 0600;
4623+
int major = 0;
4624+
int minor = 0;
4625+
int res;
4626+
if (!PyArg_ParseTuple(args, "s|iii:mknod", &filename,
4627+
&mode, &major, &minor))
4628+
return NULL;
4629+
Py_BEGIN_ALLOW_THREADS
4630+
res = mknod(filename, mode, makedev(major, minor));
45984631
Py_END_ALLOW_THREADS
45994632
if (res < 0)
46004633
return posix_error();
@@ -6336,6 +6369,9 @@ static PyMethodDef posix_methods[] = {
63366369
#ifdef HAVE_MKFIFO
63376370
{"mkfifo", posix_mkfifo, METH_VARARGS, posix_mkfifo__doc__},
63386371
#endif
6372+
#ifdef HAVE_MKNOD
6373+
{"mknod", posix_mknod, METH_VARARGS, posix_mknod__doc__},
6374+
#endif
63396375
#ifdef HAVE_FTRUNCATE
63406376
{"ftruncate", posix_ftruncate, METH_VARARGS, posix_ftruncate__doc__},
63416377
#endif

configure

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.in Revision: 1.306 .
2+
# From configure.in Revision: 1.307 .
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.53.
55
#
@@ -11243,12 +11243,13 @@ echo "${ECHO_T}MACHDEP_OBJS" >&6
1124311243
1124411244
1124511245
11246+
1124611247
1124711248
1124811249
for ac_func in alarm chown chroot clock confstr ctermid ctermid_r execv \
1124911250
flock fork fsync fdatasync fpathconf ftime ftruncate \
1125011251
gai_strerror getgroups getlogin getpeername getpid getpwent getwd \
11251-
hstrerror inet_pton kill killpg link lstat mkfifo mktime mremap \
11252+
hstrerror inet_pton kill killpg link lstat mkfifo mknod mktime mremap \
1125211253
nice pathconf pause plock poll pthread_init \
1125311254
putenv readlink \
1125411255
select setegid seteuid setgid setgroups \

configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ AC_MSG_RESULT(MACHDEP_OBJS)
15681568
AC_CHECK_FUNCS(alarm chown chroot clock confstr ctermid ctermid_r execv \
15691569
flock fork fsync fdatasync fpathconf ftime ftruncate \
15701570
gai_strerror getgroups getlogin getpeername getpid getpwent getwd \
1571-
hstrerror inet_pton kill killpg link lstat mkfifo mktime mremap \
1571+
hstrerror inet_pton kill killpg link lstat mkfifo mknod mktime mremap \
15721572
nice pathconf pause plock poll pthread_init \
15731573
putenv readlink \
15741574
select setegid seteuid setgid setgroups \

pyconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@
260260
/* Define to 1 if you have the `mkfifo' function. */
261261
#undef HAVE_MKFIFO
262262

263+
/* Define to 1 if you have the `mknod' function. */
264+
#undef HAVE_MKNOD
265+
263266
/* Define to 1 if you have the `mktime' function. */
264267
#undef HAVE_MKTIME
265268

0 commit comments

Comments
 (0)