Declaration of crypt

Ken Brown kbrown@cornell.edu
Thu Jun 9 12:05:00 GMT 2016


On 6/9/2016 5:00 AM, Corinna Vinschen wrote:
> Hi Ken,
>
> On Jun  8 17:18, Ken Brown wrote:
>> According to Posix, including <unistd.h> should bring in the declaration of
>> crypt.  The glibc and FreeBSD headers are consistent with this, but Cygwin's
>> aren't.
>>
>> $ cat test.c
>> #include <unistd.h>
>>
>> int
>> main (void)
>> {
>>   const char *key = NULL;
>>   const char *salt = NULL;
>>   crypt (key, salt);
>> }
>>
>> $ gcc -c test.c
>> test.c: In function ‘main’:
>> test.c:8:3: warning: implicit declaration of function ‘crypt’
>> [-Wimplicit-function-declaration]
>>    crypt (key, salt);
>>    ^
>>
>> The attached patch is one way to fix this.  It means that cygwin-devel would
>> have to require libcrypt-devel.
>>
>> I'm not sure if I used the right feature-test macro in the patch.  It's
>> marked XSI by Posix, but using __XSI_VISIBLE didn't work.
>
> What do you mean by "didn't work"?  __XSI_VISIBLE should be the right
> thing to use.  Your application would have to define, e.g.,
> _XOPEN_SOURCE before including the file.

Ah, that's what I missed.  I tried defining __XSI_VISIBLE in the test 
file, and I still got the implicit declaration warning.  I see now, 
reading /usr/include/sys/features.h, that __XSI_VISIBLE is a private 
macro and shouldn't have been used in my test.

> Another point is the && defined(__CYGWIN__).  This should go away.
> We're trying to make the headers more standards compatible without
> going into too much detial what targat provides which function.

I wasn't sure that <crypt.h> was portable to all newlib targets.

>> P.S. Is cygwin-patches OK for this sort of thing, or should I have sent it
>> to the newlib list?
>
> Ideally to the newlib list, but no worries :)

OK, I'll do that next time.

Revised patch attached.

Ken

-------------- next part --------------
From cb8c2454618c1d862b926d61ac95411b384d0414 Mon Sep 17 00:00:00 2001
From: Ken Brown <kbrown@cornell.edu>
Date: Wed, 8 Jun 2016 17:04:06 -0400
Subject: [PATCH] Make <unistd.h> declare crypt

This is mandated by Posix and is done by the glibc and FreeBSD headers.
---
 newlib/libc/include/sys/unistd.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/newlib/libc/include/sys/unistd.h b/newlib/libc/include/sys/unistd.h
index ef00575..0cbb5de 100644
--- a/newlib/libc/include/sys/unistd.h
+++ b/newlib/libc/include/sys/unistd.h
@@ -31,6 +31,9 @@ int     _EXFUN(close, (int __fildes ));
 #if __POSIX_VISIBLE >= 199209
 size_t	_EXFUN(confstr, (int __name, char *__buf, size_t __len));
 #endif
+#if __XSI_VISIBLE
+#include <crypt.h>
+#endif
 #if __XSI_VISIBLE && __XSI_VISIBLE < 700
 char *  _EXFUN(ctermid, (char *__s ));
 #endif
-- 
2.8.3



More information about the Cygwin-patches mailing list