From 12452976bd1f65240bcf19935e535a4c7cd773fb Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Sat, 17 Jun 2023 16:03:16 -0700 Subject: [PATCH] Remove getopt_long() from headers We removed this API a long time ago and it was breaking the GNU make open source build. --- libc/calls/fchdir.c | 8 ++++++-- libc/calls/groups.internal.h | 1 - libc/calls/tcgetpgrp.c | 3 +++ libc/str/strpbrk.c | 2 +- third_party/getopt/getopt.h | 16 ---------------- third_party/make/README.cosmo | 1 + third_party/make/getopt.h | 3 --- tool/emacs/cosmo-c-builtins.el | 1 + 8 files changed, 12 insertions(+), 23 deletions(-) diff --git a/libc/calls/fchdir.c b/libc/calls/fchdir.c index 83f7ad7d2..e5405f37a 100644 --- a/libc/calls/fchdir.c +++ b/libc/calls/fchdir.c @@ -20,6 +20,7 @@ #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" +#include "libc/intrin/strace.internal.h" /** * Sets current directory based on file descriptor. @@ -30,9 +31,12 @@ * @asyncsignalsafe */ int fchdir(int dirfd) { + int rc; if (!IsWindows()) { - return sys_fchdir(dirfd); + rc = sys_fchdir(dirfd); } else { - return sys_fchdir_nt(dirfd); + rc = sys_fchdir_nt(dirfd); } + STRACE("fchdir(%d) → %d% m", dirfd, rc); + return rc; } diff --git a/libc/calls/groups.internal.h b/libc/calls/groups.internal.h index 1c2750e0c..fb91680bc 100644 --- a/libc/calls/groups.internal.h +++ b/libc/calls/groups.internal.h @@ -1,6 +1,5 @@ #ifndef COSMOPOLITAN_LIBC_CALLS_GROUPS_INTERNAL_H_ #define COSMOPOLITAN_LIBC_CALLS_GROUPS_INTERNAL_H_ - #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ diff --git a/libc/calls/tcgetpgrp.c b/libc/calls/tcgetpgrp.c index 4107f149f..4e7596359 100644 --- a/libc/calls/tcgetpgrp.c +++ b/libc/calls/tcgetpgrp.c @@ -16,6 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/calls.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/termios.h" #include "libc/dce.h" @@ -41,6 +42,8 @@ int tcgetpgrp(int fd) { rc = sys_ioctl(fd, TIOCGPGRP_linux, &pgrp); } else if (IsBsd()) { rc = sys_ioctl(fd, TIOCGPGRP_bsd, &pgrp); + } else if (IsWindows()) { + rc = getpid(); } else { rc = enosys(); } diff --git a/libc/str/strpbrk.c b/libc/str/strpbrk.c index c5de42ea1..5d7e5e8a0 100644 --- a/libc/str/strpbrk.c +++ b/libc/str/strpbrk.c @@ -28,7 +28,7 @@ char *strpbrk(const char *s, const char *accept) { if (!accept[1]) { return strchr(s, accept[0]); } else { - memset(lut, 0, sizeof(lut)); + bzero(lut, sizeof(lut)); while (*accept) { lut[*accept++ & 255] = true; } diff --git a/third_party/getopt/getopt.h b/third_party/getopt/getopt.h index f69aedeb4..72139ce34 100644 --- a/third_party/getopt/getopt.h +++ b/third_party/getopt/getopt.h @@ -1,10 +1,5 @@ #ifndef COSMOPOLITAN_THIRD_PARTY_GETOPT_GETOPT_H_ #define COSMOPOLITAN_THIRD_PARTY_GETOPT_GETOPT_H_ - -#define no_argument 0 -#define required_argument 1 -#define optional_argument 2 - #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -14,17 +9,6 @@ extern int optind, opterr, optopt, optreset; int getopt(int, char *const[], const char *) paramsnonnull(); int getsubopt(char **, char *const *, char **) paramsnonnull(); -struct option { - const char *name; - int has_arg; - int *flag; - int val; -}; - -int getopt_long(int, char *const *, const char *, const struct option *, int *); -int getopt_long_only(int, char *const *, const char *, const struct option *, - int *); - COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_THIRD_PARTY_GETOPT_GETOPT_H_ */ diff --git a/third_party/make/README.cosmo b/third_party/make/README.cosmo index 520f21dfc..20283f965 100644 --- a/third_party/make/README.cosmo +++ b/third_party/make/README.cosmo @@ -15,6 +15,7 @@ LICENSE LOCAL CHANGES + - Introduce $(uniq token...) native function - .INTERNET variable to allow internet access - .PLEDGE variable which restricts system calls - .UNVEIL variable which controls Landlock LSM diff --git a/third_party/make/getopt.h b/third_party/make/getopt.h index c78b1f3fd..6fda5391d 100644 --- a/third_party/make/getopt.h +++ b/third_party/make/getopt.h @@ -16,11 +16,9 @@ A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "third_party/getopt/getopt.h" /* clang-format off */ #ifndef _GETOPT_H -#if 0 && !defined(_GETOPT_H) #define _GETOPT_H 1 #ifdef __cplusplus @@ -136,6 +134,5 @@ extern int _getopt_internal (int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *longind, int long_only); -#endif #endif /* getopt.h */ diff --git a/tool/emacs/cosmo-c-builtins.el b/tool/emacs/cosmo-c-builtins.el index 6c99a41c5..7612015cb 100644 --- a/tool/emacs/cosmo-c-builtins.el +++ b/tool/emacs/cosmo-c-builtins.el @@ -69,6 +69,7 @@ "__builtin_ctzll" "__builtin_expect" "__builtin_memcpy" + "__builtin_memset" "__builtin_expect_with_probability" "__builtin_extract_return_addr" "__builtin_isnan"