Browse Source

LibC: Make sure perror() is consistent about the errno it prints

Andreas Kling 5 năm trước cách đây
mục cha
commit
ada1f504fd
1 tập tin đã thay đổi với 3 bổ sung2 xóa
  1. 3 2
      Libraries/LibC/stdio.cpp

+ 3 - 2
Libraries/LibC/stdio.cpp

@@ -425,8 +425,9 @@ int snprintf(char* buffer, size_t size, const char* fmt, ...)
 
 
 void perror(const char* s)
 void perror(const char* s)
 {
 {
-    dbg() << "perror(): " << strerror(errno);
-    fprintf(stderr, "%s: %s\n", s, strerror(errno));
+    int saved_errno = errno;
+    dbg() << "perror(): " << strerror(saved_errno);
+    fprintf(stderr, "%s: %s\n", s, strerror(saved_errno));
 }
 }
 
 
 FILE* fopen(const char* pathname, const char* mode)
 FILE* fopen(const char* pathname, const char* mode)