15
15
*/
16
16
17
17
#ifdef HAVE_CONFIG_H
18
- #include < config.h>
18
+ #include " config.h"
19
19
#endif
20
20
21
21
#include "php.h"
22
22
#include <unistd.h>
23
23
#include "ext/standard/info.h"
24
+ #include "ext/standard/php_string.h"
24
25
#include "php_posix.h"
26
+ #include "main/php_network.h"
25
27
26
28
#ifdef HAVE_POSIX
27
29
38
40
#include <errno.h>
39
41
#include <grp.h>
40
42
#include <pwd.h>
41
- #ifdef MAJOR_IN_MKDEV
43
+ #ifdef HAVE_SYS_MKDEV_H
42
44
# include <sys/mkdev.h>
43
- #elif defined(MAJOR_IN_SYSMACROS )
45
+ #endif
46
+ #ifdef HAVE_SYS_SYSMACROS_H
44
47
# include <sys/sysmacros.h>
45
48
#endif
46
49
@@ -356,7 +359,7 @@ PHP_FUNCTION(posix_uname)
356
359
add_assoc_string (return_value , "version" , u .version );
357
360
add_assoc_string (return_value , "machine" , u .machine );
358
361
359
- #if defined(_GNU_SOURCE ) && defined(HAVE_STRUCT_UTSNAME_DOMAINNAME )
362
+ #if defined(_GNU_SOURCE ) && ! defined(DARWIN ) && defined( HAVE_UTSNAME_DOMAINNAME )
360
363
add_assoc_string (return_value , "domainname" , u .domainname );
361
364
#endif
362
365
}
@@ -415,30 +418,32 @@ PHP_FUNCTION(posix_ctermid)
415
418
/* }}} */
416
419
417
420
/* Checks if the provides resource is a stream and if it provides a file descriptor */
418
- static zend_result php_posix_stream_get_fd (zval * zfp , zend_long * fd ) /* {{{ */
421
+ static int php_posix_stream_get_fd (zval * zfp , zend_long * ret ) /* {{{ */
419
422
{
420
423
php_stream * stream ;
421
424
422
425
php_stream_from_zval_no_verify (stream , zfp );
423
426
424
427
if (stream == NULL ) {
425
- return FAILURE ;
428
+ return 0 ;
426
429
}
427
430
428
- /* get the fd.
431
+ /* get the fd. php_socket_t is used for FDs, and is shorter than zend_long.
429
432
* NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag when casting.
430
433
* It is only used here so that the buffered data warning is not displayed.
431
434
*/
435
+ php_socket_t fd = -1 ;
432
436
if (php_stream_can_cast (stream , PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL ) == SUCCESS ) {
433
- php_stream_cast (stream , PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL , (void * ) fd , 0 );
437
+ php_stream_cast (stream , PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL , (void * * ) & fd , 0 );
434
438
} else if (php_stream_can_cast (stream , PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL ) == SUCCESS ) {
435
- php_stream_cast (stream , PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL , (void * ) fd , 0 );
439
+ php_stream_cast (stream , PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL , (void * * ) & fd , 0 );
436
440
} else {
437
441
php_error_docref (NULL , E_WARNING , "Could not use stream of type '%s'" ,
438
442
stream -> ops -> label );
439
- return FAILURE ;
443
+ return 0 ;
440
444
}
441
- return SUCCESS ;
445
+ * ret = fd ;
446
+ return 1 ;
442
447
}
443
448
/* }}} */
444
449
@@ -458,7 +463,7 @@ PHP_FUNCTION(posix_ttyname)
458
463
ZEND_PARSE_PARAMETERS_END ();
459
464
460
465
if (Z_TYPE_P (z_fd ) == IS_RESOURCE ) {
461
- if (php_posix_stream_get_fd (z_fd , & fd ) == FAILURE ) {
466
+ if (! php_posix_stream_get_fd (z_fd , & fd )) {
462
467
RETURN_FALSE ;
463
468
}
464
469
} else {
@@ -519,7 +524,7 @@ PHP_FUNCTION(posix_isatty)
519
524
ZEND_PARSE_PARAMETERS_END ();
520
525
521
526
if (Z_TYPE_P (z_fd ) == IS_RESOURCE ) {
522
- if (php_posix_stream_get_fd (z_fd , & fd ) == FAILURE ) {
527
+ if (! php_posix_stream_get_fd (z_fd , & fd )) {
523
528
RETURN_FALSE ;
524
529
}
525
530
} else {
@@ -532,13 +537,11 @@ PHP_FUNCTION(posix_isatty)
532
537
533
538
/* A valid file descriptor must fit in an int and be positive */
534
539
if (fd < 0 || fd > INT_MAX ) {
535
- POSIX_G (last_error ) = EBADF ;
536
540
RETURN_FALSE ;
537
541
}
538
542
if (isatty (fd )) {
539
543
RETURN_TRUE ;
540
544
} else {
541
- POSIX_G (last_error ) = errno ;
542
545
RETURN_FALSE ;
543
546
}
544
547
}
@@ -632,7 +635,7 @@ PHP_FUNCTION(posix_mknod)
632
635
zend_argument_value_error (3 , "cannot be 0 for the POSIX_S_IFCHR and POSIX_S_IFBLK modes" );
633
636
RETURN_THROWS ();
634
637
} else {
635
- #ifdef HAVE_MAKEDEV
638
+ #if defined( HAVE_MAKEDEV ) || defined( makedev )
636
639
php_dev = makedev (major , minor );
637
640
#else
638
641
php_error_docref (NULL , E_WARNING , "Cannot create a block or character device, creating a normal file instead" );
@@ -746,7 +749,7 @@ PHP_FUNCTION(posix_eaccess)
746
749
747
750
path = expand_filepath (filename , NULL );
748
751
if (!path ) {
749
- zend_argument_must_not_be_empty_error ( 1 );
752
+ zend_argument_value_error ( 1 , "cannot be empty" );
750
753
RETURN_THROWS ();
751
754
}
752
755
@@ -1043,7 +1046,7 @@ PHP_FUNCTION(posix_getpwuid)
1043
1046
#define UNLIMITED_STRING "unlimited"
1044
1047
1045
1048
/* {{{ posix_addlimit */
1046
- static zend_result posix_addlimit (int limit , const char * name , zval * return_value ) {
1049
+ static int posix_addlimit (int limit , const char * name , zval * return_value ) {
1047
1050
int result ;
1048
1051
struct rlimit rl ;
1049
1052
char hard [80 ];
@@ -1285,7 +1288,7 @@ PHP_FUNCTION(posix_pathconf)
1285
1288
ZEND_PARSE_PARAMETERS_END ();
1286
1289
1287
1290
if (path_len == 0 ) {
1288
- zend_argument_must_not_be_empty_error ( 1 );
1291
+ zend_argument_value_error ( 1 , "cannot be empty" );
1289
1292
RETURN_THROWS ();
1290
1293
} else if (php_check_open_basedir (path )) {
1291
1294
php_error_docref (NULL , E_WARNING , "Invalid path supplied: %s" , path );
@@ -1315,7 +1318,7 @@ PHP_FUNCTION(posix_fpathconf)
1315
1318
ZEND_PARSE_PARAMETERS_END ();
1316
1319
1317
1320
if (Z_TYPE_P (z_fd ) == IS_RESOURCE ) {
1318
- if (php_posix_stream_get_fd (z_fd , & fd ) == FAILURE ) {
1321
+ if (! php_posix_stream_get_fd (z_fd , & fd )) {
1319
1322
RETURN_FALSE ;
1320
1323
}
1321
1324
} else {
0 commit comments