]> granicus.if.org Git - php/commitdiff
Added new function: posix_mknod().
authorMagnus M��tt� <magnus@php.net>
Fri, 13 May 2005 21:38:17 +0000 (21:38 +0000)
committerMagnus M��tt� <magnus@php.net>
Fri, 13 May 2005 21:38:17 +0000 (21:38 +0000)
NEWS
ext/posix/config.m4
ext/posix/php_posix.h
ext/posix/posix.c

diff --git a/NEWS b/NEWS
index 1aa5c47d49109b7fd723befdd0e9f46d9610145b..d48ae356bf248cd550a5a1b0ad5b7fc26c5e4a8e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -86,6 +86,7 @@ PHP                                                                        NEWS
   . inet_ntop() (Sara)
   . mysqli::client_info property (Georg)
   . posix_access() (Magnus)
+  . posix_mknod() (Magnus)
   . SimpleXMLElement::registerXPathNamespace() (Christian)
   . stream_context_get_default() (Wez)
   . stream_socket_enable_crypto() (Wez)
index e687f73bf7e008b987f897cddce9757354faf21e..aa24907bc8d6473eb941011d936300c05e0c860a 100644 (file)
@@ -9,5 +9,5 @@ if test "$PHP_POSIX" = "yes"; then
   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 getlogin getgroups)
+  AC_CHECK_FUNCS(seteuid setegid setsid getsid setpgid getpgid ctermid mkfifo mknod getrlimit getlogin getgroups)
 fi
index eff5efcf3005f46fb9666588ebdcdf918a1261d3..bcc7874785d809cc4724c0d8b7e88d481ff88171 100644 (file)
@@ -93,6 +93,9 @@ PHP_FUNCTION(posix_getcwd);
 #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 42c1164e917d1fe8c55f8f86c435e73ec6484a07..7bee3d22e222a46615dd7b64fc8d3ee871b59ae5 100644 (file)
@@ -111,6 +111,9 @@ function_entry posix_functions[] = {
 #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)
@@ -156,6 +159,22 @@ static PHP_MINIT_FUNCTION(posix)
        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;
 }
 /* }}} */
@@ -646,6 +665,51 @@ PHP_FUNCTION(posix_mkfifo)
 #endif
 /* }}} */
 
+/* {{{ proto bool posix_mknod(string pathname, int mode [, 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) {