evans@ditsyda.oz (Bruce Evans) (02/02/90)
In article <712@augean.OZ> cagney@chook.ua.oz (Andrew Cagney - aka Noid) writes: >The prototype for getpwuid in <pwd.h> vis > struct passwd *getpwuid(int __uid) >clashes with the actual code in getpwent.c > struct passwd *getpwuid(uid_t __uid) > ^^^^^ >uid_t is declared unsigned short in <sys/types.h>. Actually getpwent.c has struct passwd *getpwuid(__uid) uid_t __uid; /* NB old-style definition */ and ANSI-according-to-gcc says this is OK. The int in the prototype says that an int is passed and the uid_t in the definition says it is regarded as a uid_t. Only with the new-style definition must the types match exactly. Andrew must have this problem from using Turbo C, which apparently treats all definitions as new-style (non-ANSI or old-ANSI?). The prototype has to have an int because that is all old compilers know how to pass. It gets worse with 32 bit ints. Then a uid_t in the prototype would allow an ANSI compiler to pass a different number of bytes than an old compiler. Unsigned doesn't work, because 32-bit ANSI compilers promote a 16-bit unsigned short to an int. I think the correct fix for Turbo C is to declare the argument to getpwuid as an int. There are other functions in the library which mis-match their prototypes in the same way. E.g., chmod, creat and umask. (Un)fortunately, the problem is invisible because the file with the prototype is not included. >Finally a POSIX question, do programs that include <signal.h> also >need to include <sys/types.h> (Kermit doesn't)? Signal.h is required to be self-supporting by ANSI (I think :-)). It is slightly broken by requiring pid_t from sys/types.h for the prototype to kill(). However, kill() is a POSIX function and the prototype is only visible when _POSIX_SOURCE is defined. It is not clear to me whether defining _POSIX_SOURCE is allowed to break ANSI headers. (Kermit hasn't heard of POSIX but the makefile has been modified for Minix to supply the define.) I think Kermit *is* required to include sys/types.h and don't like it. Kermit is also broken by including pwd.h without sys/types.h. At least pwd.h is owned by POSIX. -- Bruce Evans evans@ditsyda.oz.au