bitwiseworks / libc

LIBC Next (kLIBC fork)
9 stars 4 forks source link

Align crypt() and encrypt() in unistd.h to crypt.h #121

Closed SilvanScherrer closed 2 years ago

SilvanScherrer commented 2 years ago

remove crypt() and encrypt() from unistd.h, as they are defined in crypt.h. This might give a clash if both .h are included

dmik commented 2 years ago

Sorry but I can't see the problem so far. This simple test doesn't give any clashes:

#include <stdio.h>
#include <unistd.h>
#include <crypt.h>

int main(void)
{
  printf ("%p\n", crypt);
  return 0;
}
SilvanScherrer commented 2 years ago

hmm g++ -c -Zomf unistd.c -Ic:/usr/include -o unistd.o triggers the error. Why does adding usr/include trigger it?

dmik commented 2 years ago

Are you talking about the above test case? This doesn't trigger any problems here. May be something is wrong with your include dir...

dmik commented 2 years ago

Discard my last comment, I could reproduce it too (had crypt.h commented out).

dmik commented 2 years ago

This happens because -Ic:/usr/include makes LIBC includes to be included before their GCC overrides from C:\usr\lib\gcc\i686-pc-os2-emx\9\include-fixed and this somehow breaks some GCC setup in C++ mode. It's not clear what exactly gets broken because there is no source-level difference between preprocessor results of both cases in -E mode except some # <num> <file> references to included files but apparently these references somehow change the GCC behavior. If I remove all lines starting from # both cases fail similarly:

test.E1f.c:913:14: error: declaration of 'char* crypt(const char*, const char*) throw ()' has a different exception specifier
  913 | extern char *crypt (const char *__key, const char *__salt)
      |              ^~~~~
test.E1f.c:736:7: note: from previous declaration 'char* crypt(const char*, const char*)'
  736 | char *crypt(const char *, const char *);
      |       ^~~~~
test.E1f.c:917:13: error: declaration of 'void setkey(const char*) throw ()' has a different exception specifier
  917 | extern void setkey (const char *__key) throw () __attribute__ ((__nonnull__ (1)));
      |             ^~~~~~
test.E1f.c:805:6: note: from previous declaration 'void setkey(const char*)'
  805 | void setkey(const char *);
      |      ^~~~~~
test.E1f.c:921:13: error: declaration of 'void encrypt(char*, int) throw ()' has a different exception specifier
  921 | extern void encrypt (char *__block, int __edflag) throw () __attribute__ ((__nonnull__ (1)));
      |             ^~~~~~~
test.E1f.c:738:6: note: from previous declaration 'void encrypt(char*, int)'
  738 | void encrypt(char *, int);
      |      ^~~~~~~

Given that iIn general a practice of manually adding top-level system include dirs to the GCC command line is bad (and may lead to many other problems), I guess we should fix the project that does that instead of fixing anything in LIBC or GCC.

dmik commented 2 years ago

Since crypt() and encrypt() must reside in unistd.h in XSI section according to POSIX, I will fix this by using __THROW there the same way crypt.h does.