Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:15949 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96513 invoked by uid 1010); 11 Apr 2005 22:08:35 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 96473 invoked from network); 11 Apr 2005 22:08:33 -0000 Received: from unknown (HELO pb1.pair.com) (127.0.0.1) by localhost with SMTP; 11 Apr 2005 22:08:33 -0000 X-Host-Fingerprint: 193.45.238.241 novell.stoldgods.nu Linux 2.5 (sometimes 2.4) (4) Received: from ([193.45.238.241:34003] helo=novell.stoldgods.nu) by pb1.pair.com (ecelerity HEAD r(5268)) with SMTP id 40/C1-19272-E45FA524 for ; Mon, 11 Apr 2005 18:08:27 -0400 Received: from localhost (localhost [127.0.0.1]) by novell.stoldgods.nu (Postfix) with ESMTP id 347BD9B55E for ; Tue, 12 Apr 2005 00:07:45 +0200 (CEST) Received: from novell.stoldgods.nu ([127.0.0.1]) by localhost (netsrv2 [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 05788-17 for ; Tue, 12 Apr 2005 00:07:44 +0200 (CEST) Received: from novell.stoldgods.nu (www.netiic.com [10.0.1.254]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by novell.stoldgods.nu (Postfix) with ESMTP id 79FB39B55C for ; Tue, 12 Apr 2005 00:07:44 +0200 (CEST) To: internals@lists.php.net Date: Tue, 12 Apr 2005 00:07:35 +0200 User-Agent: KMail/1.8 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_oUvWC2pjOoH3RKF" Message-ID: <200504120007.36552.magnus@php.net> Subject: [PATCH] Add posix_mknod to the posix extension From: magnus@php.net (Magnus =?iso-8859-1?q?M=E4=E4tt=E4?=) --Boundary-00=_oUvWC2pjOoH3RKF Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 ... --Boundary-00=_oUvWC2pjOoH3RKF Content-Type: text/plain; charset="us-ascii"; name="mknod.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="mknod.txt" 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 --Boundary-00=_oUvWC2pjOoH3RKF--