Skip to content

Commit 6e66b5b

Browse files
committed
LibC+less: Remove optional includes from stdlib.h
LLVM's libcxx/include/stdlib.h has this to say about how it includes the system's stdlib.h: """ The inclusion of the system's <stdlib.h> is intentionally done once outside of any include guards because some code expects to be able to include the underlying system header multiple times to get different definitions based on the macros that are set before inclusion. """ Since our stdlib.h includes math.h (which is more-or-less optional, at least macOS doesn't seem to do this), we end up in a broken include cycle (because libcxx has its own math.h, which then includes its own stdlib.h, getting us back to where we started from.) Due to this, LLVM never sees our definition of ldiv_t, which breaks the toolchain build. Just to illustrate further, the situation looks basically like this: ``` // a.h foo_t bar = 0; // b.h typedef int foo_t; // c.h // main.c int main() {}; ``` To work around this, this patch makes stdlib.h not pull in any extra headers, since other systems don't appear to do this, and this isn't exactly required by POSIX either (the exact wording in the spec is "Inclusion of the <stdlib.h> header may also make visible all symbols from <stddef.h>, <limits.h>, <math.h>, and <sys/wait.h>.")
1 parent c2f66b8 commit 6e66b5b

File tree

2 files changed

+1
-7
lines changed

2 files changed

+1
-7
lines changed

Userland/Libraries/LibC/stdlib.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66

77
#pragma once
88

9-
// Includes essentially mandated by POSIX:
10-
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdlib.h.html
11-
#include <limits.h>
12-
#include <math.h>
13-
#include <stddef.h>
14-
#include <sys/wait.h>
15-
169
#include <bits/wchar.h>
1710
#include <sys/cdefs.h>
1811
#include <sys/types.h>

Userland/Utilities/less.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <LibCore/System.h>
1010
#include <LibLine/Editor.h>
1111
#include <LibMain/Main.h>
12+
#include <math.h>
1213
#include <stdio.h>
1314
#include <termios.h>
1415
#include <unistd.h>

0 commit comments

Comments
 (0)