@@ -367,7 +367,9 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun
367367 return bytes_written ;
368368 }
369369 if (!(stream -> flags & PHP_STREAM_FLAG_SUPPRESS_ERRORS )) {
370- php_error_docref (NULL , E_NOTICE , "Write of %zu bytes failed with errno=%d %s" , count , errno , strerror (errno ));
370+ char errstr [256 ];
371+ php_error_docref (NULL , E_NOTICE , "Write of %zu bytes failed with errno=%d %s" ,
372+ count , errno , php_socket_strerror_s (errno , errstr , sizeof (errstr )));
371373 }
372374 }
373375 } else {
@@ -443,7 +445,9 @@ static ssize_t php_stdiop_read(php_stream *stream, char *buf, size_t count)
443445 /* TODO: Should this be treated as a proper error or not? */
444446 } else {
445447 if (!(stream -> flags & PHP_STREAM_FLAG_SUPPRESS_ERRORS )) {
446- php_error_docref (NULL , E_NOTICE , "Read of %zu bytes failed with errno=%d %s" , count , errno , strerror (errno ));
448+ char errstr [256 ];
449+ php_error_docref (NULL , E_NOTICE , "Read of %zu bytes failed with errno=%d %s" ,
450+ count , errno , php_socket_strerror_s (errno , errstr , sizeof (errstr )));
447451 }
448452
449453 /* TODO: Remove this special-case? */
@@ -1257,7 +1261,9 @@ static int php_plain_files_unlink(php_stream_wrapper *wrapper, const char *url,
12571261 ret = VCWD_UNLINK (url );
12581262 if (ret == -1 ) {
12591263 if (options & REPORT_ERRORS ) {
1260- php_error_docref1 (NULL , url , E_WARNING , "%s" , strerror (errno ));
1264+ char errstr [256 ];
1265+ php_error_docref1 (NULL , url , E_WARNING , "%s" ,
1266+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
12611267 }
12621268 return 0 ;
12631269 }
@@ -1300,6 +1306,7 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
13001306 }
13011307
13021308 ret = VCWD_RENAME (url_from , url_to );
1309+ char errstr [256 ];
13031310
13041311 if (ret == -1 ) {
13051312#ifndef PHP_WIN32
@@ -1323,15 +1330,17 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
13231330 * access to the file in the meantime.
13241331 */
13251332 if (VCWD_CHOWN (url_to , sb .st_uid , sb .st_gid )) {
1326- php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" , strerror (errno ));
1333+ php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" ,
1334+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
13271335 if (errno != EPERM ) {
13281336 success = 0 ;
13291337 }
13301338 }
13311339
13321340 if (success ) {
13331341 if (VCWD_CHMOD (url_to , sb .st_mode )) {
1334- php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" , strerror (errno ));
1342+ php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" ,
1343+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
13351344 if (errno != EPERM ) {
13361345 success = 0 ;
13371346 }
@@ -1342,10 +1351,12 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
13421351 VCWD_UNLINK (url_from );
13431352 }
13441353 } else {
1345- php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" , strerror (errno ));
1354+ php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" ,
1355+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
13461356 }
13471357 } else {
1348- php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" , strerror (errno ));
1358+ php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" ,
1359+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
13491360 }
13501361# if !defined(ZTS ) && !defined(TSRM_WIN32 )
13511362 umask (oldmask );
@@ -1358,7 +1369,8 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
13581369#ifdef PHP_WIN32
13591370 php_win32_docref2_from_error (GetLastError (), url_from , url_to );
13601371#else
1361- php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" , strerror (errno ));
1372+ php_error_docref2 (NULL , url_from , url_to , E_WARNING , "%s" ,
1373+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
13621374#endif
13631375 return 0 ;
13641376 }
@@ -1438,11 +1450,12 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
14381450 if (!p ) {
14391451 p = buf ;
14401452 }
1453+ char errstr [256 ];
14411454 while (true) {
14421455 int ret = VCWD_MKDIR (buf , (mode_t ) mode );
14431456 if (ret < 0 && errno != EEXIST ) {
14441457 if (options & REPORT_ERRORS ) {
1445- php_error_docref (NULL , E_WARNING , "%s" , strerror (errno ));
1458+ php_error_docref (NULL , E_WARNING , "%s" , php_socket_strerror_s (errno , errstr , sizeof ( errstr ) ));
14461459 }
14471460 return 0 ;
14481461 }
@@ -1462,7 +1475,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
14621475 /* issue a warning to client when the last directory was created failed */
14631476 if (ret < 0 ) {
14641477 if (options & REPORT_ERRORS ) {
1465- php_error_docref (NULL , E_WARNING , "%s" , strerror (errno ));
1478+ php_error_docref (NULL , E_WARNING , "%s" , php_socket_strerror_s (errno , errstr , sizeof ( errstr ) ));
14661479 }
14671480 return 0 ;
14681481 }
@@ -1481,15 +1494,16 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, i
14811494 return 0 ;
14821495 }
14831496
1497+ char errstr [256 ];
14841498#ifdef PHP_WIN32
14851499 if (!php_win32_check_trailing_space (url , strlen (url ))) {
1486- php_error_docref1 (NULL , url , E_WARNING , "%s" , strerror (ENOENT ));
1500+ php_error_docref1 (NULL , url , E_WARNING , "%s" , php_socket_strerror_s (ENOENT , errstr , sizeof ( errstr ) ));
14871501 return 0 ;
14881502 }
14891503#endif
14901504
14911505 if (VCWD_RMDIR (url ) < 0 ) {
1492- php_error_docref1 (NULL , url , E_WARNING , "%s" , strerror (errno ));
1506+ php_error_docref1 (NULL , url , E_WARNING , "%s" , php_socket_strerror_s (errno , errstr , sizeof ( errstr ) ));
14931507 return 0 ;
14941508 }
14951509
@@ -1508,10 +1522,11 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
15081522#endif
15091523 mode_t mode ;
15101524 int ret = 0 ;
1525+ char errstr [256 ];
15111526
15121527#ifdef PHP_WIN32
15131528 if (!php_win32_check_trailing_space (url , strlen (url ))) {
1514- php_error_docref1 (NULL , url , E_WARNING , "%s" , strerror (ENOENT ));
1529+ php_error_docref1 (NULL , url , E_WARNING , "%s" , php_socket_strerror_s (ENOENT , errstr , sizeof ( errstr ) ));
15151530 return 0 ;
15161531 }
15171532#endif
@@ -1530,7 +1545,8 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
15301545 if (VCWD_ACCESS (url , F_OK ) != 0 ) {
15311546 FILE * file = VCWD_FOPEN (url , "w" );
15321547 if (file == NULL ) {
1533- php_error_docref1 (NULL , url , E_WARNING , "Unable to create file %s because %s" , url , strerror (errno ));
1548+ php_error_docref1 (NULL , url , E_WARNING , "Unable to create file %s because %s" , url ,
1549+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
15341550 return 0 ;
15351551 }
15361552 fclose (file );
@@ -1573,7 +1589,8 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
15731589 return 0 ;
15741590 }
15751591 if (ret == -1 ) {
1576- php_error_docref1 (NULL , url , E_WARNING , "Operation failed: %s" , strerror (errno ));
1592+ php_error_docref1 (NULL , url , E_WARNING , "Operation failed: %s" ,
1593+ php_socket_strerror_s (errno , errstr , sizeof (errstr )));
15771594 return 0 ;
15781595 }
15791596 php_clear_stat_cache (0 , NULL , 0 );
0 commit comments