@@ -368,7 +368,9 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun
368368 return bytes_written ;
369369 }
370370 if (!(stream -> flags & PHP_STREAM_FLAG_SUPPRESS_ERRORS )) {
371- php_error_docref (NULL , E_NOTICE , "Write of %zu bytes failed with errno=%d %s" , count , errno , strerror (errno ));
371+ char errstr [256 ];
372+ php_error_docref (NULL , E_NOTICE , "Write of %zu bytes failed with errno=%d %s" ,
373+ count , errno , php_socket_strerror_s (errno , errstr , sizeof (errstr )));
372374 }
373375 }
374376 } else {
@@ -444,7 +446,9 @@ static ssize_t php_stdiop_read(php_stream *stream, char *buf, size_t count)
444446 /* TODO: Should this be treated as a proper error or not? */
445447 } else {
446448 if (!(stream -> flags & PHP_STREAM_FLAG_SUPPRESS_ERRORS )) {
447- php_error_docref (NULL , E_NOTICE , "Read of %zu bytes failed with errno=%d %s" , count , errno , strerror (errno ));
449+ char errstr [256 ];
450+ php_error_docref (NULL , E_NOTICE , "Read of %zu bytes failed with errno=%d %s" ,
451+ count , errno , php_socket_strerror_s (errno , errstr , sizeof (errstr )));
448452 }
449453
450454 /* TODO: Remove this special-case? */
@@ -1281,7 +1285,9 @@ static int php_plain_files_unlink(php_stream_wrapper *wrapper, const char *url,
12811285 ret = VCWD_UNLINK (url );
12821286 if (ret == -1 ) {
12831287 if (options & REPORT_ERRORS ) {
1284- php_error_docref1 (NULL , url , E_WARNING , "%s" , strerror (errno ));
1288+ char errstr [256 ];
1289+ php_error_docref1 (NULL , url , E_WARNING , "%s" ,
1290+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
12851291 }
12861292 return 0 ;
12871293 }
@@ -1327,6 +1333,7 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
13271333
13281334 if (ret == -1 ) {
13291335#ifndef PHP_WIN32
1336+ char errstr [256 ];
13301337# ifdef EXDEV
13311338 if (errno == EXDEV ) {
13321339 zend_stat_t sb ;
@@ -1347,15 +1354,17 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
13471354 * access to the file in the meantime.
13481355 */
13491356 if (VCWD_CHOWN (url_to , sb .st_uid , sb .st_gid )) {
1350- php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" , strerror (errno ));
1357+ php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" ,
1358+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
13511359 if (errno != EPERM ) {
13521360 success = 0 ;
13531361 }
13541362 }
13551363
13561364 if (success ) {
13571365 if (VCWD_CHMOD (url_to , sb .st_mode )) {
1358- php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" , strerror (errno ));
1366+ php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" ,
1367+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
13591368 if (errno != EPERM ) {
13601369 success = 0 ;
13611370 }
@@ -1366,10 +1375,12 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
13661375 VCWD_UNLINK (url_from );
13671376 }
13681377 } else {
1369- php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" , strerror (errno ));
1378+ php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" ,
1379+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
13701380 }
13711381 } else {
1372- php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" , strerror (errno ));
1382+ php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" ,
1383+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
13731384 }
13741385# if !defined(ZTS ) && !defined(TSRM_WIN32 )
13751386 umask (oldmask );
@@ -1382,7 +1393,8 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
13821393#ifdef PHP_WIN32
13831394 php_win32_docref2_from_error (GetLastError (), url_from , url_to );
13841395#else
1385- php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" , strerror (errno ));
1396+ php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" ,
1397+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
13861398#endif
13871399 return 0 ;
13881400 }
@@ -1462,11 +1474,12 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
14621474 if (!p ) {
14631475 p = buf ;
14641476 }
1477+ char errstr [256 ];
14651478 while (true) {
14661479 int ret = VCWD_MKDIR (buf , (mode_t ) mode );
14671480 if (ret < 0 && errno != EEXIST ) {
14681481 if (options & REPORT_ERRORS ) {
1469- php_error_docref (NULL , E_WARNING , "%s" , strerror (errno ));
1482+ php_error_docref (NULL , E_WARNING , "%s" , php_socket_strerror_s (errno , errstr , sizeof ( errstr ) ));
14701483 }
14711484 return 0 ;
14721485 }
@@ -1486,7 +1499,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
14861499 /* issue a warning to client when the last directory was created failed */
14871500 if (ret < 0 ) {
14881501 if (options & REPORT_ERRORS ) {
1489- php_error_docref (NULL , E_WARNING , "%s" , strerror (errno ));
1502+ php_error_docref (NULL , E_WARNING , "%s" , php_socket_strerror_s (errno , errstr , sizeof ( errstr ) ));
14901503 }
14911504 return 0 ;
14921505 }
@@ -1505,15 +1518,16 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, i
15051518 return 0 ;
15061519 }
15071520
1521+ char errstr [256 ];
15081522#ifdef PHP_WIN32
15091523 if (!php_win32_check_trailing_space (url , strlen (url ))) {
1510- php_error_docref1 (NULL , url , E_WARNING , "%s" , strerror (ENOENT ));
1524+ php_error_docref1 (NULL , url , E_WARNING , "%s" , php_socket_strerror_s (ENOENT , errstr , sizeof ( errstr ) ));
15111525 return 0 ;
15121526 }
15131527#endif
15141528
15151529 if (VCWD_RMDIR (url ) < 0 ) {
1516- php_error_docref1 (NULL , url , E_WARNING , "%s" , strerror (errno ));
1530+ php_error_docref1 (NULL , url , E_WARNING , "%s" , php_socket_strerror_s (errno , errstr , sizeof ( errstr ) ));
15171531 return 0 ;
15181532 }
15191533
@@ -1532,10 +1546,11 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
15321546#endif
15331547 mode_t mode ;
15341548 int ret = 0 ;
1549+ char errstr [256 ];
15351550
15361551#ifdef PHP_WIN32
15371552 if (!php_win32_check_trailing_space (url , strlen (url ))) {
1538- php_error_docref1 (NULL , url , E_WARNING , "%s" , strerror (ENOENT ));
1553+ php_error_docref1 (NULL , url , E_WARNING , "%s" , php_socket_strerror_s (ENOENT , errstr , sizeof ( errstr ) ));
15391554 return 0 ;
15401555 }
15411556#endif
@@ -1554,7 +1569,8 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
15541569 if (VCWD_ACCESS (url , F_OK ) != 0 ) {
15551570 FILE * file = VCWD_FOPEN (url , "w" );
15561571 if (file == NULL ) {
1557- php_error_docref1 (NULL , url , E_WARNING , "Unable to create file %s because %s" , url , strerror (errno ));
1572+ php_error_docref1 (NULL , url , E_WARNING , "Unable to create file %s because %s" , url ,
1573+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
15581574 return 0 ;
15591575 }
15601576 fclose (file );
@@ -1597,7 +1613,8 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
15971613 return 0 ;
15981614 }
15991615 if (ret == -1 ) {
1600- php_error_docref1 (NULL , url , E_WARNING , "Operation failed: %s" , strerror (errno ));
1616+ php_error_docref1 (NULL , url , E_WARNING , "Operation failed: %s" ,
1617+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
16011618 return 0 ;
16021619 }
16031620 php_clear_stat_cache (0 , NULL , 0 );
0 commit comments