Bug 72829

Summary: crypt() header declarations do not match man pages
Product: [Retired] Red Hat Linux Reporter: D. Stimits <stimits>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.3CC: fweimer, stimits
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2003-10-03 10:14:18 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description D. Stimits 2002-08-28 08:26:58 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0rc3) Gecko/20020528

Description of problem:
According to the man pages (and therefore this could be considered a man page
problem, and not a glibc-devel problem), the proper file to include under C
development for use of crypt() is <unistd.h>. However, this prototype is not
correct for C, and results in warnings about implicit declaration of crypt().

Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1.Use the crypt(const char*, const char*) function, -Wall, and -lcrypt.
2.#include <unistd.h>
3.Compile...watch it claim that crypt has an implicit declaration.
4.Check "man crypt" for required include.
5.Change from #include <unistd.h>, to #include <crypt.h>, all warnings will go away.

Actual Results:  Warnings of implicit declaration of crypt when including
unistd.h instead of crypt.h.

Expected Results:  No implicit declaration warnings with use of unistd.h.

Additional info:

The proper definition for C development using crypt() is instead in <crypt.h>,
but should probably not be there. Because other references (which are not
necessarily current) also agree that <unistd.h> is the proper header, and not
<crypt.h>, I am initially calling this a bug of glibc-devel, rather than a bug
of man-pages. It is possible that the __THROW macro in the <unistd.h> version is
causing gcc to declare the <unistd.h> declaration as the wrong signature.
Although this could be corrected by editing the man page and declaring <crypt.h>
the proper include file, rather than fixing the headers, it is likely that a
fix-by-man-page will leave a lot of software broken (despite C accepting
implicit declarations, this should be considered an error, not a warning).
Perhaps standards have changed though, in which case the man page would be the
proper thing to update.

Comment 1 Jakub Jelinek 2002-08-28 08:34:06 UTC
crypt is prototyped in unistd.h too, but, as it is not in all the standards which
describe unistd.h, it is enabled only for XOpen and GNU compilations,
ie. you need to use either -D_XOPEN_SOURCE or -D_GNU_SOURCE on the command line
to get it.
info libc (Feature Test Macros) describes this in a big detail...

Comment 2 D. Stimits 2002-08-28 16:58:44 UTC
This error occurs with -D_XOPEN_SOURCE. I simply failed to mention this, it is
still an error. How can I reopen this bug?

Comment 3 D. Stimits 2002-08-28 17:01:19 UTC
Additional comment: The unistd.h file uses -D_USE_XOPEN, the man page specifies
-D_XOPEN_SOURCE, and none of the above results in a non-implicit warning when
unistd.h is the included header. It fails in all cases.

Comment 4 Jakub Jelinek 2002-08-28 17:11:02 UTC
It works without problems with -D_XOPEN_SOURCE for me.
Which means you need to provide (minimal if possible) testcase for what you're
really doing and what warning do you get...
Note that __USE_XOPEN macro is glibc internal thing, which <features.h>
sets based from what feature set macros were used.

Comment 5 Ulrich Drepper 2003-10-03 10:14:18 UTC
It's been more than a year.  This definitely is no problem in glibc and the man
page also seems correct.  NOTABUG

Comment 6 Allen 2005-06-22 22:03:40 UTC
I've found a clue.  It is dependent on other includes in the same file.  I am 
using gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-52), but I am submitting 
this just in case it is still a problem.  It drove me nuts for several hours.

This works with -Wimplicit.

#define _XOPEN_SOURCE
#include <unistd.h>
int main (int argc, char *argv[]) {
    char *a="xx",*b="xxx";
    crypt (a,b);
}

This fails with -Wimplicit.

#include <string.h>
#define _XOPEN_SOURCE
#include <unistd.h>
int main (int argc, char *argv[]) {
    char *a="xx",*b="xxx";
    crypt (a,b);
}
(In reply to comment #0)
> From Bugzilla Helper:
> User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0rc3) Gecko/20020528
> Description of problem:
> According to the man pages (and therefore this could be considered a man page
> problem, and not a glibc-devel problem), the proper file to include under C
> development for use of crypt() is <unistd.h>. However, this prototype is not
> correct for C, and results in warnings about implicit declaration of crypt().
> Version-Release number of selected component (if applicable):
> How reproducible:
> Always
> Steps to Reproduce:
> 1.Use the crypt(const char*, const char*) function, -Wall, and -lcrypt.
> 2.#include <unistd.h>
> 3.Compile...watch it claim that crypt has an implicit declaration.
> 4.Check "man crypt" for required include.
> 5.Change from #include <unistd.h>, to #include <crypt.h>, all warnings will 
go away.
> Actual Results:  Warnings of implicit declaration of crypt when including
> unistd.h instead of crypt.h.
> Expected Results:  No implicit declaration warnings with use of unistd.h.
> Additional info:
> The proper definition for C development using crypt() is instead in 
<crypt.h>,
> but should probably not be there. Because other references (which are not
> necessarily current) also agree that <unistd.h> is the proper header, and not
> <crypt.h>, I am initially calling this a bug of glibc-devel, rather than a 
bug
> of man-pages. It is possible that the __THROW macro in the <unistd.h> 
version is
> causing gcc to declare the <unistd.h> declaration as the wrong signature.
> Although this could be corrected by editing the man page and declaring 
<crypt.h>
> the proper include file, rather than fixing the headers, it is likely that a
> fix-by-man-page will leave a lot of software broken (despite C accepting
> implicit declarations, this should be considered an error, not a warning).
> Perhaps standards have changed though, in which case the man page would be 
the
> proper thing to update.