Is the crypt() function declared in unistd.h or crypt.h?

前端 未结 2 1753
旧时难觅i
旧时难觅i 2020-12-19 12:39

I\'m using GCC 4.6.0 (on an otherwise unidentified platform).

I am using the crypt() function to encrypt a password.

I have never used

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-19 13:01

    It also says #define _XOPEN_SOURCE (before including unistd.h) in my man page. So you should probably add it to expose the declaration of crypt.

    EDIT

    I just tried it. Including unistd.h and #define _XOPEN_SOURCE before it does the trick. Including it alone isn't enough.

    Using

    gcc version 4.6.0 20110429
    GNU C Library stable release version 2.13
    

    Looking into unistd.h:

    /* XPG4.2 specifies that prototypes for the encryption functions must
       be defined here.  */
    #ifdef  __USE_XOPEN
    /* Encrypt at most 8 characters from KEY using salt to perturb DES.  */
    extern char *crypt (__const char *__key, __const char *__salt)
         __THROW __nonnull ((1, 2));
    

提交回复
热议问题