Hello,

This patch will add posix_mknod to the posix extension.
Usage: posix_mknod('file', mode | type [, major [,minor]]), like 
mknod(2) (except for major and minor).

Any objections against adding it to HEAD ?


Magnus

-- 
We are now enjoying total mutual interaction in an imaginary hot 
tub ...
Index: ext/posix/posix.c
===================================================================
RCS file: /repository/php-src/ext/posix/posix.c,v
retrieving revision 1.64
diff -u -r1.64 posix.c
--- ext/posix/posix.c   28 Jan 2005 01:38:56 -0000      1.64
+++ ext/posix/posix.c   11 Apr 2005 20:40:14 -0000
@@ -107,6 +107,9 @@
 #ifdef HAVE_MKFIFO
        PHP_FE(posix_mkfifo,    NULL)
 #endif
+#ifdef HAVE_MKNOD
+       PHP_FE(posix_mknod,     NULL)
+#endif
 
        /* POSIX.1, 5.6 */
        PHP_FE(posix_access,    NULL)
@@ -152,6 +155,22 @@
        REGISTER_LONG_CONSTANT("POSIX_X_OK", X_OK, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("POSIX_W_OK", W_OK, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("POSIX_R_OK", R_OK, CONST_CS | CONST_PERSISTENT);
+#ifdef S_IFREG
+       REGISTER_LONG_CONSTANT("POSIX_S_IFREG", S_IFREG, CONST_CS | 
CONST_PERSISTENT);
+#endif
+#ifdef S_IFCHR
+       REGISTER_LONG_CONSTANT("POSIX_S_IFCHR", S_IFCHR, CONST_CS | 
CONST_PERSISTENT);
+#endif
+#ifdef S_IFBLK
+       REGISTER_LONG_CONSTANT("POSIX_S_IFBLK", S_IFBLK, CONST_CS | 
CONST_PERSISTENT);
+#endif
+#ifdef S_IFIFO
+       REGISTER_LONG_CONSTANT("POSIX_S_IFIFO", S_IFIFO, CONST_CS | 
CONST_PERSISTENT);
+#endif
+#ifdef S_IFSOCK
+       REGISTER_LONG_CONSTANT("POSIX_S_IFSOCK", S_IFSOCK, CONST_CS | 
CONST_PERSISTENT);
+#endif
+
        return SUCCESS;
 }
 /* }}} */
@@ -638,6 +657,51 @@
 #endif
 /* }}} */
 
+/* {{{ proto bool posix_mknod(string pathname, int mode, int filetype [, int 
major [, int minor]])
+   Make a special or ordinary file (POSIX.1) */
+#ifdef HAVE_MKNOD
+PHP_FUNCTION(posix_mknod)
+{
+       char *path;
+       int path_len;
+       long mode;
+       long major, minor = 0;
+       int result;
+       dev_t php_dev;
+
+       php_dev = 0;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ll", &path, 
&path_len,
+                       &mode, &major, &minor) == FAILURE) {
+               RETURN_FALSE;
+       }
+
+       if (php_check_open_basedir_ex(path, 0 TSRMLS_CC) ||
+                       (PG(safe_mode) && (!php_checkuid(path, NULL, 
CHECKUID_ALLOW_ONLY_DIR)))) {
+               RETURN_FALSE;
+       }
+
+       if ((mode & S_IFCHR) || (mode & S_IFBLK)) {
+               if (major == 0) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING,
+                               "expects argument 4 to be non-zero for 
POSIX_S_IFCHR and POSIX_S_IFBLK");
+                       RETURN_FALSE;
+               } else {
+                       php_dev = makedev(major, minor);
+               }
+       }
+
+       result = mknod(path, mode, php_dev);
+       if (result < 0) {
+               POSIX_G(last_error) = errno;
+               RETURN_FALSE;
+       }
+
+       RETURN_TRUE;
+}
+#endif
+/* }}} */
+
 /* Takes a pointer to posix group and a pointer to an already initialized ZVAL
  * array container and fills the array with the posix group member data. */
 int php_posix_group_to_array(struct group *g, zval *array_group) {
Index: ext/posix/php_posix.h
===================================================================
RCS file: /repository/php-src/ext/posix/php_posix.h,v
retrieving revision 1.15
diff -u -r1.15 php_posix.h
--- ext/posix/php_posix.h       7 Jan 2005 16:05:06 -0000       1.15
+++ ext/posix/php_posix.h       11 Apr 2005 20:40:15 -0000
@@ -89,6 +89,9 @@
 #ifdef HAVE_MKFIFO
 PHP_FUNCTION(posix_mkfifo);
 #endif
+#ifdef HAVE_MKNOD
+PHP_FUNCTION(posix_mknod);
+#endif
 
 /* POSIX.1, 5.6 */
 PHP_FUNCTION(posix_access);
Index: ext/posix/config.m4
===================================================================
RCS file: /repository/php-src/ext/posix/config.m4,v
retrieving revision 1.7
diff -u -r1.7 config.m4
--- ext/posix/config.m4 12 Mar 2002 16:32:13 -0000      1.7
+++ ext/posix/config.m4 11 Apr 2005 20:40:15 -0000
@@ -9,5 +9,5 @@
   AC_DEFINE(HAVE_POSIX, 1, [whether to include POSIX-like functions])
   PHP_NEW_EXTENSION(posix, posix.c, $ext_shared)
 
-  AC_CHECK_FUNCS(seteuid setegid setsid getsid setpgid getpgid ctermid mkfifo 
getrlimit)
+  AC_CHECK_FUNCS(seteuid setegid setsid getsid setpgid getpgid ctermid mkfifo 
mknod getrlimit)
 fi

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to