diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt --- a/libc/src/__support/CMakeLists.txt +++ b/libc/src/__support/CMakeLists.txt @@ -64,7 +64,6 @@ DEPENDS .ctype_utils .str_to_num_result - libc.include.errno libc.src.errno.errno libc.src.__support.CPP.limits libc.src.__support.common diff --git a/libc/src/__support/File/CMakeLists.txt b/libc/src/__support/File/CMakeLists.txt --- a/libc/src/__support/File/CMakeLists.txt +++ b/libc/src/__support/File/CMakeLists.txt @@ -11,7 +11,7 @@ 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 @@ ${LIBC_TARGET_OS}_file.cpp DEPENDS .file - libc.include.errno + libc.include.fcntl libc.include.stdio libc.include.sys_syscall @@ -55,10 +55,10 @@ ${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() diff --git a/libc/src/__support/File/dir.cpp b/libc/src/__support/File/dir.cpp --- a/libc/src/__support/File/dir.cpp +++ b/libc/src/__support/File/dir.cpp @@ -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 #include namespace __llvm_libc { diff --git a/libc/src/__support/File/file.cpp b/libc/src/__support/File/file.cpp --- a/libc/src/__support/File/file.cpp +++ b/libc/src/__support/File/file.cpp @@ -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 // For error macros #include #include diff --git a/libc/src/__support/File/linux_file.cpp b/libc/src/__support/File/linux_file.cpp --- a/libc/src/__support/File/linux_file.cpp +++ b/libc/src/__support/File/linux_file.cpp @@ -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 // For error macros #include // For mode_t and other flags to the open syscall #include #include // For syscall numbers diff --git a/libc/src/__support/StringUtil/CMakeLists.txt b/libc/src/__support/StringUtil/CMakeLists.txt --- a/libc/src/__support/StringUtil/CMakeLists.txt +++ b/libc/src/__support/StringUtil/CMakeLists.txt @@ -15,7 +15,7 @@ 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 diff --git a/libc/src/__support/StringUtil/error_to_string.cpp b/libc/src/__support/StringUtil/error_to_string.cpp --- a/libc/src/__support/StringUtil/error_to_string.cpp +++ b/libc/src/__support/StringUtil/error_to_string.cpp @@ -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 #include namespace __llvm_libc { diff --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h --- a/libc/src/__support/str_to_float.h +++ b/libc/src/__support/str_to_float.h @@ -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 +#include "src/errno/libc_errno.h" // For ERANGE namespace __llvm_libc { namespace internal { diff --git a/libc/src/__support/str_to_integer.h b/libc/src/__support/str_to_integer.h --- a/libc/src/__support/str_to_integer.h +++ b/libc/src/__support/str_to_integer.h @@ -13,7 +13,7 @@ #include "src/__support/common.h" #include "src/__support/ctype_utils.h" #include "src/__support/str_to_num_result.h" -#include +#include "src/errno/libc_errno.h" // For ERANGE #include namespace __llvm_libc { diff --git a/libc/src/__support/threads/linux/CMakeLists.txt b/libc/src/__support/threads/linux/CMakeLists.txt --- a/libc/src/__support/threads/linux/CMakeLists.txt +++ b/libc/src/__support/threads/linux/CMakeLists.txt @@ -28,6 +28,7 @@ .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 diff --git a/libc/src/__support/threads/linux/thread.cpp b/libc/src/__support/threads/linux/thread.cpp --- a/libc/src/__support/threads/linux/thread.cpp +++ b/libc/src/__support/threads/linux/thread.cpp @@ -15,12 +15,12 @@ #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 #endif -#include #include #include #include // For PR_SET_NAME diff --git a/libc/src/stdio/CMakeLists.txt b/libc/src/stdio/CMakeLists.txt --- a/libc/src/stdio/CMakeLists.txt +++ b/libc/src/stdio/CMakeLists.txt @@ -25,7 +25,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 diff --git a/libc/src/stdio/fclose.cpp b/libc/src/stdio/fclose.cpp --- a/libc/src/stdio/fclose.cpp +++ b/libc/src/stdio/fclose.cpp @@ -9,7 +9,7 @@ #include "src/stdio/fclose.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -18,7 +18,7 @@ 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; diff --git a/libc/src/stdio/fflush.cpp b/libc/src/stdio/fflush.cpp --- a/libc/src/stdio/fflush.cpp +++ b/libc/src/stdio/fflush.cpp @@ -9,7 +9,7 @@ #include "src/stdio/fflush.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -17,7 +17,7 @@ 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; diff --git a/libc/src/stdio/fgetc.cpp b/libc/src/stdio/fgetc.cpp --- a/libc/src/stdio/fgetc.cpp +++ b/libc/src/stdio/fgetc.cpp @@ -9,7 +9,7 @@ #include "src/stdio/fgetc.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -19,7 +19,7 @@ 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; diff --git a/libc/src/stdio/fgetc_unlocked.cpp b/libc/src/stdio/fgetc_unlocked.cpp --- a/libc/src/stdio/fgetc_unlocked.cpp +++ b/libc/src/stdio/fgetc_unlocked.cpp @@ -9,7 +9,7 @@ #include "src/stdio/fgetc_unlocked.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -20,7 +20,7 @@ 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; diff --git a/libc/src/stdio/fgets.cpp b/libc/src/stdio/fgets.cpp --- a/libc/src/stdio/fgets.cpp +++ b/libc/src/stdio/fgets.cpp @@ -9,7 +9,7 @@ #include "src/stdio/fgets.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include #include @@ -32,7 +32,7 @@ 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; diff --git a/libc/src/stdio/fopen.cpp b/libc/src/stdio/fopen.cpp --- a/libc/src/stdio/fopen.cpp +++ b/libc/src/stdio/fopen.cpp @@ -9,7 +9,7 @@ #include "src/stdio/fopen.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -18,7 +18,7 @@ (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()); diff --git a/libc/src/stdio/fopencookie.cpp b/libc/src/stdio/fopencookie.cpp --- a/libc/src/stdio/fopencookie.cpp +++ b/libc/src/stdio/fopencookie.cpp @@ -10,7 +10,7 @@ #include "src/__support/CPP/new.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include #include diff --git a/libc/src/stdio/fputc.cpp b/libc/src/stdio/fputc.cpp --- a/libc/src/stdio/fputc.cpp +++ b/libc/src/stdio/fputc.cpp @@ -9,7 +9,7 @@ #include "src/stdio/fputc.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -19,7 +19,7 @@ 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) { diff --git a/libc/src/stdio/fputs.cpp b/libc/src/stdio/fputs.cpp --- a/libc/src/stdio/fputs.cpp +++ b/libc/src/stdio/fputs.cpp @@ -10,7 +10,7 @@ #include "src/__support/CPP/string_view.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -22,7 +22,7 @@ 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) { diff --git a/libc/src/stdio/fread.cpp b/libc/src/stdio/fread.cpp --- a/libc/src/stdio/fread.cpp +++ b/libc/src/stdio/fread.cpp @@ -9,7 +9,7 @@ #include "src/stdio/fread.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -22,7 +22,7 @@ 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; } diff --git a/libc/src/stdio/fread_unlocked.cpp b/libc/src/stdio/fread_unlocked.cpp --- a/libc/src/stdio/fread_unlocked.cpp +++ b/libc/src/stdio/fread_unlocked.cpp @@ -9,7 +9,7 @@ #include "src/stdio/fread_unlocked.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -22,7 +22,7 @@ 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; } diff --git a/libc/src/stdio/fseek.cpp b/libc/src/stdio/fseek.cpp --- a/libc/src/stdio/fseek.cpp +++ b/libc/src/stdio/fseek.cpp @@ -9,7 +9,7 @@ #include "src/stdio/fseek.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -18,7 +18,7 @@ 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; diff --git a/libc/src/stdio/ftell.cpp b/libc/src/stdio/ftell.cpp --- a/libc/src/stdio/ftell.cpp +++ b/libc/src/stdio/ftell.cpp @@ -9,7 +9,7 @@ #include "src/stdio/ftell.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -17,7 +17,7 @@ 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(); diff --git a/libc/src/stdio/fwrite.cpp b/libc/src/stdio/fwrite.cpp --- a/libc/src/stdio/fwrite.cpp +++ b/libc/src/stdio/fwrite.cpp @@ -9,7 +9,7 @@ #include "src/stdio/fwrite.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -22,7 +22,7 @@ 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; } diff --git a/libc/src/stdio/fwrite_unlocked.cpp b/libc/src/stdio/fwrite_unlocked.cpp --- a/libc/src/stdio/fwrite_unlocked.cpp +++ b/libc/src/stdio/fwrite_unlocked.cpp @@ -9,7 +9,7 @@ #include "src/stdio/fwrite_unlocked.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -23,7 +23,7 @@ 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; } diff --git a/libc/src/stdio/getc.cpp b/libc/src/stdio/getc.cpp --- a/libc/src/stdio/getc.cpp +++ b/libc/src/stdio/getc.cpp @@ -9,7 +9,7 @@ #include "src/stdio/getc.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -19,7 +19,7 @@ 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; diff --git a/libc/src/stdio/getc_unlocked.cpp b/libc/src/stdio/getc_unlocked.cpp --- a/libc/src/stdio/getc_unlocked.cpp +++ b/libc/src/stdio/getc_unlocked.cpp @@ -9,7 +9,7 @@ #include "src/stdio/getc_unlocked.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -20,7 +20,7 @@ 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; diff --git a/libc/src/stdio/linux/remove.cpp b/libc/src/stdio/linux/remove.cpp --- a/libc/src/stdio/linux/remove.cpp +++ b/libc/src/stdio/linux/remove.cpp @@ -11,7 +11,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include +#include "src/errno/libc_errno.h" #include // For AT_* macros. #include // For syscall numbers. @@ -25,7 +25,7 @@ ret = __llvm_libc::syscall_impl(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); if (ret >= 0) return 0; - errno = -ret; + libc_errno = -ret; return -1; } diff --git a/libc/src/stdio/putc.cpp b/libc/src/stdio/putc.cpp --- a/libc/src/stdio/putc.cpp +++ b/libc/src/stdio/putc.cpp @@ -9,7 +9,7 @@ #include "src/stdio/putc.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -19,7 +19,7 @@ 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) { diff --git a/libc/src/stdio/putchar.cpp b/libc/src/stdio/putchar.cpp --- a/libc/src/stdio/putchar.cpp +++ b/libc/src/stdio/putchar.cpp @@ -9,7 +9,7 @@ #include "src/stdio/putchar.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -19,7 +19,7 @@ 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) { diff --git a/libc/src/stdio/puts.cpp b/libc/src/stdio/puts.cpp --- a/libc/src/stdio/puts.cpp +++ b/libc/src/stdio/puts.cpp @@ -10,7 +10,7 @@ #include "src/__support/CPP/string_view.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -19,7 +19,7 @@ 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 @@ } 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. diff --git a/libc/src/stdio/setbuf.cpp b/libc/src/stdio/setbuf.cpp --- a/libc/src/stdio/setbuf.cpp +++ b/libc/src/stdio/setbuf.cpp @@ -9,7 +9,7 @@ #include "src/stdio/setbuf.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -22,7 +22,7 @@ int err = reinterpret_cast<__llvm_libc::File *>(stream)->set_buffer( buf, BUFSIZ, mode); if (err != 0) - errno = err; + libc_errno = err; } } // namespace __llvm_libc diff --git a/libc/src/stdio/setvbuf.cpp b/libc/src/stdio/setvbuf.cpp --- a/libc/src/stdio/setvbuf.cpp +++ b/libc/src/stdio/setvbuf.cpp @@ -9,7 +9,7 @@ #include "src/stdio/setvbuf.h" #include "src/__support/File/file.h" -#include +#include "src/errno/libc_errno.h" #include namespace __llvm_libc { @@ -20,7 +20,7 @@ int err = reinterpret_cast<__llvm_libc::File *>(stream)->set_buffer(buf, size, type); if (err != 0) - errno = err; + libc_errno = err; return err; } diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt --- a/libc/src/stdlib/CMakeLists.txt +++ b/libc/src/stdlib/CMakeLists.txt @@ -5,6 +5,7 @@ HDRS atoi.h DEPENDS + libc.src.errno.errno libc.src.__support.str_to_integer ) @@ -15,6 +16,7 @@ HDRS atof.h DEPENDS + libc.src.errno.errno libc.src.__support.str_to_float ) @@ -25,6 +27,7 @@ HDRS atol.h DEPENDS + libc.src.errno.errno libc.src.__support.str_to_integer ) @@ -35,6 +38,7 @@ HDRS atoll.h DEPENDS + libc.src.errno.errno libc.src.__support.str_to_integer ) @@ -55,6 +59,7 @@ HDRS strtof.h DEPENDS + libc.src.errno.errno libc.src.__support.str_to_float ) @@ -65,6 +70,7 @@ HDRS strtod.h DEPENDS + libc.src.errno.errno libc.src.__support.str_to_float ) @@ -75,6 +81,7 @@ HDRS strtold.h DEPENDS + libc.src.errno.errno libc.src.__support.str_to_float ) @@ -85,6 +92,7 @@ HDRS strtol.h DEPENDS + libc.src.errno.errno libc.src.__support.str_to_integer ) @@ -95,6 +103,7 @@ HDRS strtoll.h DEPENDS + libc.src.errno.errno libc.src.__support.str_to_integer ) @@ -105,6 +114,7 @@ HDRS strtoul.h DEPENDS + libc.src.errno.errno libc.src.__support.str_to_integer ) @@ -115,6 +125,7 @@ HDRS strtoull.h DEPENDS + libc.src.errno.errno libc.src.__support.str_to_integer ) diff --git a/libc/src/stdlib/atof.cpp b/libc/src/stdlib/atof.cpp --- a/libc/src/stdlib/atof.cpp +++ b/libc/src/stdlib/atof.cpp @@ -9,14 +9,14 @@ #include "src/stdlib/atof.h" #include "src/__support/common.h" #include "src/__support/str_to_float.h" -#include +#include "src/errno/libc_errno.h" namespace __llvm_libc { LLVM_LIBC_FUNCTION(double, atof, (const char *str)) { auto result = internal::strtofloatingpoint(str); if (result.has_error()) - errno = result.error; + libc_errno = result.error; return result.value; } diff --git a/libc/src/stdlib/atoi.cpp b/libc/src/stdlib/atoi.cpp --- a/libc/src/stdlib/atoi.cpp +++ b/libc/src/stdlib/atoi.cpp @@ -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 @@ // (int)(strtol). auto result = internal::strtointeger(str, 10); if (result.has_error()) - errno = result.error; + libc_errno = result.error; return static_cast(result); } diff --git a/libc/src/stdlib/atol.cpp b/libc/src/stdlib/atol.cpp --- a/libc/src/stdlib/atol.cpp +++ b/libc/src/stdlib/atol.cpp @@ -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(str, 10); if (result.has_error()) - errno = result.error; + libc_errno = result.error; return result; } diff --git a/libc/src/stdlib/atoll.cpp b/libc/src/stdlib/atoll.cpp --- a/libc/src/stdlib/atoll.cpp +++ b/libc/src/stdlib/atoll.cpp @@ -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(str, 10); if (result.has_error()) - errno = result.error; + libc_errno = result.error; return result; } diff --git a/libc/src/stdlib/strtod.cpp b/libc/src/stdlib/strtod.cpp --- a/libc/src/stdlib/strtod.cpp +++ b/libc/src/stdlib/strtod.cpp @@ -9,7 +9,7 @@ #include "src/stdlib/strtod.h" #include "src/__support/common.h" #include "src/__support/str_to_float.h" -#include +#include "src/errno/libc_errno.h" namespace __llvm_libc { @@ -17,7 +17,7 @@ (const char *__restrict str, char **__restrict str_end)) { auto result = internal::strtofloatingpoint(str); if (result.has_error()) - errno = result.error; + libc_errno = result.error; if (str_end != NULL) *str_end = const_cast(str + result.parsed_len); diff --git a/libc/src/stdlib/strtof.cpp b/libc/src/stdlib/strtof.cpp --- a/libc/src/stdlib/strtof.cpp +++ b/libc/src/stdlib/strtof.cpp @@ -9,7 +9,7 @@ #include "src/stdlib/strtof.h" #include "src/__support/common.h" #include "src/__support/str_to_float.h" -#include +#include "src/errno/libc_errno.h" namespace __llvm_libc { @@ -17,7 +17,7 @@ (const char *__restrict str, char **__restrict str_end)) { auto result = internal::strtofloatingpoint(str); if (result.has_error()) - errno = result.error; + libc_errno = result.error; if (str_end != NULL) *str_end = const_cast(str + result.parsed_len); diff --git a/libc/src/stdlib/strtol.cpp b/libc/src/stdlib/strtol.cpp --- a/libc/src/stdlib/strtol.cpp +++ b/libc/src/stdlib/strtol.cpp @@ -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 @@ int base)) { auto result = internal::strtointeger(str, base); if (result.has_error()) - errno = result.error; + libc_errno = result.error; if (str_end != nullptr) *str_end = const_cast(str + result.parsed_len); diff --git a/libc/src/stdlib/strtold.cpp b/libc/src/stdlib/strtold.cpp --- a/libc/src/stdlib/strtold.cpp +++ b/libc/src/stdlib/strtold.cpp @@ -9,7 +9,7 @@ #include "src/stdlib/strtold.h" #include "src/__support/common.h" #include "src/__support/str_to_float.h" -#include +#include "src/errno/libc_errno.h" namespace __llvm_libc { @@ -17,7 +17,7 @@ (const char *__restrict str, char **__restrict str_end)) { auto result = internal::strtofloatingpoint(str); if (result.has_error()) - errno = result.error; + libc_errno = result.error; if (str_end != NULL) *str_end = const_cast(str + result.parsed_len); diff --git a/libc/src/stdlib/strtoll.cpp b/libc/src/stdlib/strtoll.cpp --- a/libc/src/stdlib/strtoll.cpp +++ b/libc/src/stdlib/strtoll.cpp @@ -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 @@ int base)) { auto result = internal::strtointeger(str, base); if (result.has_error()) - errno = result.error; + libc_errno = result.error; if (str_end != nullptr) *str_end = const_cast(str + result.parsed_len); diff --git a/libc/src/stdlib/strtoul.cpp b/libc/src/stdlib/strtoul.cpp --- a/libc/src/stdlib/strtoul.cpp +++ b/libc/src/stdlib/strtoul.cpp @@ -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 @@ int base)) { auto result = internal::strtointeger(str, base); if (result.has_error()) - errno = result.error; + libc_errno = result.error; if (str_end != nullptr) *str_end = const_cast(str + result.parsed_len); diff --git a/libc/src/stdlib/strtoull.cpp b/libc/src/stdlib/strtoull.cpp --- a/libc/src/stdlib/strtoull.cpp +++ b/libc/src/stdlib/strtoull.cpp @@ -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 @@ int base)) { auto result = internal::strtointeger(str, base); if (result.has_error()) - errno = result.error; + libc_errno = result.error; if (str_end != nullptr) *str_end = const_cast(str + result.parsed_len); diff --git a/libc/test/src/stdio/CMakeLists.txt b/libc/test/src/stdio/CMakeLists.txt --- a/libc/test/src/stdio/CMakeLists.txt +++ b/libc/test/src/stdio/CMakeLists.txt @@ -7,8 +7,8 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ SRCS ftell_test.cpp DEPENDS - libc.include.errno libc.include.stdio libc.src.stdio.fclose libc.src.stdio.fflush diff --git a/libc/test/src/stdio/fgetc_test.cpp b/libc/test/src/stdio/fgetc_test.cpp --- a/libc/test/src/stdio/fgetc_test.cpp +++ b/libc/test/src/stdio/fgetc_test.cpp @@ -16,7 +16,7 @@ #include "src/stdio/getc.h" #include "test/UnitTest/Test.h" -#include +#include "src/errno/libc_errno.h" #include class LlvmLibcGetcTest : public __llvm_libc::testing::Test { @@ -33,7 +33,7 @@ // 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)); diff --git a/libc/test/src/stdio/fgetc_unlocked_test.cpp b/libc/test/src/stdio/fgetc_unlocked_test.cpp --- a/libc/test/src/stdio/fgetc_unlocked_test.cpp +++ b/libc/test/src/stdio/fgetc_unlocked_test.cpp @@ -19,7 +19,7 @@ #include "src/stdio/getc_unlocked.h" #include "test/UnitTest/Test.h" -#include +#include "src/errno/libc_errno.h" #include class LlvmLibcGetcTest : public __llvm_libc::testing::Test { @@ -36,7 +36,7 @@ // 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)); diff --git a/libc/test/src/stdio/fgets_test.cpp b/libc/test/src/stdio/fgets_test.cpp --- a/libc/test/src/stdio/fgets_test.cpp +++ b/libc/test/src/stdio/fgets_test.cpp @@ -14,7 +14,7 @@ #include "src/stdio/fwrite.h" #include "test/UnitTest/Test.h" -#include +#include "src/errno/libc_errno.h" #include TEST(LlvmLibcFgetsTest, WriteAndReadCharacters) { @@ -36,7 +36,7 @@ // 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 @@ 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 @@ // 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)); } diff --git a/libc/test/src/stdio/fileop_test.cpp b/libc/test/src/stdio/fileop_test.cpp --- a/libc/test/src/stdio/fileop_test.cpp +++ b/libc/test/src/stdio/fileop_test.cpp @@ -18,7 +18,7 @@ #include "src/stdio/fwrite.h" #include "test/UnitTest/Test.h" -#include +#include "src/errno/libc_errno.h" #include TEST(LlvmLibcFILETest, SimpleFileOperations) { @@ -33,8 +33,8 @@ 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 @@ // 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 @@ 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 @@ 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(nullptr)); - // EXPECT_NE(errno, 0); + // EXPECT_NE(libc_errno, 0); } TEST(LlvmLibcFILETest, FFlush) { @@ -158,13 +158,13 @@ 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 @@ 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); diff --git a/libc/test/src/stdio/fopencookie_test.cpp b/libc/test/src/stdio/fopencookie_test.cpp --- a/libc/test/src/stdio/fopencookie_test.cpp +++ b/libc/test/src/stdio/fopencookie_test.cpp @@ -18,7 +18,7 @@ #include "test/UnitTest/MemoryMatcher.h" #include "test/UnitTest/Test.h" -#include +#include "src/errno/libc_errno.h" #include #include @@ -67,7 +67,7 @@ } 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 @@ // 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 @@ // 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 @@ // 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); diff --git a/libc/test/src/stdio/fprintf_test.cpp b/libc/test/src/stdio/fprintf_test.cpp --- a/libc/test/src/stdio/fprintf_test.cpp +++ b/libc/test/src/stdio/fprintf_test.cpp @@ -15,7 +15,6 @@ #include "test/UnitTest/Test.h" -#include #include TEST(LlvmLibcFPrintfTest, WriteToFile) { diff --git a/libc/test/src/stdio/fscanf_test.cpp b/libc/test/src/stdio/fscanf_test.cpp --- a/libc/test/src/stdio/fscanf_test.cpp +++ b/libc/test/src/stdio/fscanf_test.cpp @@ -16,7 +16,6 @@ #include "test/UnitTest/Test.h" -#include #include TEST(LlvmLibcFScanfTest, WriteToFile) { diff --git a/libc/test/src/stdio/ftell_test.cpp b/libc/test/src/stdio/ftell_test.cpp --- a/libc/test/src/stdio/ftell_test.cpp +++ b/libc/test/src/stdio/ftell_test.cpp @@ -16,7 +16,6 @@ #include "src/stdio/setvbuf.h" #include "test/UnitTest/Test.h" -#include #include class LlvmLibcFTellTest : public __llvm_libc::testing::Test { @@ -54,10 +53,6 @@ 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); } }; diff --git a/libc/test/src/stdio/putc_test.cpp b/libc/test/src/stdio/putc_test.cpp --- a/libc/test/src/stdio/putc_test.cpp +++ b/libc/test/src/stdio/putc_test.cpp @@ -15,7 +15,6 @@ #include "test/UnitTest/Test.h" -#include #include TEST(LlvmLibcPutcTest, WriteToFile) { diff --git a/libc/test/src/stdio/remove_test.cpp b/libc/test/src/stdio/remove_test.cpp --- a/libc/test/src/stdio/remove_test.cpp +++ b/libc/test/src/stdio/remove_test.cpp @@ -15,18 +15,18 @@ #include "test/UnitTest/Test.h" #include "utils/testutils/FDReader.h" -#include +#include "src/errno/libc_errno.h" #include 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, 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"; diff --git a/libc/test/src/stdio/setvbuf_test.cpp b/libc/test/src/stdio/setvbuf_test.cpp --- a/libc/test/src/stdio/setvbuf_test.cpp +++ b/libc/test/src/stdio/setvbuf_test.cpp @@ -13,7 +13,7 @@ #include "src/stdio/setvbuf.h" #include "test/UnitTest/Test.h" -#include +#include "src/errno/libc_errno.h" #include TEST(LlvmLibcSetvbufTest, SetNBFBuffer) { @@ -99,8 +99,8 @@ 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)); } diff --git a/libc/test/src/stdio/unlocked_fileop_test.cpp b/libc/test/src/stdio/unlocked_fileop_test.cpp --- a/libc/test/src/stdio/unlocked_fileop_test.cpp +++ b/libc/test/src/stdio/unlocked_fileop_test.cpp @@ -17,7 +17,7 @@ #include "src/stdio/fwrite_unlocked.h" #include "test/UnitTest/Test.h" -#include +#include "src/errno/libc_errno.h" #include TEST(LlvmLibcFILETest, UnlockedReadAndWrite) { @@ -36,8 +36,8 @@ 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 @@ 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); diff --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt --- a/libc/test/src/stdlib/CMakeLists.txt +++ b/libc/test/src/stdlib/CMakeLists.txt @@ -7,6 +7,7 @@ SRCS atof_test.cpp DEPENDS + libc.src.errno.errno libc.src.stdlib.atof ) @@ -15,6 +16,7 @@ HDRS AtoiTest.h DEPENDS + libc.src.errno.errno libc.src.__support.CPP.type_traits ) @@ -58,6 +60,7 @@ SRCS strtod_test.cpp DEPENDS + libc.src.errno.errno libc.src.stdlib.strtod ) @@ -68,6 +71,7 @@ SRCS strtof_test.cpp DEPENDS + libc.src.errno.errno libc.src.stdlib.strtof ) @@ -78,7 +82,6 @@ DEPENDS libc.src.__support.CPP.limits libc.src.__support.CPP.type_traits - libc.include.errno libc.src.errno.errno ) @@ -100,6 +103,7 @@ SRCS strtold_test.cpp DEPENDS + libc.src.errno.errno libc.src.__support.uint128 libc.src.stdlib.strtold ) diff --git a/libc/test/src/stdlib/StrtolTest.h b/libc/test/src/stdlib/StrtolTest.h --- a/libc/test/src/stdlib/StrtolTest.h +++ b/libc/test/src/stdlib/StrtolTest.h @@ -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 #include #include @@ -35,9 +35,9 @@ 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 @@ // 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 @@ // Note that 0 is not on that list. ASSERT_EQ(func(too_big_negative_number, &str_end, 10), (is_signed_v ? 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 @@ 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 @@ 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(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 @@ 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(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(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 @@ if (first_digit < base && second_digit < base && third_digit < base) { - errno = 0; + libc_errno = 0; ASSERT_EQ(func(small_string, nullptr, base), static_cast(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(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(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(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 @@ 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 @@ 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 @@ 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)); } }; diff --git a/libc/test/src/stdlib/atof_test.cpp b/libc/test/src/stdlib/atof_test.cpp --- a/libc/test/src/stdlib/atof_test.cpp +++ b/libc/test/src/stdlib/atof_test.cpp @@ -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 #include #include @@ -21,7 +21,7 @@ __llvm_libc::fputil::FPBits expected_fp = __llvm_libc::fputil::FPBits(uint64_t(0x405ec00000000000)); - errno = 0; + libc_errno = 0; double result = __llvm_libc::atof("123"); __llvm_libc::fputil::FPBits actual_fp = @@ -31,14 +31,14 @@ 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 expected_fp = __llvm_libc::fputil::FPBits(uint64_t(0)); - errno = 0; + libc_errno = 0; double result = __llvm_libc::atof("???"); __llvm_libc::fputil::FPBits actual_fp = @@ -48,5 +48,5 @@ 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); } diff --git a/libc/test/src/stdlib/strtod_test.cpp b/libc/test/src/stdlib/strtod_test.cpp --- a/libc/test/src/stdlib/strtod_test.cpp +++ b/libc/test/src/stdlib/strtod_test.cpp @@ -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 #include #include @@ -43,7 +43,7 @@ __llvm_libc::fputil::FPBits expected_fp = __llvm_libc::fputil::FPBits(expectedRawData); - errno = 0; + libc_errno = 0; double result = __llvm_libc::strtod(inputString, &str_end); __llvm_libc::fputil::FPBits actual_fp = @@ -55,7 +55,7 @@ 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); } }; diff --git a/libc/test/src/stdlib/strtof_test.cpp b/libc/test/src/stdlib/strtof_test.cpp --- a/libc/test/src/stdlib/strtof_test.cpp +++ b/libc/test/src/stdlib/strtof_test.cpp @@ -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 #include #include @@ -43,7 +43,7 @@ __llvm_libc::fputil::FPBits expected_fp = __llvm_libc::fputil::FPBits(expectedRawData); - errno = 0; + libc_errno = 0; float result = __llvm_libc::strtof(inputString, &str_end); __llvm_libc::fputil::FPBits actual_fp = @@ -55,7 +55,7 @@ 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); } }; diff --git a/libc/test/src/stdlib/strtold_test.cpp b/libc/test/src/stdlib/strtold_test.cpp --- a/libc/test/src/stdlib/strtold_test.cpp +++ b/libc/test/src/stdlib/strtold_test.cpp @@ -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 #include #include @@ -78,7 +78,7 @@ __llvm_libc::fputil::FPBits(expectedRawData); const int expected_errno = expectedErrno; - errno = 0; + libc_errno = 0; long double result = __llvm_libc::strtold(inputString, &str_end); __llvm_libc::fputil::FPBits actual_fp = @@ -91,7 +91,7 @@ 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); } }; diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -288,6 +288,7 @@ ":__support_cpp_limits", ":__support_ctype_utils", ":__support_str_to_num_result", + ":errno", ], ) @@ -309,6 +310,7 @@ ":__support_str_to_integer", ":__support_str_to_num_result", ":__support_uint128", + ":errno", ], ) @@ -1331,6 +1333,7 @@ deps = [ ":__support_common", ":__support_str_to_integer", + ":errno", ], ) @@ -1341,6 +1344,7 @@ deps = [ ":__support_common", ":__support_str_to_integer", + ":errno", ], ) @@ -1351,6 +1355,7 @@ deps = [ ":__support_common", ":__support_str_to_integer", + ":errno", ], ) @@ -1361,6 +1366,7 @@ deps = [ ":__support_common", ":__support_str_to_float", + ":errno", ], ) @@ -1389,6 +1395,7 @@ deps = [ ":__support_common", ":__support_str_to_integer", + ":errno", ], ) @@ -1399,6 +1406,7 @@ deps = [ ":__support_common", ":__support_str_to_integer", + ":errno", ], ) @@ -1409,6 +1417,7 @@ deps = [ ":__support_common", ":__support_str_to_integer", + ":errno", ], ) @@ -1419,6 +1428,7 @@ deps = [ ":__support_common", ":__support_str_to_integer", + ":errno", ], ) @@ -1429,6 +1439,7 @@ deps = [ ":__support_common", ":__support_str_to_float", + ":errno", ], ) @@ -1439,6 +1450,7 @@ deps = [ ":__support_common", ":__support_str_to_float", + ":errno", ], ) @@ -1449,6 +1461,7 @@ deps = [ ":__support_common", ":__support_str_to_float", + ":errno", ], )