Declaration of crypt

Ken Brown
Wed Jun 8 21:19:00 GMT 2016

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>

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’ 
    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.


P.S. Is cygwin-patches OK for this sort of thing, or should I have sent 
it to the newlib list?
-------------- next part --------------
From 91ed7816e771a78170555db246e0e35dc6d2ca3e Mon Sep 17 00:00:00 2001
From: Ken Brown <>
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..ebae5d8 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));
+#if __BSD_VISIBLE && defined(__CYGWIN__)
+#include <crypt.h>
 #if __XSI_VISIBLE && __XSI_VISIBLE < 700
 char *  _EXFUN(ctermid, (char *__s ));

More information about the Cygwin-patches mailing list