[libc] move stdlib and stdio to new errno pattern
authorMichael Jones <michaelrj@google.com>
Thu, 2 Mar 2023 22:01:41 +0000 (14:01 -0800)
committerMichael Jones <michaelrj@google.com>
Fri, 3 Mar 2023 19:15:36 +0000 (11:15 -0800)
Fixes https://github.com/llvm/llvm-project/issues/61071

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145191

67 files changed:
libc/src/__support/CMakeLists.txt
libc/src/__support/File/CMakeLists.txt
libc/src/__support/File/dir.cpp
libc/src/__support/File/file.cpp
libc/src/__support/File/linux_file.cpp
libc/src/__support/StringUtil/CMakeLists.txt
libc/src/__support/StringUtil/error_to_string.cpp
libc/src/__support/str_to_float.h
libc/src/__support/str_to_integer.h
libc/src/__support/threads/linux/CMakeLists.txt
libc/src/__support/threads/linux/thread.cpp
libc/src/stdio/CMakeLists.txt
libc/src/stdio/fclose.cpp
libc/src/stdio/fflush.cpp
libc/src/stdio/fgetc.cpp
libc/src/stdio/fgetc_unlocked.cpp
libc/src/stdio/fgets.cpp
libc/src/stdio/fopen.cpp
libc/src/stdio/fopencookie.cpp
libc/src/stdio/fputc.cpp
libc/src/stdio/fputs.cpp
libc/src/stdio/fread.cpp
libc/src/stdio/fread_unlocked.cpp
libc/src/stdio/fseek.cpp
libc/src/stdio/ftell.cpp
libc/src/stdio/fwrite.cpp
libc/src/stdio/fwrite_unlocked.cpp
libc/src/stdio/getc.cpp
libc/src/stdio/getc_unlocked.cpp
libc/src/stdio/linux/remove.cpp
libc/src/stdio/putc.cpp
libc/src/stdio/putchar.cpp
libc/src/stdio/puts.cpp
libc/src/stdio/setbuf.cpp
libc/src/stdio/setvbuf.cpp
libc/src/stdlib/CMakeLists.txt
libc/src/stdlib/atof.cpp
libc/src/stdlib/atoi.cpp
libc/src/stdlib/atol.cpp
libc/src/stdlib/atoll.cpp
libc/src/stdlib/strtod.cpp
libc/src/stdlib/strtof.cpp
libc/src/stdlib/strtol.cpp
libc/src/stdlib/strtold.cpp
libc/src/stdlib/strtoll.cpp
libc/src/stdlib/strtoul.cpp
libc/src/stdlib/strtoull.cpp
libc/test/src/stdio/CMakeLists.txt
libc/test/src/stdio/fgetc_test.cpp
libc/test/src/stdio/fgetc_unlocked_test.cpp
libc/test/src/stdio/fgets_test.cpp
libc/test/src/stdio/fileop_test.cpp
libc/test/src/stdio/fopencookie_test.cpp
libc/test/src/stdio/fprintf_test.cpp
libc/test/src/stdio/fscanf_test.cpp
libc/test/src/stdio/ftell_test.cpp
libc/test/src/stdio/putc_test.cpp
libc/test/src/stdio/remove_test.cpp
libc/test/src/stdio/setvbuf_test.cpp
libc/test/src/stdio/unlocked_fileop_test.cpp
libc/test/src/stdlib/CMakeLists.txt
libc/test/src/stdlib/StrtolTest.h
libc/test/src/stdlib/atof_test.cpp
libc/test/src/stdlib/strtod_test.cpp
libc/test/src/stdlib/strtof_test.cpp
libc/test/src/stdlib/strtold_test.cpp
utils/bazel/llvm-project-overlay/libc/BUILD.bazel

index bafcd6e..8329a80 100644 (file)
@@ -64,7 +64,6 @@ add_header_library(
   DEPENDS
     .ctype_utils
     .str_to_num_result
-    libc.include.errno
     libc.src.errno.errno
     libc.src.__support.CPP.limits
     libc.src.__support.common
index dd9bbee..2d94c2f 100644 (file)
@@ -11,7 +11,7 @@ add_object_library(
   HDRS
     file.h
   DEPENDS
-    libc.include.errno
+    
     libc.src.__support.CPP.new
     libc.src.__support.CPP.span
     libc.src.__support.threads.mutex
@@ -37,7 +37,7 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}_file.cpp)
       ${LIBC_TARGET_OS}_file.cpp
     DEPENDS
       .file
-      libc.include.errno
+      
       libc.include.fcntl
       libc.include.stdio
       libc.include.sys_syscall
@@ -55,10 +55,10 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}_dir.cpp)
       ${LIBC_TARGET_OS}_dir.cpp
     DEPENDS
       .dir
-      libc.include.errno
       libc.include.fcntl
       libc.include.sys_syscall
       libc.src.__support.OSUtil.osutil
       libc.src.__support.error_or
+      libc.src.errno.errno
   )
 endif()
index a473704..70f550f 100644 (file)
@@ -10,8 +10,8 @@
 
 #include "src/__support/CPP/new.h"
 #include "src/__support/error_or.h"
+#include "src/errno/libc_errno.h" // For error macros
 
-#include <errno.h>
 #include <stdlib.h>
 
 namespace __llvm_libc {
index 53fa06b..6a80ce0 100644 (file)
@@ -10,8 +10,8 @@
 
 #include "src/__support/CPP/new.h"
 #include "src/__support/CPP/span.h"
+#include "src/errno/libc_errno.h" // For error macros
 
-#include <errno.h> // For error macros
 #include <stdio.h>
 #include <stdlib.h>
 
index be6c61b..658bffc 100644 (file)
@@ -10,8 +10,8 @@
 
 #include "src/__support/CPP/new.h"
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/errno/libc_errno.h"         // For error macros
 
-#include <errno.h> // For error macros
 #include <fcntl.h> // For mode_t and other flags to the open syscall
 #include <stdio.h>
 #include <sys/syscall.h> // For syscall numbers
index 5c4c69f..e440792 100644 (file)
@@ -15,7 +15,7 @@ add_object_library(
     error_to_string.cpp
   DEPENDS
   .message_mapper
-  libc.include.errno
+  libc.src.errno.errno
   libc.src.__support.CPP.span
   libc.src.__support.CPP.string_view
   libc.src.__support.CPP.stringstream
index 98e2fbd..59e34c5 100644 (file)
@@ -13,8 +13,8 @@
 #include "src/__support/CPP/stringstream.h"
 #include "src/__support/StringUtil/message_mapper.h"
 #include "src/__support/integer_to_string.h"
+#include "src/errno/libc_errno.h" // For error macros
 
-#include <errno.h>
 #include <stddef.h>
 
 namespace __llvm_libc {
index df6ca4d..dc8c3cb 100644 (file)
@@ -21,7 +21,7 @@
 #include "src/__support/high_precision_decimal.h"
 #include "src/__support/str_to_integer.h"
 #include "src/__support/str_to_num_result.h"
-#include <errno.h>
+#include "src/errno/libc_errno.h" // For ERANGE
 
 namespace __llvm_libc {
 namespace internal {
index 8e1ce11..39ed940 100644 (file)
@@ -13,7 +13,7 @@
 #include "src/__support/common.h"
 #include "src/__support/ctype_utils.h"
 #include "src/__support/str_to_num_result.h"
-#include <errno.h>
+#include "src/errno/libc_errno.h" // For ERANGE
 #include <limits.h>
 
 namespace __llvm_libc {
index 21b5dce..62351da 100644 (file)
@@ -28,6 +28,7 @@ add_object_library(
     .futex_word_type
     libc.config.linux.app_h
     libc.include.sys_syscall
+    libc.src.errno.errno
     libc.src.__support.CPP.atomic
     libc.src.__support.CPP.stringstream
     libc.src.__support.CPP.string_view
index 90198fb..f158f16 100644 (file)
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/threads/linux/futex_word.h" // For FutexWordType
+#include "src/errno/libc_errno.h"                   // For error macros
 
 #ifdef LIBC_TARGET_ARCH_IS_AARCH64
 #include <arm_acle.h>
 #endif
 
-#include <errno.h>
 #include <fcntl.h>
 #include <linux/futex.h>
 #include <linux/prctl.h> // For PR_SET_NAME
index bb765ee..5f8d179 100644 (file)
@@ -25,7 +25,7 @@ add_entrypoint_object(
     fclose.h
   DEPENDS
     libc.include.stdio
-    libc.include.errno
+    libc.src.errno.errno
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
 )
@@ -109,7 +109,7 @@ add_entrypoint_object(
   HDRS
     fgetc.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -122,7 +122,7 @@ add_entrypoint_object(
   HDRS
     fgetc_unlocked.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -135,7 +135,7 @@ add_entrypoint_object(
   HDRS
     getc.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -148,7 +148,7 @@ add_entrypoint_object(
   HDRS
     getc_unlocked.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -161,7 +161,7 @@ add_entrypoint_object(
   HDRS
     fgets.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -174,7 +174,7 @@ add_entrypoint_object(
   HDRS
     fflush.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -211,7 +211,7 @@ add_entrypoint_object(
   HDRS
     fread_unlocked.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -224,7 +224,7 @@ add_entrypoint_object(
   HDRS
     fread.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -237,7 +237,7 @@ add_entrypoint_object(
   HDRS
     fwrite_unlocked.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -250,7 +250,7 @@ add_entrypoint_object(
   HDRS
     fwrite.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -263,7 +263,7 @@ add_entrypoint_object(
   HDRS
     fputc.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -276,7 +276,7 @@ add_entrypoint_object(
   HDRS
     putc.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -289,7 +289,7 @@ add_entrypoint_object(
   HDRS
     putchar.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -302,7 +302,7 @@ add_entrypoint_object(
   HDRS
     fputs.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -316,7 +316,7 @@ add_entrypoint_object(
   HDRS
     puts.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -329,7 +329,7 @@ add_entrypoint_object(
   HDRS
     fseek.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -402,7 +402,7 @@ add_entrypoint_object(
   HDRS
     setbuf.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -415,7 +415,7 @@ add_entrypoint_object(
   HDRS
     setvbuf.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
@@ -512,7 +512,7 @@ add_entrypoint_object(
   HDRS
     ftell.h
   DEPENDS
-    libc.include.errno
+    libc.src.errno.errno
     libc.include.stdio
     libc.src.__support.File.file
     libc.src.__support.File.platform_file
index b4a366a..1d53974 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/fclose.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -18,7 +18,7 @@ LLVM_LIBC_FUNCTION(int, fclose, (::FILE * stream)) {
   auto *file = reinterpret_cast<__llvm_libc::File *>(stream);
   int result = File::cleanup(file);
   if (result != 0) {
-    errno = result;
+    libc_errno = result;
     return EOF;
   }
   return 0;
index 75cf4d3..d7a5652 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/fflush.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -17,7 +17,7 @@ namespace __llvm_libc {
 LLVM_LIBC_FUNCTION(int, fflush, (::FILE * stream)) {
   int result = reinterpret_cast<__llvm_libc::File *>(stream)->flush();
   if (result != 0) {
-    errno = result;
+    libc_errno = result;
     return EOF;
   }
   return 0;
index 33b27a2..9a61096 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/fgetc.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -19,7 +19,7 @@ LLVM_LIBC_FUNCTION(int, fgetc, (::FILE * stream)) {
   auto result = reinterpret_cast<__llvm_libc::File *>(stream)->read(&c, 1);
   size_t r = result.value;
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   if (r != 1)
     return EOF;
index abec1d9..032a9fb 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/fgetc_unlocked.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -20,7 +20,7 @@ LLVM_LIBC_FUNCTION(int, fgetc_unlocked, (::FILE * stream)) {
       reinterpret_cast<__llvm_libc::File *>(stream)->read_unlocked(&c, 1);
   size_t r = result.value;
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
   if (r != 1)
     return EOF;
   return c;
index bb7c794..dd5051a 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/fgets.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stddef.h>
 #include <stdio.h>
 
@@ -32,7 +32,7 @@ LLVM_LIBC_FUNCTION(char *, fgets,
     auto result = stream->read_unlocked(&c, 1);
     size_t r = result.value;
     if (result.has_error())
-      errno = result.error;
+      libc_errno = result.error;
 
     if (r != 1)
       break;
index f39b65e..3062a05 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/fopen.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -18,7 +18,7 @@ LLVM_LIBC_FUNCTION(::FILE *, fopen,
                    (const char *__restrict name, const char *__restrict mode)) {
   auto result = __llvm_libc::openfile(name, mode);
   if (!result.has_value()) {
-    errno = result.error();
+    libc_errno = result.error();
     return nullptr;
   }
   return reinterpret_cast<::FILE *>(result.value());
index 2e3cce7..da72ed3 100644 (file)
@@ -10,7 +10,7 @@
 #include "src/__support/CPP/new.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 #include <stdlib.h>
 
index 8287e4e..5f41e5c 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/fputc.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -19,7 +19,7 @@ LLVM_LIBC_FUNCTION(int, fputc, (int c, ::FILE *stream)) {
 
   auto result = reinterpret_cast<__llvm_libc::File *>(stream)->write(&uc, 1);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
   size_t written = result.value;
 
   if (1 != written) {
index 0b1a3e1..d8ba18f 100644 (file)
@@ -10,7 +10,7 @@
 #include "src/__support/CPP/string_view.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -22,7 +22,7 @@ LLVM_LIBC_FUNCTION(int, fputs,
   auto result = reinterpret_cast<__llvm_libc::File *>(stream)->write(
       str, str_view.size());
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
   size_t written = result.value;
 
   if (str_view.size() != written) {
index 103d88c..affc6b7 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/fread.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -22,7 +22,7 @@ LLVM_LIBC_FUNCTION(size_t, fread,
   auto result =
       reinterpret_cast<__llvm_libc::File *>(stream)->read(buffer, size * nmemb);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
   return result.value / size;
 }
 
index 18e7160..3f922c5 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/fread_unlocked.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -22,7 +22,7 @@ LLVM_LIBC_FUNCTION(size_t, fread_unlocked,
   auto result = reinterpret_cast<__llvm_libc::File *>(stream)->read_unlocked(
       buffer, size * nmemb);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
   return result.value / size;
 }
 
index 4a29c99..928ff84 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/fseek.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -18,7 +18,7 @@ LLVM_LIBC_FUNCTION(int, fseek, (::FILE * stream, long offset, int whence)) {
   auto result =
       reinterpret_cast<__llvm_libc::File *>(stream)->seek(offset, whence);
   if (!result.has_value()) {
-    errno = result.error();
+    libc_errno = result.error();
     return -1;
   }
   return 0;
index 2d11a42..697e9bc 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/ftell.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -17,7 +17,7 @@ namespace __llvm_libc {
 LLVM_LIBC_FUNCTION(long, ftell, (::FILE * stream)) {
   auto result = reinterpret_cast<__llvm_libc::File *>(stream)->tell();
   if (!result.has_value()) {
-    errno = result.error();
+    libc_errno = result.error();
     return -1;
   }
   return result.value();
index 43f0201..cc6c450 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/fwrite.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -22,7 +22,7 @@ LLVM_LIBC_FUNCTION(size_t, fwrite,
   auto result = reinterpret_cast<__llvm_libc::File *>(stream)->write(
       buffer, size * nmemb);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   return result.value / size;
 }
index 47fe075..736dfe0 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/fwrite_unlocked.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -23,7 +23,7 @@ LLVM_LIBC_FUNCTION(size_t, fwrite_unlocked,
   auto result = reinterpret_cast<__llvm_libc::File *>(stream)->write_unlocked(
       buffer, size * nmemb);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   return result.value / size;
 }
index a27f79f..730be68 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/getc.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -19,7 +19,7 @@ LLVM_LIBC_FUNCTION(int, getc, (::FILE * stream)) {
   auto result = reinterpret_cast<__llvm_libc::File *>(stream)->read(&c, 1);
   size_t r = result.value;
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   if (r != 1)
     return EOF;
index ecb3184..4eae5c1 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/getc_unlocked.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -20,7 +20,7 @@ LLVM_LIBC_FUNCTION(int, getc_unlocked, (::FILE * stream)) {
       reinterpret_cast<__llvm_libc::File *>(stream)->read_unlocked(&c, 1);
   size_t r = result.value;
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   if (r != 1)
     return EOF;
index 2a868a7..0199644 100644 (file)
@@ -11,7 +11,7 @@
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <fcntl.h>       // For AT_* macros.
 #include <sys/syscall.h> // For syscall numbers.
 
@@ -25,7 +25,7 @@ LLVM_LIBC_FUNCTION(int, remove, (const char *path)) {
     ret = __llvm_libc::syscall_impl(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
   if (ret >= 0)
     return 0;
-  errno = -ret;
+  libc_errno = -ret;
   return -1;
 }
 
index 3016060..37937df 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/putc.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -19,7 +19,7 @@ LLVM_LIBC_FUNCTION(int, putc, (int c, ::FILE *stream)) {
 
   auto result = reinterpret_cast<__llvm_libc::File *>(stream)->write(&uc, 1);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
   size_t written = result.value;
 
   if (1 != written) {
index 2cf5d64..9190b71 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/putchar.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -19,7 +19,7 @@ LLVM_LIBC_FUNCTION(int, putchar, (int c)) {
 
   auto result = __llvm_libc::stdout->write(&uc, 1);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
   size_t written = result.value;
 
   if (1 != written) {
index 57e4919..ffcbf56 100644 (file)
@@ -10,7 +10,7 @@
 #include "src/__support/CPP/string_view.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -19,7 +19,7 @@ LLVM_LIBC_FUNCTION(int, puts, (const char *__restrict str)) {
   cpp::string_view str_view(str);
   auto result = __llvm_libc::stdout->write(str, str_view.size());
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
   size_t written = result.value;
   if (str_view.size() != written) {
     // The stream should be in an error state in this case.
@@ -27,7 +27,7 @@ LLVM_LIBC_FUNCTION(int, puts, (const char *__restrict str)) {
   }
   result = __llvm_libc::stdout->write("\n", 1);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
   written = result.value;
   if (1 != written) {
     // The stream should be in an error state in this case.
index b759632..cb30fe3 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/setbuf.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -22,7 +22,7 @@ LLVM_LIBC_FUNCTION(void, setbuf,
   int err = reinterpret_cast<__llvm_libc::File *>(stream)->set_buffer(
       buf, BUFSIZ, mode);
   if (err != 0)
-    errno = err;
+    libc_errno = err;
 }
 
 } // namespace __llvm_libc
index 162519f..9080c55 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdio/setvbuf.h"
 #include "src/__support/File/file.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 namespace __llvm_libc {
@@ -20,7 +20,7 @@ LLVM_LIBC_FUNCTION(int, setvbuf,
   int err = reinterpret_cast<__llvm_libc::File *>(stream)->set_buffer(buf, size,
                                                                       type);
   if (err != 0)
-    errno = err;
+    libc_errno = err;
   return err;
 }
 
index b067e84..a9de969 100644 (file)
@@ -5,6 +5,7 @@ add_entrypoint_object(
   HDRS
     atoi.h
   DEPENDS
+    libc.src.errno.errno
     libc.src.__support.str_to_integer
 )
 
@@ -15,6 +16,7 @@ add_entrypoint_object(
   HDRS
     atof.h
   DEPENDS
+    libc.src.errno.errno
     libc.src.__support.str_to_float
 )
 
@@ -25,6 +27,7 @@ add_entrypoint_object(
   HDRS
     atol.h
   DEPENDS
+    libc.src.errno.errno
     libc.src.__support.str_to_integer
 )
 
@@ -35,6 +38,7 @@ add_entrypoint_object(
   HDRS
     atoll.h
   DEPENDS
+    libc.src.errno.errno
     libc.src.__support.str_to_integer
 )
 
@@ -55,6 +59,7 @@ add_entrypoint_object(
   HDRS
     strtof.h
   DEPENDS
+    libc.src.errno.errno
     libc.src.__support.str_to_float
 )
 
@@ -65,6 +70,7 @@ add_entrypoint_object(
   HDRS
     strtod.h
   DEPENDS
+    libc.src.errno.errno
     libc.src.__support.str_to_float
 )
 
@@ -75,6 +81,7 @@ add_entrypoint_object(
   HDRS
     strtold.h
   DEPENDS
+    libc.src.errno.errno
     libc.src.__support.str_to_float
 )
 
@@ -85,6 +92,7 @@ add_entrypoint_object(
   HDRS
     strtol.h
   DEPENDS
+    libc.src.errno.errno
     libc.src.__support.str_to_integer
 )
 
@@ -95,6 +103,7 @@ add_entrypoint_object(
   HDRS
     strtoll.h
   DEPENDS
+    libc.src.errno.errno
     libc.src.__support.str_to_integer
 )
 
@@ -105,6 +114,7 @@ add_entrypoint_object(
   HDRS
     strtoul.h
   DEPENDS
+    libc.src.errno.errno
     libc.src.__support.str_to_integer
 )
 
@@ -115,6 +125,7 @@ add_entrypoint_object(
   HDRS
     strtoull.h
   DEPENDS
+    libc.src.errno.errno
     libc.src.__support.str_to_integer
 )
 
index 3066df0..2359ce7 100644 (file)
@@ -9,14 +9,14 @@
 #include "src/stdlib/atof.h"
 #include "src/__support/common.h"
 #include "src/__support/str_to_float.h"
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 
 namespace __llvm_libc {
 
 LLVM_LIBC_FUNCTION(double, atof, (const char *str)) {
   auto result = internal::strtofloatingpoint<double>(str);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   return result.value;
 }
index d9bc866..eec15aa 100644 (file)
@@ -9,6 +9,7 @@
 #include "src/stdlib/atoi.h"
 #include "src/__support/common.h"
 #include "src/__support/str_to_integer.h"
+#include "src/errno/libc_errno.h"
 
 namespace __llvm_libc {
 
@@ -17,7 +18,7 @@ LLVM_LIBC_FUNCTION(int, atoi, (const char *str)) {
   // (int)(strtol).
   auto result = internal::strtointeger<long>(str, 10);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   return static_cast<int>(result);
 }
index d786845..78928e8 100644 (file)
@@ -9,13 +9,14 @@
 #include "src/stdlib/atol.h"
 #include "src/__support/common.h"
 #include "src/__support/str_to_integer.h"
+#include "src/errno/libc_errno.h"
 
 namespace __llvm_libc {
 
 LLVM_LIBC_FUNCTION(long, atol, (const char *str)) {
   auto result = internal::strtointeger<long>(str, 10);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   return result;
 }
index cfa8edf..5047226 100644 (file)
@@ -9,13 +9,14 @@
 #include "src/stdlib/atoll.h"
 #include "src/__support/common.h"
 #include "src/__support/str_to_integer.h"
+#include "src/errno/libc_errno.h"
 
 namespace __llvm_libc {
 
 LLVM_LIBC_FUNCTION(long long, atoll, (const char *str)) {
   auto result = internal::strtointeger<long long>(str, 10);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   return result;
 }
index 0690cfd..eb3f290 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdlib/strtod.h"
 #include "src/__support/common.h"
 #include "src/__support/str_to_float.h"
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 
 namespace __llvm_libc {
 
@@ -17,7 +17,7 @@ LLVM_LIBC_FUNCTION(double, strtod,
                    (const char *__restrict str, char **__restrict str_end)) {
   auto result = internal::strtofloatingpoint<double>(str);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   if (str_end != NULL)
     *str_end = const_cast<char *>(str + result.parsed_len);
index 41141c6..f4b90e8 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdlib/strtof.h"
 #include "src/__support/common.h"
 #include "src/__support/str_to_float.h"
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 
 namespace __llvm_libc {
 
@@ -17,7 +17,7 @@ LLVM_LIBC_FUNCTION(float, strtof,
                    (const char *__restrict str, char **__restrict str_end)) {
   auto result = internal::strtofloatingpoint<float>(str);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   if (str_end != NULL)
     *str_end = const_cast<char *>(str + result.parsed_len);
index 9564f5d..fb02353 100644 (file)
@@ -9,6 +9,7 @@
 #include "src/stdlib/strtol.h"
 #include "src/__support/common.h"
 #include "src/__support/str_to_integer.h"
+#include "src/errno/libc_errno.h"
 
 namespace __llvm_libc {
 
@@ -17,7 +18,7 @@ LLVM_LIBC_FUNCTION(long, strtol,
                     int base)) {
   auto result = internal::strtointeger<long>(str, base);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   if (str_end != nullptr)
     *str_end = const_cast<char *>(str + result.parsed_len);
index bccb273..01cbb7f 100644 (file)
@@ -9,7 +9,7 @@
 #include "src/stdlib/strtold.h"
 #include "src/__support/common.h"
 #include "src/__support/str_to_float.h"
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 
 namespace __llvm_libc {
 
@@ -17,7 +17,7 @@ LLVM_LIBC_FUNCTION(long double, strtold,
                    (const char *__restrict str, char **__restrict str_end)) {
   auto result = internal::strtofloatingpoint<long double>(str);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   if (str_end != NULL)
     *str_end = const_cast<char *>(str + result.parsed_len);
index c1aa94e..f4f9754 100644 (file)
@@ -9,6 +9,7 @@
 #include "src/stdlib/strtoll.h"
 #include "src/__support/common.h"
 #include "src/__support/str_to_integer.h"
+#include "src/errno/libc_errno.h"
 
 namespace __llvm_libc {
 
@@ -17,7 +18,7 @@ LLVM_LIBC_FUNCTION(long long, strtoll,
                     int base)) {
   auto result = internal::strtointeger<long long>(str, base);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   if (str_end != nullptr)
     *str_end = const_cast<char *>(str + result.parsed_len);
index d0accb5..c3b1b93 100644 (file)
@@ -9,6 +9,7 @@
 #include "src/stdlib/strtoul.h"
 #include "src/__support/common.h"
 #include "src/__support/str_to_integer.h"
+#include "src/errno/libc_errno.h"
 
 namespace __llvm_libc {
 
@@ -17,7 +18,7 @@ LLVM_LIBC_FUNCTION(unsigned long, strtoul,
                     int base)) {
   auto result = internal::strtointeger<unsigned long>(str, base);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   if (str_end != nullptr)
     *str_end = const_cast<char *>(str + result.parsed_len);
index 26f0821..9bf3d0b 100644 (file)
@@ -9,6 +9,7 @@
 #include "src/stdlib/strtoull.h"
 #include "src/__support/common.h"
 #include "src/__support/str_to_integer.h"
+#include "src/errno/libc_errno.h"
 
 namespace __llvm_libc {
 
@@ -17,7 +18,7 @@ LLVM_LIBC_FUNCTION(unsigned long long, strtoull,
                     int base)) {
   auto result = internal::strtointeger<unsigned long long>(str, base);
   if (result.has_error())
-    errno = result.error;
+    libc_errno = result.error;
 
   if (str_end != nullptr)
     *str_end = const_cast<char *>(str + result.parsed_len);
index e94432d..8747f18 100644 (file)
@@ -7,8 +7,8 @@ add_libc_unittest(
   SRCS
     fileop_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.stdio
+    libc.src.errno.errno
     libc.src.stdio.clearerr
     libc.src.stdio.fclose
     libc.src.stdio.feof
@@ -60,8 +60,8 @@ add_libc_unittest(
   SRCS
     setvbuf_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.stdio
+    libc.src.errno.errno
     libc.src.stdio.fclose
     libc.src.stdio.fopen
     libc.src.stdio.fread
@@ -76,8 +76,8 @@ add_libc_unittest(
   SRCS
     unlocked_fileop_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.stdio
+    libc.src.errno.errno
     libc.src.stdio.clearerr_unlocked
     libc.src.stdio.fclose
     libc.src.stdio.feof_unlocked
@@ -96,9 +96,9 @@ add_libc_unittest(
   SRCS
     fopencookie_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.stdio
     libc.include.stdlib
+    libc.src.errno.errno
     libc.src.stdio.clearerr
     libc.src.stdio.fclose
     libc.src.stdio.feof
@@ -218,8 +218,8 @@ if(${LIBC_TARGET_OS} STREQUAL "linux")
     SRCS
       remove_test.cpp
     DEPENDS
-      libc.include.errno
       libc.include.unistd
+      libc.src.errno.errno
       libc.src.fcntl.open
       libc.src.stdio.remove
       libc.src.sys.stat.mkdirat
@@ -235,8 +235,8 @@ add_libc_unittest(
   SRCS
     fgetc_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.stdio
+    libc.src.errno.errno
     libc.src.stdio.fclose
     libc.src.stdio.feof
     libc.src.stdio.ferror
@@ -253,8 +253,8 @@ add_libc_unittest(
   SRCS
     fgetc_unlocked_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.stdio
+    libc.src.errno.errno
     libc.src.stdio.fclose
     libc.src.stdio.ferror
     libc.src.stdio.ferror_unlocked
@@ -275,8 +275,8 @@ add_libc_unittest(
   SRCS
     fgets_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.stdio
+    libc.src.errno.errno
     libc.src.stdio.fclose
     libc.src.stdio.feof
     libc.src.stdio.ferror
@@ -292,7 +292,6 @@ add_libc_unittest(
   SRCS
     ftell_test.cpp
   DEPENDS
-    libc.include.errno
     libc.include.stdio
     libc.src.stdio.fclose
     libc.src.stdio.fflush
index 464fd20..b262dda 100644 (file)
@@ -16,7 +16,7 @@
 #include "src/stdio/getc.h"
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 class LlvmLibcGetcTest : public __llvm_libc::testing::Test {
@@ -33,7 +33,7 @@ public:
     // This is an error and not a real EOF.
     ASSERT_EQ(__llvm_libc::feof(file), 0);
     ASSERT_NE(__llvm_libc::ferror(file), 0);
-    errno = 0;
+    libc_errno = 0;
 
     ASSERT_EQ(0, __llvm_libc::fclose(file));
 
index d8e0cd1..4608be3 100644 (file)
@@ -19,7 +19,7 @@
 #include "src/stdio/getc_unlocked.h"
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 class LlvmLibcGetcTest : public __llvm_libc::testing::Test {
@@ -36,7 +36,7 @@ public:
     // This is an error and not a real EOF.
     ASSERT_EQ(__llvm_libc::feof(file), 0);
     ASSERT_NE(__llvm_libc::ferror(file), 0);
-    errno = 0;
+    libc_errno = 0;
 
     ASSERT_EQ(0, __llvm_libc::fclose(file));
 
index 1ef2415..150a9dd 100644 (file)
@@ -14,7 +14,7 @@
 #include "src/stdio/fwrite.h"
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 TEST(LlvmLibcFgetsTest, WriteAndReadCharacters) {
@@ -36,7 +36,7 @@ TEST(LlvmLibcFgetsTest, WriteAndReadCharacters) {
   // This is an error and not a real EOF.
   ASSERT_EQ(__llvm_libc::feof(file), 0);
   ASSERT_NE(__llvm_libc::ferror(file), 0);
-  errno = 0;
+  libc_errno = 0;
 
   ASSERT_EQ(0, __llvm_libc::fclose(file));
 
@@ -48,7 +48,7 @@ TEST(LlvmLibcFgetsTest, WriteAndReadCharacters) {
   output = __llvm_libc::fgets(buff, 1, file);
   ASSERT_TRUE(output == buff);
   ASSERT_EQ(buff[0], '\0');
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
 
   // If we request less than 1 byte, it should do nothing and return nullptr.
   // This is also implementation defined.
@@ -76,13 +76,13 @@ TEST(LlvmLibcFgetsTest, WriteAndReadCharacters) {
   // fails to read anything.
   ASSERT_NE(__llvm_libc::feof(file), 0);
   ASSERT_EQ(__llvm_libc::ferror(file), 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
 
   // Reading more should be an EOF, but not an error.
   output = __llvm_libc::fgets(buff, 8, file);
   ASSERT_TRUE(output == nullptr);
   ASSERT_NE(__llvm_libc::feof(file), 0);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
 
   ASSERT_EQ(0, __llvm_libc::fclose(file));
 }
index 6d068ad..989de29 100644 (file)
@@ -18,7 +18,7 @@
 #include "src/stdio/fwrite.h"
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 TEST(LlvmLibcFILETest, SimpleFileOperations) {
@@ -33,8 +33,8 @@ TEST(LlvmLibcFILETest, SimpleFileOperations) {
   char read_data[sizeof(CONTENT)];
   ASSERT_EQ(__llvm_libc::fread(read_data, 1, sizeof(CONTENT), file), size_t(0));
   ASSERT_NE(__llvm_libc::ferror(file), 0);
-  EXPECT_NE(errno, 0);
-  errno = 0;
+  EXPECT_NE(libc_errno, 0);
+  libc_errno = 0;
 
   __llvm_libc::clearerr(file);
   ASSERT_EQ(__llvm_libc::ferror(file), 0);
@@ -64,24 +64,24 @@ TEST(LlvmLibcFILETest, SimpleFileOperations) {
   // Should be an error to write.
   ASSERT_EQ(size_t(0), __llvm_libc::fwrite(CONTENT, 1, sizeof(CONTENT), file));
   ASSERT_NE(__llvm_libc::ferror(file), 0);
-  ASSERT_NE(errno, 0);
-  errno = 0;
+  ASSERT_NE(libc_errno, 0);
+  libc_errno = 0;
 
   __llvm_libc::clearerr(file);
 
   // Should be an error to puts.
   ASSERT_EQ(EOF, __llvm_libc::fputs(CONTENT, file));
   ASSERT_NE(__llvm_libc::ferror(file), 0);
-  ASSERT_NE(errno, 0);
-  errno = 0;
+  ASSERT_NE(libc_errno, 0);
+  libc_errno = 0;
 
   __llvm_libc::clearerr(file);
   ASSERT_EQ(__llvm_libc::ferror(file), 0);
 
-  errno = 0;
+  libc_errno = 0;
   ASSERT_EQ(__llvm_libc::fwrite("nothing", 1, 1, file), size_t(0));
-  ASSERT_NE(errno, 0);
-  errno = 0;
+  ASSERT_NE(libc_errno, 0);
+  libc_errno = 0;
 
   ASSERT_EQ(__llvm_libc::fclose(file), 0);
 
@@ -96,10 +96,10 @@ TEST(LlvmLibcFILETest, SimpleFileOperations) {
   ASSERT_EQ(__llvm_libc::ferror(file), 0);
 
   // This is not a readable file.
-  errno = 0;
+  libc_errno = 0;
   ASSERT_EQ(__llvm_libc::fread(data, 1, 1, file), size_t(0));
-  ASSERT_NE(errno, 0);
-  errno = 0;
+  ASSERT_NE(libc_errno, 0);
+  libc_errno = 0;
 
   ASSERT_EQ(0, __llvm_libc::fclose(file));
 
@@ -112,20 +112,20 @@ TEST(LlvmLibcFILETest, SimpleFileOperations) {
   ASSERT_STREQ(read_data, CONTENT);
   ASSERT_EQ(__llvm_libc::fclose(file), 0);
 
-  // Check that the other functions correctly set errno.
+  // Check that the other functions correctly set libc_errno.
 
-  // errno = 0;
+  // libc_errno = 0;
   // ASSERT_NE(__llvm_libc::fseek(file, 0, SEEK_SET), 0);
-  // EXPECT_NE(errno, 0);
+  // EXPECT_NE(libc_errno, 0);
 
-  // errno = 0;
+  // libc_errno = 0;
   // ASSERT_NE(__llvm_libc::fclose(file), 0);
-  // EXPECT_NE(errno, 0);
+  // EXPECT_NE(libc_errno, 0);
 
-  // errno = 0;
+  // libc_errno = 0;
   // ASSERT_EQ(__llvm_libc::fopen("INVALID FILE NAME", "r"),
   //           static_cast<FILE *>(nullptr));
-  // EXPECT_NE(errno, 0);
+  // EXPECT_NE(libc_errno, 0);
 }
 
 TEST(LlvmLibcFILETest, FFlush) {
@@ -158,13 +158,13 @@ TEST(LlvmLibcFILETest, FOpenFWriteSizeGreaterThanOne) {
   constexpr size_t WRITE_NMEMB = sizeof(WRITE_DATA) / sizeof(MyStruct);
   constexpr char FILENAME[] = "testdata/fread_fwrite.test";
 
-  errno = 0;
+  libc_errno = 0;
   FILE *file = __llvm_libc::fopen(FILENAME, "w");
   ASSERT_FALSE(file == nullptr);
   ASSERT_EQ(size_t(0), __llvm_libc::fwrite(WRITE_DATA, 0, 1, file));
   ASSERT_EQ(WRITE_NMEMB, __llvm_libc::fwrite(WRITE_DATA, sizeof(MyStruct),
                                              WRITE_NMEMB, file));
-  EXPECT_EQ(errno, 0);
+  EXPECT_EQ(libc_errno, 0);
   ASSERT_EQ(__llvm_libc::fclose(file), 0);
 
   file = __llvm_libc::fopen(FILENAME, "r");
@@ -173,11 +173,11 @@ TEST(LlvmLibcFILETest, FOpenFWriteSizeGreaterThanOne) {
   ASSERT_EQ(size_t(0), __llvm_libc::fread(read_data, 0, 1, file));
   ASSERT_EQ(WRITE_NMEMB,
             __llvm_libc::fread(read_data, sizeof(MyStruct), WRITE_NMEMB, file));
-  EXPECT_EQ(errno, 0);
+  EXPECT_EQ(libc_errno, 0);
   // Trying to read more should fetch nothing.
   ASSERT_EQ(size_t(0),
             __llvm_libc::fread(read_data, sizeof(MyStruct), WRITE_NMEMB, file));
-  EXPECT_EQ(errno, 0);
+  EXPECT_EQ(libc_errno, 0);
   EXPECT_NE(__llvm_libc::feof(file), 0);
   EXPECT_EQ(__llvm_libc::ferror(file), 0);
   ASSERT_EQ(__llvm_libc::fclose(file), 0);
index ff24b58..1397006 100644 (file)
@@ -18,7 +18,7 @@
 #include "test/UnitTest/MemoryMatcher.h"
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -67,7 +67,7 @@ int seek_ss(void *cookie, off64_t *offset, int whence) {
   } else if (whence == SEEK_END) {
     new_offset = *offset + ss->endpos;
   } else {
-    errno = EINVAL;
+    libc_errno = EINVAL;
     return -1;
   }
   if (new_offset < 0 || size_t(new_offset) > ss->bufsize)
@@ -114,8 +114,8 @@ TEST(LlvmLibcFOpenCookie, ReadOnlyCookieTest) {
   // Should be an error to write.
   ASSERT_EQ(size_t(0), __llvm_libc::fwrite(CONTENT, 1, sizeof(CONTENT), f));
   ASSERT_NE(__llvm_libc::ferror(f), 0);
-  ASSERT_NE(errno, 0);
-  errno = 0;
+  ASSERT_NE(libc_errno, 0);
+  libc_errno = 0;
 
   __llvm_libc::clearerr(f);
   ASSERT_EQ(__llvm_libc::ferror(f), 0);
@@ -147,8 +147,8 @@ TEST(LlvmLibcFOpenCookie, WriteOnlyCookieTest) {
   // Should be an error to read.
   ASSERT_EQ(size_t(0), __llvm_libc::fread(read_data, 1, sizeof(WRITE_DATA), f));
   ASSERT_NE(__llvm_libc::ferror(f), 0);
-  ASSERT_EQ(errno, EBADF);
-  errno = 0;
+  ASSERT_EQ(libc_errno, EBADF);
+  libc_errno = 0;
 
   __llvm_libc::clearerr(f);
   ASSERT_EQ(__llvm_libc::ferror(f), 0);
@@ -176,8 +176,8 @@ TEST(LlvmLibcFOpenCookie, AppendOnlyCookieTest) {
   // This is not a readable file.
   ASSERT_EQ(__llvm_libc::fread(read_data, 1, READ_SIZE, f), size_t(0));
   ASSERT_NE(__llvm_libc::ferror(f), 0);
-  EXPECT_NE(errno, 0);
-  errno = 0;
+  EXPECT_NE(libc_errno, 0);
+  libc_errno = 0;
 
   __llvm_libc::clearerr(f);
   ASSERT_EQ(__llvm_libc::ferror(f), 0);
index 7b0b1ad..286c516 100644 (file)
@@ -15,7 +15,6 @@
 
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
 #include <stdio.h>
 
 TEST(LlvmLibcFPrintfTest, WriteToFile) {
index f4f61a2..71402f0 100644 (file)
@@ -16,7 +16,6 @@
 
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
 #include <stdio.h>
 
 TEST(LlvmLibcFScanfTest, WriteToFile) {
index 5a74c44..e5e4cc4 100644 (file)
@@ -16,7 +16,6 @@
 #include "src/stdio/setvbuf.h"
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
 #include <stdio.h>
 
 class LlvmLibcFTellTest : public __llvm_libc::testing::Test {
@@ -54,10 +53,6 @@ protected:
     ASSERT_EQ(size_t(__llvm_libc::ftell(file)), READ_SIZE);
 
     ASSERT_EQ(0, __llvm_libc::fclose(file));
-
-    // errno = 0;
-    // ASSERT_EQ(__llvm_libc::ftell(file), long(-1));
-    // ASSERT_NE(errno, 0);
   }
 };
 
index 384526b..0bd3acc 100644 (file)
@@ -15,7 +15,6 @@
 
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
 #include <stdio.h>
 
 TEST(LlvmLibcPutcTest, WriteToFile) {
index 4295046..b6e8b64 100644 (file)
 #include "test/UnitTest/Test.h"
 #include "utils/testutils/FDReader.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <unistd.h>
 
 TEST(LlvmLibcRemoveTest, CreateAndRemoveFile) {
   // The test strategy is to create a file and remove it, and also verify that
   // it was removed.
-  errno = 0;
+  libc_errno = 0;
   using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
   using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
   constexpr const char *TEST_FILE = "testdata/remove.test.file";
   int fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
-  ASSERT_EQ(errno, 0);
+  ASSERT_EQ(libc_errno, 0);
   ASSERT_GT(fd, 0);
   ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
 
@@ -38,7 +38,7 @@ TEST(LlvmLibcRemoveTest, CreateAndRemoveFile) {
 TEST(LlvmLibcRemoveTest, CreateAndRemoveDir) {
   // The test strategy is to create a dir and remove it, and also verify that
   // it was removed.
-  errno = 0;
+  libc_errno = 0;
   using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
   using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
   constexpr const char *TEST_DIR = "testdata/remove.test.dir";
index f111fcc..6b44f6b 100644 (file)
@@ -13,7 +13,7 @@
 #include "src/stdio/setvbuf.h"
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 TEST(LlvmLibcSetvbufTest, SetNBFBuffer) {
@@ -99,8 +99,8 @@ TEST(LlvmLibcSetbufTest, InvalidBufferMode) {
   ASSERT_FALSE(f == nullptr);
   char buf[BUFSIZ];
   ASSERT_NE(__llvm_libc::setvbuf(f, buf, _IOFBF + _IOLBF + _IONBF, BUFSIZ), 0);
-  ASSERT_EQ(errno, EINVAL);
+  ASSERT_EQ(libc_errno, EINVAL);
 
-  errno = 0;
+  libc_errno = 0;
   ASSERT_EQ(0, __llvm_libc::fclose(f));
 }
index 86a6354..67ce11e 100644 (file)
@@ -17,7 +17,7 @@
 #include "src/stdio/fwrite_unlocked.h"
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
+#include "src/errno/libc_errno.h"
 #include <stdio.h>
 
 TEST(LlvmLibcFILETest, UnlockedReadAndWrite) {
@@ -36,8 +36,8 @@ TEST(LlvmLibcFILETest, UnlockedReadAndWrite) {
   ASSERT_EQ(size_t(0),
             __llvm_libc::fread_unlocked(data, 1, sizeof(READ_SIZE), f));
   ASSERT_NE(__llvm_libc::ferror_unlocked(f), 0);
-  ASSERT_NE(errno, 0);
-  errno = 0;
+  ASSERT_NE(libc_errno, 0);
+  libc_errno = 0;
 
   __llvm_libc::clearerr_unlocked(f);
   ASSERT_EQ(__llvm_libc::ferror_unlocked(f), 0);
@@ -57,8 +57,8 @@ TEST(LlvmLibcFILETest, UnlockedReadAndWrite) {
   ASSERT_EQ(size_t(0),
             __llvm_libc::fwrite_unlocked(CONTENT, 1, sizeof(CONTENT), f));
   ASSERT_NE(__llvm_libc::ferror_unlocked(f), 0);
-  ASSERT_NE(errno, 0);
-  errno = 0;
+  ASSERT_NE(libc_errno, 0);
+  libc_errno = 0;
 
   __llvm_libc::clearerr_unlocked(f);
   ASSERT_EQ(__llvm_libc::ferror_unlocked(f), 0);
index 67e0e97..b1893bc 100644 (file)
@@ -7,6 +7,7 @@ add_libc_unittest(
   SRCS
     atof_test.cpp
   DEPENDS
+    libc.src.errno.errno
     libc.src.stdlib.atof
 )
 
@@ -15,6 +16,7 @@ add_header_library(
   HDRS
     AtoiTest.h
   DEPENDS
+    libc.src.errno.errno
     libc.src.__support.CPP.type_traits
 )
 
@@ -58,6 +60,7 @@ add_libc_unittest(
   SRCS
     strtod_test.cpp
   DEPENDS
+    libc.src.errno.errno
     libc.src.stdlib.strtod
 )
 
@@ -68,6 +71,7 @@ add_libc_unittest(
   SRCS
     strtof_test.cpp
   DEPENDS
+    libc.src.errno.errno
     libc.src.stdlib.strtof
 )
 
@@ -78,7 +82,6 @@ add_header_library(
   DEPENDS
     libc.src.__support.CPP.limits
     libc.src.__support.CPP.type_traits
-    libc.include.errno
     libc.src.errno.errno
 )
 
@@ -100,6 +103,7 @@ add_libc_unittest(
   SRCS
     strtold_test.cpp
   DEPENDS
+    libc.src.errno.errno
     libc.src.__support.uint128
     libc.src.stdlib.strtold
 )
index f3d610e..09d8da1 100644 (file)
@@ -8,9 +8,9 @@
 
 #include "src/__support/CPP/limits.h"
 #include "src/__support/CPP/type_traits.h"
+#include "src/errno/libc_errno.h"
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
 #include <limits.h>
 #include <stddef.h>
 
@@ -35,9 +35,9 @@ struct StrtoTest : public __llvm_libc::testing::Test {
 
   void InvalidBase(FunctionT func) {
     const char *ten = "10";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(ten, nullptr, -1), ReturnT(0));
-    ASSERT_EQ(errno, EINVAL);
+    ASSERT_EQ(libc_errno, EINVAL);
   }
 
   void CleanBaseTenDecode(FunctionT func) {
@@ -45,69 +45,69 @@ struct StrtoTest : public __llvm_libc::testing::Test {
 
     // TODO: Look into collapsing these repeated segments.
     const char *ten = "10";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(ten, &str_end, 10), ReturnT(10));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - ten, ptrdiff_t(2));
 
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(ten, nullptr, 10), ReturnT(10));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
 
     const char *hundred = "100";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(hundred, &str_end, 10), ReturnT(100));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - hundred, ptrdiff_t(3));
 
     const char *big_number = "1234567890";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(big_number, &str_end, 10), ReturnT(1234567890));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - big_number, ptrdiff_t(10));
 
     // This number is larger than 2^32, meaning that if long is only 32 bits
     // wide, strtol will return LONG_MAX.
     const char *bigger_number = "12345678900";
-    errno = 0;
+    libc_errno = 0;
     if constexpr (sizeof(ReturnT) < 8) {
       ASSERT_EQ(func(bigger_number, &str_end, 10), T_MAX);
-      ASSERT_EQ(errno, ERANGE);
+      ASSERT_EQ(libc_errno, ERANGE);
     } else {
       ASSERT_EQ(func(bigger_number, &str_end, 10), ReturnT(12345678900));
-      ASSERT_EQ(errno, 0);
+      ASSERT_EQ(libc_errno, 0);
     }
     EXPECT_EQ(str_end - bigger_number, ptrdiff_t(11));
 
     const char *too_big_number = "123456789012345678901";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(too_big_number, &str_end, 10), T_MAX);
-    ASSERT_EQ(errno, ERANGE);
+    ASSERT_EQ(libc_errno, ERANGE);
     EXPECT_EQ(str_end - too_big_number, ptrdiff_t(21));
 
     const char *long_number_range_test =
         "10000000000000000000000000000000000000000000000000";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(long_number_range_test, &str_end, 10), T_MAX);
-    ASSERT_EQ(errno, ERANGE);
+    ASSERT_EQ(libc_errno, ERANGE);
     EXPECT_EQ(str_end - long_number_range_test, ptrdiff_t(50));
 
     // For most negative numbers, the unsigned functions treat it the same as
     // casting a negative variable to an unsigned type.
     const char *negative = "-100";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(negative, &str_end, 10), ReturnT(-100));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - negative, ptrdiff_t(4));
 
     const char *big_negative_number = "-1234567890";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(big_negative_number, &str_end, 10), ReturnT(-1234567890));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - big_negative_number, ptrdiff_t(11));
 
     const char *too_big_negative_number = "-123456789012345678901";
-    errno = 0;
+    libc_errno = 0;
     // If the number is signed, it should return the smallest negative number
     // for the current type, but if it's unsigned it should max out and return
     // the largest positive number for the current type. From the standard:
@@ -117,7 +117,7 @@ struct StrtoTest : public __llvm_libc::testing::Test {
     // Note that 0 is not on that list.
     ASSERT_EQ(func(too_big_negative_number, &str_end, 10),
               (is_signed_v<ReturnT> ? T_MIN : T_MAX));
-    ASSERT_EQ(errno, ERANGE);
+    ASSERT_EQ(libc_errno, ERANGE);
     EXPECT_EQ(str_end - too_big_negative_number, ptrdiff_t(22));
   }
 
@@ -125,75 +125,75 @@ struct StrtoTest : public __llvm_libc::testing::Test {
     char *str_end = nullptr;
 
     const char *spaces_before = "     10";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(spaces_before, &str_end, 10), ReturnT(10));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - spaces_before, ptrdiff_t(7));
 
     const char *spaces_after = "10      ";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(spaces_after, &str_end, 10), ReturnT(10));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - spaces_after, ptrdiff_t(2));
 
     const char *word_before = "word10";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(word_before, &str_end, 10), ReturnT(0));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - word_before, ptrdiff_t(0));
 
     const char *word_after = "10word";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(word_after, &str_end, 10), ReturnT(10));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - word_after, ptrdiff_t(2));
 
     const char *two_numbers = "10 999";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(two_numbers, &str_end, 10), ReturnT(10));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - two_numbers, ptrdiff_t(2));
 
     const char *two_signs = "--10 999";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(two_signs, &str_end, 10), ReturnT(0));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - two_signs, ptrdiff_t(0));
 
     const char *sign_before = "+2=4";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(sign_before, &str_end, 10), ReturnT(2));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - sign_before, ptrdiff_t(2));
 
     const char *sign_after = "2+2=4";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(sign_after, &str_end, 10), ReturnT(2));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - sign_after, ptrdiff_t(1));
 
     const char *tab_before = "\t10";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(tab_before, &str_end, 10), ReturnT(10));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - tab_before, ptrdiff_t(3));
 
     const char *all_together = "\t  -12345and+67890";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(all_together, &str_end, 10), ReturnT(-12345));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - all_together, ptrdiff_t(9));
 
     const char *just_spaces = "  ";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(just_spaces, &str_end, 10), ReturnT(0));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - just_spaces, ptrdiff_t(0));
 
     const char *just_space_and_sign = " +";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(just_space_and_sign, &str_end, 10), ReturnT(0));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - just_space_and_sign, ptrdiff_t(0));
   }
 
@@ -203,14 +203,14 @@ struct StrtoTest : public __llvm_libc::testing::Test {
       for (int first_digit = 0; first_digit <= 36; ++first_digit) {
         small_string[0] = int_to_b36_char(first_digit);
         if (first_digit < base) {
-          errno = 0;
+          libc_errno = 0;
           ASSERT_EQ(func(small_string, nullptr, base),
                     static_cast<ReturnT>(first_digit));
-          ASSERT_EQ(errno, 0);
+          ASSERT_EQ(libc_errno, 0);
         } else {
-          errno = 0;
+          libc_errno = 0;
           ASSERT_EQ(func(small_string, nullptr, base), ReturnT(0));
-          ASSERT_EQ(errno, 0);
+          ASSERT_EQ(libc_errno, 0);
         }
       }
     }
@@ -221,20 +221,20 @@ struct StrtoTest : public __llvm_libc::testing::Test {
         for (int second_digit = 0; second_digit <= 36; ++second_digit) {
           small_string[1] = int_to_b36_char(second_digit);
           if (first_digit < base && second_digit < base) {
-            errno = 0;
+            libc_errno = 0;
             ASSERT_EQ(
                 func(small_string, nullptr, base),
                 static_cast<ReturnT>(second_digit + (first_digit * base)));
-            ASSERT_EQ(errno, 0);
+            ASSERT_EQ(libc_errno, 0);
           } else if (first_digit < base) {
-            errno = 0;
+            libc_errno = 0;
             ASSERT_EQ(func(small_string, nullptr, base),
                       static_cast<ReturnT>(first_digit));
-            ASSERT_EQ(errno, 0);
+            ASSERT_EQ(libc_errno, 0);
           } else {
-            errno = 0;
+            libc_errno = 0;
             ASSERT_EQ(func(small_string, nullptr, base), ReturnT(0));
-            ASSERT_EQ(errno, 0);
+            ASSERT_EQ(libc_errno, 0);
           }
         }
       }
@@ -250,42 +250,42 @@ struct StrtoTest : public __llvm_libc::testing::Test {
 
             if (first_digit < base && second_digit < base &&
                 third_digit < base) {
-              errno = 0;
+              libc_errno = 0;
               ASSERT_EQ(func(small_string, nullptr, base),
                         static_cast<ReturnT>(third_digit +
                                              (second_digit * base) +
                                              (first_digit * base * base)));
-              ASSERT_EQ(errno, 0);
+              ASSERT_EQ(libc_errno, 0);
             } else if (first_digit < base && second_digit < base) {
-              errno = 0;
+              libc_errno = 0;
               ASSERT_EQ(
                   func(small_string, nullptr, base),
                   static_cast<ReturnT>(second_digit + (first_digit * base)));
-              ASSERT_EQ(errno, 0);
+              ASSERT_EQ(libc_errno, 0);
             } else if (first_digit < base) {
               // if the base is 16 there is a special case for the prefix 0X.
               // The number is treated as a one digit hexadecimal.
               if (base == 16 && first_digit == 0 && second_digit == 33) {
                 if (third_digit < base) {
-                  errno = 0;
+                  libc_errno = 0;
                   ASSERT_EQ(func(small_string, nullptr, base),
                             static_cast<ReturnT>(third_digit));
-                  ASSERT_EQ(errno, 0);
+                  ASSERT_EQ(libc_errno, 0);
                 } else {
-                  errno = 0;
+                  libc_errno = 0;
                   ASSERT_EQ(func(small_string, nullptr, base), ReturnT(0));
-                  ASSERT_EQ(errno, 0);
+                  ASSERT_EQ(libc_errno, 0);
                 }
               } else {
-                errno = 0;
+                libc_errno = 0;
                 ASSERT_EQ(func(small_string, nullptr, base),
                           static_cast<ReturnT>(first_digit));
-                ASSERT_EQ(errno, 0);
+                ASSERT_EQ(libc_errno, 0);
               }
             } else {
-              errno = 0;
+              libc_errno = 0;
               ASSERT_EQ(func(small_string, nullptr, base), ReturnT(0));
-              ASSERT_EQ(errno, 0);
+              ASSERT_EQ(libc_errno, 0);
             }
           }
         }
@@ -297,21 +297,21 @@ struct StrtoTest : public __llvm_libc::testing::Test {
     char *str_end = nullptr;
 
     const char *no_prefix = "123abc";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(no_prefix, &str_end, 16), ReturnT(0x123abc));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - no_prefix, ptrdiff_t(6));
 
     const char *yes_prefix = "0x456def";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(yes_prefix, &str_end, 16), ReturnT(0x456def));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - yes_prefix, ptrdiff_t(8));
 
     const char *letter_after_prefix = "0xabc123";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(letter_after_prefix, &str_end, 16), ReturnT(0xabc123));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - letter_after_prefix, ptrdiff_t(8));
   }
 
@@ -319,25 +319,25 @@ struct StrtoTest : public __llvm_libc::testing::Test {
     char *str_end = nullptr;
 
     const char *just_prefix = "0x";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(just_prefix, &str_end, 16), ReturnT(0));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - just_prefix, ptrdiff_t(1));
 
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(just_prefix, &str_end, 0), ReturnT(0));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - just_prefix, ptrdiff_t(1));
 
     const char *prefix_with_x_after = "0xx";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(prefix_with_x_after, &str_end, 16), ReturnT(0));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - prefix_with_x_after, ptrdiff_t(1));
 
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(prefix_with_x_after, &str_end, 0), ReturnT(0));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - prefix_with_x_after, ptrdiff_t(1));
   }
 
@@ -345,45 +345,45 @@ struct StrtoTest : public __llvm_libc::testing::Test {
     char *str_end = nullptr;
 
     const char *base_ten = "12345";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(base_ten, &str_end, 0), ReturnT(12345));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - base_ten, ptrdiff_t(5));
 
     const char *base_sixteen_no_prefix = "123abc";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(base_sixteen_no_prefix, &str_end, 0), ReturnT(123));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - base_sixteen_no_prefix, ptrdiff_t(3));
 
     const char *base_sixteen_with_prefix = "0x456def";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(base_sixteen_with_prefix, &str_end, 0), ReturnT(0x456def));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - base_sixteen_with_prefix, ptrdiff_t(8));
 
     const char *base_eight_with_prefix = "012345";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(base_eight_with_prefix, &str_end, 0), ReturnT(012345));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - base_eight_with_prefix, ptrdiff_t(6));
 
     const char *just_zero = "0";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(just_zero, &str_end, 0), ReturnT(0));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - just_zero, ptrdiff_t(1));
 
     const char *just_zero_x = "0x";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(just_zero_x, &str_end, 0), ReturnT(0));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - just_zero_x, ptrdiff_t(1));
 
     const char *just_zero_eight = "08";
-    errno = 0;
+    libc_errno = 0;
     ASSERT_EQ(func(just_zero_eight, &str_end, 0), ReturnT(0));
-    ASSERT_EQ(errno, 0);
+    ASSERT_EQ(libc_errno, 0);
     EXPECT_EQ(str_end - just_zero_eight, ptrdiff_t(1));
   }
 };
index 3ca2797..92d28b3 100644 (file)
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/FPUtil/FPBits.h"
+#include "src/errno/libc_errno.h"
 #include "src/stdlib/atof.h"
 
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
 #include <limits.h>
 #include <stddef.h>
 
@@ -21,7 +21,7 @@ TEST(LlvmLibcAToFTest, SimpleTest) {
   __llvm_libc::fputil::FPBits<double> expected_fp =
       __llvm_libc::fputil::FPBits<double>(uint64_t(0x405ec00000000000));
 
-  errno = 0;
+  libc_errno = 0;
   double result = __llvm_libc::atof("123");
 
   __llvm_libc::fputil::FPBits<double> actual_fp =
@@ -31,14 +31,14 @@ TEST(LlvmLibcAToFTest, SimpleTest) {
   EXPECT_EQ(actual_fp.get_sign(), expected_fp.get_sign());
   EXPECT_EQ(actual_fp.get_exponent(), expected_fp.get_exponent());
   EXPECT_EQ(actual_fp.get_mantissa(), expected_fp.get_mantissa());
-  EXPECT_EQ(errno, 0);
+  EXPECT_EQ(libc_errno, 0);
 }
 
 TEST(LlvmLibcAToFTest, FailedParsingTest) {
   __llvm_libc::fputil::FPBits<double> expected_fp =
       __llvm_libc::fputil::FPBits<double>(uint64_t(0));
 
-  errno = 0;
+  libc_errno = 0;
   double result = __llvm_libc::atof("???");
 
   __llvm_libc::fputil::FPBits<double> actual_fp =
@@ -48,5 +48,5 @@ TEST(LlvmLibcAToFTest, FailedParsingTest) {
   EXPECT_EQ(actual_fp.get_sign(), expected_fp.get_sign());
   EXPECT_EQ(actual_fp.get_exponent(), expected_fp.get_exponent());
   EXPECT_EQ(actual_fp.get_mantissa(), expected_fp.get_mantissa());
-  EXPECT_EQ(errno, 0);
+  EXPECT_EQ(libc_errno, 0);
 }
index 44f8dca..3160ef3 100644 (file)
@@ -7,12 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/FPUtil/FPBits.h"
+#include "src/errno/libc_errno.h"
 #include "src/stdlib/strtod.h"
 
 #include "test/UnitTest/Test.h"
 #include "utils/testutils/RoundingModeUtils.h"
 
-#include <errno.h>
 #include <limits.h>
 #include <stddef.h>
 
@@ -43,7 +43,7 @@ public:
     __llvm_libc::fputil::FPBits<double> expected_fp =
         __llvm_libc::fputil::FPBits<double>(expectedRawData);
 
-    errno = 0;
+    libc_errno = 0;
     double result = __llvm_libc::strtod(inputString, &str_end);
 
     __llvm_libc::fputil::FPBits<double> actual_fp =
@@ -55,7 +55,7 @@ public:
     EXPECT_EQ(actual_fp.get_sign(), expected_fp.get_sign());
     EXPECT_EQ(actual_fp.get_exponent(), expected_fp.get_exponent());
     EXPECT_EQ(actual_fp.get_mantissa(), expected_fp.get_mantissa());
-    EXPECT_EQ(errno, expectedErrno);
+    EXPECT_EQ(libc_errno, expectedErrno);
   }
 };
 
index 4fed552..6897df4 100644 (file)
@@ -7,12 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/FPUtil/FPBits.h"
+#include "src/errno/libc_errno.h"
 #include "src/stdlib/strtof.h"
 
 #include "test/UnitTest/Test.h"
 #include "utils/testutils/RoundingModeUtils.h"
 
-#include <errno.h>
 #include <limits.h>
 #include <stddef.h>
 
@@ -43,7 +43,7 @@ public:
     __llvm_libc::fputil::FPBits<float> expected_fp =
         __llvm_libc::fputil::FPBits<float>(expectedRawData);
 
-    errno = 0;
+    libc_errno = 0;
     float result = __llvm_libc::strtof(inputString, &str_end);
 
     __llvm_libc::fputil::FPBits<float> actual_fp =
@@ -55,7 +55,7 @@ public:
     EXPECT_EQ(actual_fp.get_sign(), expected_fp.get_sign());
     EXPECT_EQ(actual_fp.get_exponent(), expected_fp.get_exponent());
     EXPECT_EQ(actual_fp.get_mantissa(), expected_fp.get_mantissa());
-    EXPECT_EQ(errno, expectedErrno);
+    EXPECT_EQ(libc_errno, expectedErrno);
   }
 };
 
index 75eb29e..8db4b4e 100644 (file)
@@ -8,11 +8,11 @@
 
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/UInt128.h"
+#include "src/errno/libc_errno.h"
 #include "src/stdlib/strtold.h"
 
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
 #include <limits.h>
 #include <stddef.h>
 
@@ -78,7 +78,7 @@ public:
         __llvm_libc::fputil::FPBits<long double>(expectedRawData);
     const int expected_errno = expectedErrno;
 
-    errno = 0;
+    libc_errno = 0;
     long double result = __llvm_libc::strtold(inputString, &str_end);
 
     __llvm_libc::fputil::FPBits<long double> actual_fp =
@@ -91,7 +91,7 @@ public:
     EXPECT_EQ(actual_fp.get_sign(), expected_fp.get_sign());
     EXPECT_EQ(actual_fp.get_exponent(), expected_fp.get_exponent());
     EXPECT_EQ(actual_fp.get_mantissa(), expected_fp.get_mantissa());
-    EXPECT_EQ(errno, expected_errno);
+    EXPECT_EQ(libc_errno, expected_errno);
   }
 };
 
index b89fe4c..0a14003 100644 (file)
@@ -288,6 +288,7 @@ libc_support_library(
         ":__support_cpp_limits",
         ":__support_ctype_utils",
         ":__support_str_to_num_result",
+        ":errno",
     ],
 )
 
@@ -309,6 +310,7 @@ libc_support_library(
         ":__support_str_to_integer",
         ":__support_str_to_num_result",
         ":__support_uint128",
+        ":errno",
     ],
 )
 
@@ -1331,6 +1333,7 @@ libc_function(
     deps = [
         ":__support_common",
         ":__support_str_to_integer",
+        ":errno",
     ],
 )
 
@@ -1341,6 +1344,7 @@ libc_function(
     deps = [
         ":__support_common",
         ":__support_str_to_integer",
+        ":errno",
     ],
 )
 
@@ -1351,6 +1355,7 @@ libc_function(
     deps = [
         ":__support_common",
         ":__support_str_to_integer",
+        ":errno",
     ],
 )
 
@@ -1361,6 +1366,7 @@ libc_function(
     deps = [
         ":__support_common",
         ":__support_str_to_float",
+        ":errno",
     ],
 )
 
@@ -1389,6 +1395,7 @@ libc_function(
     deps = [
         ":__support_common",
         ":__support_str_to_integer",
+        ":errno",
     ],
 )
 
@@ -1399,6 +1406,7 @@ libc_function(
     deps = [
         ":__support_common",
         ":__support_str_to_integer",
+        ":errno",
     ],
 )
 
@@ -1409,6 +1417,7 @@ libc_function(
     deps = [
         ":__support_common",
         ":__support_str_to_integer",
+        ":errno",
     ],
 )
 
@@ -1419,6 +1428,7 @@ libc_function(
     deps = [
         ":__support_common",
         ":__support_str_to_integer",
+        ":errno",
     ],
 )
 
@@ -1429,6 +1439,7 @@ libc_function(
     deps = [
         ":__support_common",
         ":__support_str_to_float",
+        ":errno",
     ],
 )
 
@@ -1439,6 +1450,7 @@ libc_function(
     deps = [
         ":__support_common",
         ":__support_str_to_float",
+        ":errno",
     ],
 )
 
@@ -1449,6 +1461,7 @@ libc_function(
     deps = [
         ":__support_common",
         ":__support_str_to_float",
+        ":errno",
     ],
 )