From: Michael Jones Date: Thu, 2 Mar 2023 22:01:41 +0000 (-0800) Subject: [libc] move stdlib and stdio to new errno pattern X-Git-Tag: upstream/17.0.6~15899 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=04a9c62554cf74b06bd1f7af94eefd5a0a19590d;p=platform%2Fupstream%2Fllvm.git [libc] move stdlib and stdio to new errno pattern Fixes https://github.com/llvm/llvm-project/issues/61071 Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D145191 --- diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt index bafcd6e..8329a80 100644 --- a/libc/src/__support/CMakeLists.txt +++ b/libc/src/__support/CMakeLists.txt @@ -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 diff --git a/libc/src/__support/File/CMakeLists.txt b/libc/src/__support/File/CMakeLists.txt index dd9bbee..2d94c2f 100644 --- a/libc/src/__support/File/CMakeLists.txt +++ b/libc/src/__support/File/CMakeLists.txt @@ -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() diff --git a/libc/src/__support/File/dir.cpp b/libc/src/__support/File/dir.cpp index a473704..70f550f 100644 --- 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 index 53fa06b..6a80ce0 100644 --- 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 index be6c61b..658bffc 100644 --- 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 index 5c4c69f..e440792 100644 --- a/libc/src/__support/StringUtil/CMakeLists.txt +++ b/libc/src/__support/StringUtil/CMakeLists.txt @@ -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 diff --git a/libc/src/__support/StringUtil/error_to_string.cpp b/libc/src/__support/StringUtil/error_to_string.cpp index 98e2fbd..59e34c5 100644 --- 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 index df6ca4d..dc8c3cb 100644 --- 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 index 8e1ce11..39ed940 100644 --- 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 index 21b5dce..62351da 100644 --- a/libc/src/__support/threads/linux/CMakeLists.txt +++ b/libc/src/__support/threads/linux/CMakeLists.txt @@ -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 diff --git a/libc/src/__support/threads/linux/thread.cpp b/libc/src/__support/threads/linux/thread.cpp index 90198fb..f158f16e 100644 --- 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 index bb765ee..5f8d179 100644 --- a/libc/src/stdio/CMakeLists.txt +++ b/libc/src/stdio/CMakeLists.txt @@ -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 diff --git a/libc/src/stdio/fclose.cpp b/libc/src/stdio/fclose.cpp index b4a366a..1d53974 100644 --- 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 @@ 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; diff --git a/libc/src/stdio/fflush.cpp b/libc/src/stdio/fflush.cpp index 75cf4d3..d7a5652 100644 --- 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 @@ 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; diff --git a/libc/src/stdio/fgetc.cpp b/libc/src/stdio/fgetc.cpp index 33b27a2..9a61096 100644 --- 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 @@ 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; diff --git a/libc/src/stdio/fgetc_unlocked.cpp b/libc/src/stdio/fgetc_unlocked.cpp index abec1d9..032a9fb 100644 --- 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 @@ 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; diff --git a/libc/src/stdio/fgets.cpp b/libc/src/stdio/fgets.cpp index bb7c794..dd5051a 100644 --- 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 @@ 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; diff --git a/libc/src/stdio/fopen.cpp b/libc/src/stdio/fopen.cpp index f39b65e..3062a05 100644 --- 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 @@ 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()); diff --git a/libc/src/stdio/fopencookie.cpp b/libc/src/stdio/fopencookie.cpp index 2e3cce7..da72ed3 100644 --- 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 index 8287e4e..5f41e5c 100644 --- 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 @@ 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) { diff --git a/libc/src/stdio/fputs.cpp b/libc/src/stdio/fputs.cpp index 0b1a3e1..d8ba18f 100644 --- 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 @@ 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) { diff --git a/libc/src/stdio/fread.cpp b/libc/src/stdio/fread.cpp index 103d88c..affc6b7 100644 --- 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 @@ 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; } diff --git a/libc/src/stdio/fread_unlocked.cpp b/libc/src/stdio/fread_unlocked.cpp index 18e7160..3f922c5 100644 --- 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 @@ 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; } diff --git a/libc/src/stdio/fseek.cpp b/libc/src/stdio/fseek.cpp index 4a29c995..928ff84 100644 --- 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 @@ 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; diff --git a/libc/src/stdio/ftell.cpp b/libc/src/stdio/ftell.cpp index 2d11a42..697e9bc 100644 --- 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 @@ 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(); diff --git a/libc/src/stdio/fwrite.cpp b/libc/src/stdio/fwrite.cpp index 43f0201..cc6c450 100644 --- 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 @@ 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; } diff --git a/libc/src/stdio/fwrite_unlocked.cpp b/libc/src/stdio/fwrite_unlocked.cpp index 47fe075..736dfe0 100644 --- 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 @@ 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; } diff --git a/libc/src/stdio/getc.cpp b/libc/src/stdio/getc.cpp index a27f79f..730be68 100644 --- 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 @@ 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; diff --git a/libc/src/stdio/getc_unlocked.cpp b/libc/src/stdio/getc_unlocked.cpp index ecb3184..4eae5c1 100644 --- 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 @@ 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; diff --git a/libc/src/stdio/linux/remove.cpp b/libc/src/stdio/linux/remove.cpp index 2a868a7..0199644 100644 --- 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 @@ 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; } diff --git a/libc/src/stdio/putc.cpp b/libc/src/stdio/putc.cpp index 3016060..37937df 100644 --- 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 @@ 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) { diff --git a/libc/src/stdio/putchar.cpp b/libc/src/stdio/putchar.cpp index 2cf5d64..9190b71 100644 --- 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 @@ 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) { diff --git a/libc/src/stdio/puts.cpp b/libc/src/stdio/puts.cpp index 57e4919..ffcbf56 100644 --- 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 @@ 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. diff --git a/libc/src/stdio/setbuf.cpp b/libc/src/stdio/setbuf.cpp index b759632..cb30fe3 100644 --- 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 @@ 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 diff --git a/libc/src/stdio/setvbuf.cpp b/libc/src/stdio/setvbuf.cpp index 162519f..9080c55 100644 --- 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 @@ 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; } diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt index b067e84..a9de969 100644 --- a/libc/src/stdlib/CMakeLists.txt +++ b/libc/src/stdlib/CMakeLists.txt @@ -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 ) diff --git a/libc/src/stdlib/atof.cpp b/libc/src/stdlib/atof.cpp index 3066df0..2359ce7 100644 --- 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 index d9bc866..eec15aa 100644 --- 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 @@ LLVM_LIBC_FUNCTION(int, atoi, (const char *str)) { // (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 index d786845..78928e8 100644 --- 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 index cfa8edf..5047226 100644 --- 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 index 0690cfd..eb3f290 100644 --- 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 @@ LLVM_LIBC_FUNCTION(double, strtod, (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 index 41141c6..f4b90e8 100644 --- 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 @@ LLVM_LIBC_FUNCTION(float, strtof, (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 index 9564f5d..fb02353 100644 --- 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 @@ LLVM_LIBC_FUNCTION(long, strtol, 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 index bccb273..01cbb7f 100644 --- 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 @@ LLVM_LIBC_FUNCTION(long double, strtold, (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 index c1aa94e..f4f9754 100644 --- 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 @@ LLVM_LIBC_FUNCTION(long long, strtoll, 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 index d0accb54..c3b1b93 100644 --- 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 @@ LLVM_LIBC_FUNCTION(unsigned long, strtoul, 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 index 26f0821..9bf3d0b 100644 --- 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 @@ LLVM_LIBC_FUNCTION(unsigned long long, strtoull, 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 index e94432d..8747f18 100644 --- a/libc/test/src/stdio/CMakeLists.txt +++ b/libc/test/src/stdio/CMakeLists.txt @@ -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 diff --git a/libc/test/src/stdio/fgetc_test.cpp b/libc/test/src/stdio/fgetc_test.cpp index 464fd20..b262dda 100644 --- 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 @@ 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)); diff --git a/libc/test/src/stdio/fgetc_unlocked_test.cpp b/libc/test/src/stdio/fgetc_unlocked_test.cpp index d8e0cd1..4608be3ee 100644 --- 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 @@ 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)); diff --git a/libc/test/src/stdio/fgets_test.cpp b/libc/test/src/stdio/fgets_test.cpp index 1ef2415..150a9dd 100644 --- 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 @@ 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)); } diff --git a/libc/test/src/stdio/fileop_test.cpp b/libc/test/src/stdio/fileop_test.cpp index 6d068ad..989de29 100644 --- 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 @@ 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(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); diff --git a/libc/test/src/stdio/fopencookie_test.cpp b/libc/test/src/stdio/fopencookie_test.cpp index ff24b58..1397006 100644 --- 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 @@ 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); diff --git a/libc/test/src/stdio/fprintf_test.cpp b/libc/test/src/stdio/fprintf_test.cpp index 7b0b1ad..286c516 100644 --- 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 index f4f61a2..71402f0 100644 --- 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 index 5a74c44..e5e4cc4 100644 --- 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 @@ 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); } }; diff --git a/libc/test/src/stdio/putc_test.cpp b/libc/test/src/stdio/putc_test.cpp index 384526b..0bd3acc 100644 --- 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 index 4295046..b6e8b64 100644 --- 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, 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"; diff --git a/libc/test/src/stdio/setvbuf_test.cpp b/libc/test/src/stdio/setvbuf_test.cpp index f111fcc..6b44f6b 100644 --- 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 @@ 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)); } diff --git a/libc/test/src/stdio/unlocked_fileop_test.cpp b/libc/test/src/stdio/unlocked_fileop_test.cpp index 86a6354..67ce11e 100644 --- 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 @@ 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); diff --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt index 67e0e97..b1893bc 100644 --- a/libc/test/src/stdlib/CMakeLists.txt +++ b/libc/test/src/stdlib/CMakeLists.txt @@ -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 ) diff --git a/libc/test/src/stdlib/StrtolTest.h b/libc/test/src/stdlib/StrtolTest.h index f3d610e..09d8da1 100644 --- 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 @@ 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 ? 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(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(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 @@ 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(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 @@ 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)); } }; diff --git a/libc/test/src/stdlib/atof_test.cpp b/libc/test/src/stdlib/atof_test.cpp index 3ca2797..92d28b3 100644 --- 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 @@ TEST(LlvmLibcAToFTest, SimpleTest) { __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 @@ 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 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 @@ 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); } diff --git a/libc/test/src/stdlib/strtod_test.cpp b/libc/test/src/stdlib/strtod_test.cpp index 44f8dca..3160ef3 100644 --- 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 @@ public: __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 @@ 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); } }; diff --git a/libc/test/src/stdlib/strtof_test.cpp b/libc/test/src/stdlib/strtof_test.cpp index 4fed552..6897df4 100644 --- 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 @@ public: __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 @@ 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); } }; diff --git a/libc/test/src/stdlib/strtold_test.cpp b/libc/test/src/stdlib/strtold_test.cpp index 75eb29e..8db4b4e 100644 --- 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 @@ public: __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 @@ 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); } }; diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index b89fe4c..0a14003 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -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", ], )