From 74caabb823124db6f8e39949963391fe40c98b86 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Tue, 15 Aug 2023 19:24:21 -0700 Subject: [PATCH] Fix getopt again --- libc/calls/winstdin1.c | 20 ++++++++++++++++++++ libc/isystem/getopt.h | 1 + libc/runtime/winmain.greg.c | 20 -------------------- third_party/getopt/getopt.internal.h | 3 +-- third_party/getopt/long1.h | 6 +++--- third_party/getopt/long2.h | 6 +++--- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/libc/calls/winstdin1.c b/libc/calls/winstdin1.c index 3b1c17da6..bc8442b0a 100644 --- a/libc/calls/winstdin1.c +++ b/libc/calls/winstdin1.c @@ -31,6 +31,26 @@ #include "libc/nt/thread.h" #include "libc/nt/thunk/msabi.h" +/** + * @fileoverview makes windows stdin handle capable of being poll'd + * + * 1. On Windows, there's no way to check how many bytes of input are + * available from the cmd.exe console. The only thing you can do is a + * blocking read that can't be interrupted. + * + * 2. On Windows, it's up to the parent process whether or not the + * handles it passes us are capable of non-blocking overlapped i/o + * reads (which we need for busy polling to check for interrupts). + * + * So we solve this by creating a thread which just does naive reads on + * standard input, and then relays the data to the process via a named + * pipe, which we explicitly creaete with overlapped i/o enabled. + * + * This code runs very early during process initialization, at the + * beginning of WinMain(). This module is only activated if the app + * links any one of: poll(), select(), or ioctl(FIONREAD). + */ + __msabi extern typeof(CloseHandle) *const __imp_CloseHandle; __msabi extern typeof(CreateFile) *const __imp_CreateFileW; __msabi extern typeof(CreateNamedPipe) *const __imp_CreateNamedPipeW; diff --git a/libc/isystem/getopt.h b/libc/isystem/getopt.h index 26b86e5d1..992aa6c55 100644 --- a/libc/isystem/getopt.h +++ b/libc/isystem/getopt.h @@ -1,4 +1,5 @@ #ifndef _GETOPT_H #define _GETOPT_H +#include "third_party/getopt/long1.h" #include "third_party/getopt/long2.h" #endif /* _GETOPT_H */ diff --git a/libc/runtime/winmain.greg.c b/libc/runtime/winmain.greg.c index 8c5db241e..8a2ba78ae 100644 --- a/libc/runtime/winmain.greg.c +++ b/libc/runtime/winmain.greg.c @@ -58,26 +58,6 @@ #ifdef __x86_64__ -/** - * @fileoverview makes windows stdin handle capable of being poll'd - * - * 1. On Windows, there's no way to check how many bytes of input are - * available from the cmd.exe console. The only thing you can do is a - * blocking read that can't be interrupted. - * - * 2. On Windows, it's up to the parent process whether or not the - * handles it passes us are capable of non-blocking overlapped i/o - * reads (which we need for busy polling to check for interrupts). - * - * So we solve this by creating a thread which just does naive reads on - * standard input, and then relays the data to the process via a named - * pipe, which we explicitly creaete with overlapped i/o enabled. - * - * This code runs very early during process initialization, at the - * beginning of WinMain(). This module is only activated if the app - * links any one of: poll(), select(), or ioctl(FIONREAD). - */ - // clang-format off __msabi extern typeof(AddVectoredExceptionHandler) *const __imp_AddVectoredExceptionHandler; __msabi extern typeof(CloseHandle) *const __imp_CloseHandle; diff --git a/third_party/getopt/getopt.internal.h b/third_party/getopt/getopt.internal.h index d9829a572..1af7e09dd 100644 --- a/third_party/getopt/getopt.internal.h +++ b/third_party/getopt/getopt.internal.h @@ -1,7 +1,6 @@ #ifndef COSMOPOLITAN_GETOPT_H_ #define COSMOPOLITAN_GETOPT_H_ -#if defined(COSMOPOLITAN_GETOPT_LONG1_H_) || \ - defined(COSMOPOLITAN_GETOPT_LONG2_H_) +#if defined(_GETOPT_CORE_H) || defined(_GETOPT_EXT_H) #error "don't mix getopt_long() with cosmo's getopt()" #endif diff --git a/third_party/getopt/long1.h b/third_party/getopt/long1.h index 4a31585a1..9e8ebc8d0 100755 --- a/third_party/getopt/long1.h +++ b/third_party/getopt/long1.h @@ -1,5 +1,5 @@ -#ifndef COSMOPOLITAN_GETOPT_LONG1_H_ -#define COSMOPOLITAN_GETOPT_LONG1_H_ +#ifndef _GETOPT_CORE_H +#define _GETOPT_CORE_H #ifdef COSMOPOLITAN_GETOPT_H_ #error "don't mix getopt_long() with cosmo's getopt()" #endif @@ -13,4 +13,4 @@ int getopt(int, char *const *, const char *); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_GETOPT_LONG1_H_ */ +#endif /* _GETOPT_CORE_H */ diff --git a/third_party/getopt/long2.h b/third_party/getopt/long2.h index 21e934afa..5e7f6e8f2 100644 --- a/third_party/getopt/long2.h +++ b/third_party/getopt/long2.h @@ -1,5 +1,5 @@ -#ifndef COSMOPOLITAN_GETOPT_LONG2_H_ -#define COSMOPOLITAN_GETOPT_LONG2_H_ +#ifndef _GETOPT_EXT_H +#define _GETOPT_EXT_H #ifdef COSMOPOLITAN_GETOPT_H_ #error "don't mix getopt_long() with cosmo's getopt()" #endif @@ -24,4 +24,4 @@ int getopt_long_only(int, char *const *, const char *, const struct option *, COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_GETOPT_LONG2_H_ */ +#endif /* _GETOPT_EXT_H */