Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't include <crypt.h> from <stdlib.h> #1112

Merged
merged 1 commit into from
Feb 23, 2024
Merged

Don't include <crypt.h> from <stdlib.h> #1112

merged 1 commit into from
Feb 23, 2024

Conversation

dfyz
Copy link
Contributor

@dfyz dfyz commented Feb 23, 2024

This PR tries to re-land #1104, which was closed because I had tried to make a PR directly from my master and messed up.
Except for the branch name, this PR is identical to #1104, so I'm copying the original PR description below verbatim.

POSIX says that crypt() resides in <unistd.h>. As far as I know, crypt() doesn't have anything to do with the C standard library, so including it unconditionally from <stdlib.h> is somewhat strange and breaks the build of the Lua MD5 implementation bundled with LuaTeX:

/home/dfyz/busytex/source/texlive/texk/web2c/luatexdir/luamd5/md5lib.c:117:12: error: conflicting types for ‘crypt’; have ‘int(lua_State *)’
  117 | static int crypt (lua_State *L) {
      |            ^~~~~
In file included from /home/dfyz/cosmopolitan/cosmocc/include/stdlib.h:17,
                 from /home/dfyz/busytex/source/texlive/texk/web2c/luatexdir/luamd5/md5lib.c:8:
/home/dfyz/cosmopolitan/cosmocc/include/third_party/musl/crypt.h:12:7: note: previous declaration of ‘crypt’ with type ‘char *(const char *, const char *)’
   12 | char *crypt(const char *, const char *);
      |       ^~~~~

A simpler test program is just:

#include <stdlib.h>

void crypt() {
}

int main() {
}

It builds successfully with both gcc (glibc) and musl-gcc (musl), but fails to build with cosmocc (with an error very similar to the above).
Given that crypt() is a very short word and is likely to clash with other real-world programs in the future, I suggest removing this include.

Copy link
Owner

@jart jart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this happened due to setkey(). I'll write a follow-up change to put that back into stdlib.h after merging this. Thanks!

@jart jart merged commit 9b4701b into jart:master Feb 23, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants