What is the difference between crypt in unistd.h and crypt.h?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1















Background



crypt has two definitions, from the docs,




  1. One of them uses unistd.h



    #define _XOPEN_SOURCE /* See feature_test_macros(7) */
    #include <unistd.h>


    This is defined as



    #ifdef __USE_MISC

    extern char *crypt (const char *__key, const char *__salt)
    __THROW __nonnull ((1, 2));
    #endif



  2. One of them uses GNU crypt.h



    #define _GNU_SOURCE /* See feature_test_macros(7) */
    #include <crypt.h>


    This is defined as



    extern char *crypt (const char *__phrase, const char *__salt) 
    __THROW __nonnull ((1, 2));


Problem



When I compile with the definition in the first example (unistd.h)



#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>

int main()

printf("%s", crypt("foobar", "sa"));



I'm getting the error



In function ‘main’:
warning: implicit declaration of function ‘crypt’; did you mean ‘chroot’? [-Wimplicit-function-declaration]
printf("%s", crypt("foobar", "sa"));
^~~~~
chroot
warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
printf("%s", crypt("foobar", "sa"));
~^ ~~~~~~~~~~~~~~~~~~~~~
%d


Out of desperation, I've tried adding this.



#define _XOPEN_VERSION 700
#define _POSIX_VERSION 200809L
#define __USE_MISC 1


On Ubuntu Trusty 14.04 I believe this works fine use the unistd.h declaration, which makes all the more confusing.










share|improve this question















migrated from unix.stackexchange.com Feb 1 at 8:12


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.


















  • This is a question about C, not about Linux usage or administration.

    – Gilles
    Feb 1 at 7:16















1















Background



crypt has two definitions, from the docs,




  1. One of them uses unistd.h



    #define _XOPEN_SOURCE /* See feature_test_macros(7) */
    #include <unistd.h>


    This is defined as



    #ifdef __USE_MISC

    extern char *crypt (const char *__key, const char *__salt)
    __THROW __nonnull ((1, 2));
    #endif



  2. One of them uses GNU crypt.h



    #define _GNU_SOURCE /* See feature_test_macros(7) */
    #include <crypt.h>


    This is defined as



    extern char *crypt (const char *__phrase, const char *__salt) 
    __THROW __nonnull ((1, 2));


Problem



When I compile with the definition in the first example (unistd.h)



#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>

int main()

printf("%s", crypt("foobar", "sa"));



I'm getting the error



In function ‘main’:
warning: implicit declaration of function ‘crypt’; did you mean ‘chroot’? [-Wimplicit-function-declaration]
printf("%s", crypt("foobar", "sa"));
^~~~~
chroot
warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
printf("%s", crypt("foobar", "sa"));
~^ ~~~~~~~~~~~~~~~~~~~~~
%d


Out of desperation, I've tried adding this.



#define _XOPEN_VERSION 700
#define _POSIX_VERSION 200809L
#define __USE_MISC 1


On Ubuntu Trusty 14.04 I believe this works fine use the unistd.h declaration, which makes all the more confusing.










share|improve this question















migrated from unix.stackexchange.com Feb 1 at 8:12


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.


















  • This is a question about C, not about Linux usage or administration.

    – Gilles
    Feb 1 at 7:16













1












1








1








Background



crypt has two definitions, from the docs,




  1. One of them uses unistd.h



    #define _XOPEN_SOURCE /* See feature_test_macros(7) */
    #include <unistd.h>


    This is defined as



    #ifdef __USE_MISC

    extern char *crypt (const char *__key, const char *__salt)
    __THROW __nonnull ((1, 2));
    #endif



  2. One of them uses GNU crypt.h



    #define _GNU_SOURCE /* See feature_test_macros(7) */
    #include <crypt.h>


    This is defined as



    extern char *crypt (const char *__phrase, const char *__salt) 
    __THROW __nonnull ((1, 2));


Problem



When I compile with the definition in the first example (unistd.h)



#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>

int main()

printf("%s", crypt("foobar", "sa"));



I'm getting the error



In function ‘main’:
warning: implicit declaration of function ‘crypt’; did you mean ‘chroot’? [-Wimplicit-function-declaration]
printf("%s", crypt("foobar", "sa"));
^~~~~
chroot
warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
printf("%s", crypt("foobar", "sa"));
~^ ~~~~~~~~~~~~~~~~~~~~~
%d


Out of desperation, I've tried adding this.



#define _XOPEN_VERSION 700
#define _POSIX_VERSION 200809L
#define __USE_MISC 1


On Ubuntu Trusty 14.04 I believe this works fine use the unistd.h declaration, which makes all the more confusing.










share|improve this question
















Background



crypt has two definitions, from the docs,




  1. One of them uses unistd.h



    #define _XOPEN_SOURCE /* See feature_test_macros(7) */
    #include <unistd.h>


    This is defined as



    #ifdef __USE_MISC

    extern char *crypt (const char *__key, const char *__salt)
    __THROW __nonnull ((1, 2));
    #endif



  2. One of them uses GNU crypt.h



    #define _GNU_SOURCE /* See feature_test_macros(7) */
    #include <crypt.h>


    This is defined as



    extern char *crypt (const char *__phrase, const char *__salt) 
    __THROW __nonnull ((1, 2));


Problem



When I compile with the definition in the first example (unistd.h)



#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>

int main()

printf("%s", crypt("foobar", "sa"));



I'm getting the error



In function ‘main’:
warning: implicit declaration of function ‘crypt’; did you mean ‘chroot’? [-Wimplicit-function-declaration]
printf("%s", crypt("foobar", "sa"));
^~~~~
chroot
warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
printf("%s", crypt("foobar", "sa"));
~^ ~~~~~~~~~~~~~~~~~~~~~
%d


Out of desperation, I've tried adding this.



#define _XOPEN_VERSION 700
#define _POSIX_VERSION 200809L
#define __USE_MISC 1


On Ubuntu Trusty 14.04 I believe this works fine use the unistd.h declaration, which makes all the more confusing.







compilation c posix crypt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 1 at 18:09







Evan Carroll

















asked Feb 1 at 7:09









Evan CarrollEvan Carroll

36k23145247




36k23145247




migrated from unix.stackexchange.com Feb 1 at 8:12


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.









migrated from unix.stackexchange.com Feb 1 at 8:12


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.














  • This is a question about C, not about Linux usage or administration.

    – Gilles
    Feb 1 at 7:16

















  • This is a question about C, not about Linux usage or administration.

    – Gilles
    Feb 1 at 7:16
















This is a question about C, not about Linux usage or administration.

– Gilles
Feb 1 at 7:16





This is a question about C, not about Linux usage or administration.

– Gilles
Feb 1 at 7:16












2 Answers
2






active

oldest

votes


















3














These are two declarations, not two definitions. The content of the header file has no impact on which definition of a function is included: this is determined by the linker. There is only one definition of the crypt function in the Unix C standard library, it's whatever the symbol crypt points to in libcrypt.a or libcrypt.so (depending on whether you link statically or dynamically).



Since the two declarations are compatible, it doesn't matter which header a program gets its through. It's also fine if both declarations are processed: a program can contain any number of declarations for a function as long as they're compatible. Without going into the exact details (refer to the C language specification), two function declarations are compatible if they have the same return type, the same number of arguments and the same type for each argument. The name of the argument given in a declaration is not significant.






share|improve this answer























  • That's what I would think but I know some of this stuff is defined internally and does some deep voodoo (at least with c99.h magic). If they are the same definitions, why would the unistd.h version not work then (my other question)

    – Evan Carroll
    Feb 1 at 7:24











  • The crypt function is not defined internally. It's defined in a library, not one of those functions for which the compiler itself can generate code. The deep voodoo is for conditional inclusion of the declaration, not the definition. The two headers that declare this function do so with different preprocessor guard. What preprocessor symbols to define to get the declaration from unistd.h is your other question.

    – Gilles
    Feb 1 at 7:35


















0














You should ignore unistd.h. That declaration is there for POSIX compatibility but GLIB has removed the definition for crypt when they migrated to libxcrypt to develop those features in isolation of glibc. This means you can still get ABI-compatibility but must link in the crypt. You can read more about that here




Availability in glibc



The crypt (), encrypt (), and setkey () functions are part of the POSIX.1-2008 XSI Options Group for Encryption and are optional. If the interfaces are not available then the symbolic constant _XOPEN_CRYPT is either not defined or defined to -1, and can be checked at runtime with sysconf ().



This may be the case if the downstream distribution has switched from glibc crypt to libxcrypt. When recompiling applications in such distributions the
user must detect if _XOPEN_CRPYT is not available and include crypt.h for the function prototypes; otherwise libxcrypt is a ABI compatible drop-in replacement.




As for why even if you link the definition isn't pulled down with



#define _XOPEN_VERSION 700
#define _POSIX_VERSION 200809L
#define __USE_MISC 1
#define _XOPEN_SOURCE


Well there are a few things that happening there



  1. The only header that matters in unistd.h is __USE_MISC.


  2. unistd.h includes features.h which undefs the __USE_ macros to start with a "clean slate"

  3. The only way to define __USE_MISC is to have defined _GNU_SOURCE.

If you want to pull in the declaration of crypt.h from unistd.h you must define _GNU_SOURCE! Those two examples cited from man page of crypt.h do the same thing and whether you include unistd.h or crypt.h you MUST also define _GNU_SOURCE in contemporary versions of glibc.



So you can either do,



#define _GNU_SOURCE
#include <unistd.h>


Or,



#define _GNU_SOURCE
#include <crypt.h>


But because you must link against crypt (-lcrypt) I would suggest using the declaration in crypt.h for sanity.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54475384%2fwhat-is-the-difference-between-crypt-in-unistd-h-and-crypt-h%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    These are two declarations, not two definitions. The content of the header file has no impact on which definition of a function is included: this is determined by the linker. There is only one definition of the crypt function in the Unix C standard library, it's whatever the symbol crypt points to in libcrypt.a or libcrypt.so (depending on whether you link statically or dynamically).



    Since the two declarations are compatible, it doesn't matter which header a program gets its through. It's also fine if both declarations are processed: a program can contain any number of declarations for a function as long as they're compatible. Without going into the exact details (refer to the C language specification), two function declarations are compatible if they have the same return type, the same number of arguments and the same type for each argument. The name of the argument given in a declaration is not significant.






    share|improve this answer























    • That's what I would think but I know some of this stuff is defined internally and does some deep voodoo (at least with c99.h magic). If they are the same definitions, why would the unistd.h version not work then (my other question)

      – Evan Carroll
      Feb 1 at 7:24











    • The crypt function is not defined internally. It's defined in a library, not one of those functions for which the compiler itself can generate code. The deep voodoo is for conditional inclusion of the declaration, not the definition. The two headers that declare this function do so with different preprocessor guard. What preprocessor symbols to define to get the declaration from unistd.h is your other question.

      – Gilles
      Feb 1 at 7:35















    3














    These are two declarations, not two definitions. The content of the header file has no impact on which definition of a function is included: this is determined by the linker. There is only one definition of the crypt function in the Unix C standard library, it's whatever the symbol crypt points to in libcrypt.a or libcrypt.so (depending on whether you link statically or dynamically).



    Since the two declarations are compatible, it doesn't matter which header a program gets its through. It's also fine if both declarations are processed: a program can contain any number of declarations for a function as long as they're compatible. Without going into the exact details (refer to the C language specification), two function declarations are compatible if they have the same return type, the same number of arguments and the same type for each argument. The name of the argument given in a declaration is not significant.






    share|improve this answer























    • That's what I would think but I know some of this stuff is defined internally and does some deep voodoo (at least with c99.h magic). If they are the same definitions, why would the unistd.h version not work then (my other question)

      – Evan Carroll
      Feb 1 at 7:24











    • The crypt function is not defined internally. It's defined in a library, not one of those functions for which the compiler itself can generate code. The deep voodoo is for conditional inclusion of the declaration, not the definition. The two headers that declare this function do so with different preprocessor guard. What preprocessor symbols to define to get the declaration from unistd.h is your other question.

      – Gilles
      Feb 1 at 7:35













    3












    3








    3







    These are two declarations, not two definitions. The content of the header file has no impact on which definition of a function is included: this is determined by the linker. There is only one definition of the crypt function in the Unix C standard library, it's whatever the symbol crypt points to in libcrypt.a or libcrypt.so (depending on whether you link statically or dynamically).



    Since the two declarations are compatible, it doesn't matter which header a program gets its through. It's also fine if both declarations are processed: a program can contain any number of declarations for a function as long as they're compatible. Without going into the exact details (refer to the C language specification), two function declarations are compatible if they have the same return type, the same number of arguments and the same type for each argument. The name of the argument given in a declaration is not significant.






    share|improve this answer













    These are two declarations, not two definitions. The content of the header file has no impact on which definition of a function is included: this is determined by the linker. There is only one definition of the crypt function in the Unix C standard library, it's whatever the symbol crypt points to in libcrypt.a or libcrypt.so (depending on whether you link statically or dynamically).



    Since the two declarations are compatible, it doesn't matter which header a program gets its through. It's also fine if both declarations are processed: a program can contain any number of declarations for a function as long as they're compatible. Without going into the exact details (refer to the C language specification), two function declarations are compatible if they have the same return type, the same number of arguments and the same type for each argument. The name of the argument given in a declaration is not significant.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Feb 1 at 7:21









    GillesGilles

    75.4k19161205




    75.4k19161205












    • That's what I would think but I know some of this stuff is defined internally and does some deep voodoo (at least with c99.h magic). If they are the same definitions, why would the unistd.h version not work then (my other question)

      – Evan Carroll
      Feb 1 at 7:24











    • The crypt function is not defined internally. It's defined in a library, not one of those functions for which the compiler itself can generate code. The deep voodoo is for conditional inclusion of the declaration, not the definition. The two headers that declare this function do so with different preprocessor guard. What preprocessor symbols to define to get the declaration from unistd.h is your other question.

      – Gilles
      Feb 1 at 7:35

















    • That's what I would think but I know some of this stuff is defined internally and does some deep voodoo (at least with c99.h magic). If they are the same definitions, why would the unistd.h version not work then (my other question)

      – Evan Carroll
      Feb 1 at 7:24











    • The crypt function is not defined internally. It's defined in a library, not one of those functions for which the compiler itself can generate code. The deep voodoo is for conditional inclusion of the declaration, not the definition. The two headers that declare this function do so with different preprocessor guard. What preprocessor symbols to define to get the declaration from unistd.h is your other question.

      – Gilles
      Feb 1 at 7:35
















    That's what I would think but I know some of this stuff is defined internally and does some deep voodoo (at least with c99.h magic). If they are the same definitions, why would the unistd.h version not work then (my other question)

    – Evan Carroll
    Feb 1 at 7:24





    That's what I would think but I know some of this stuff is defined internally and does some deep voodoo (at least with c99.h magic). If they are the same definitions, why would the unistd.h version not work then (my other question)

    – Evan Carroll
    Feb 1 at 7:24













    The crypt function is not defined internally. It's defined in a library, not one of those functions for which the compiler itself can generate code. The deep voodoo is for conditional inclusion of the declaration, not the definition. The two headers that declare this function do so with different preprocessor guard. What preprocessor symbols to define to get the declaration from unistd.h is your other question.

    – Gilles
    Feb 1 at 7:35





    The crypt function is not defined internally. It's defined in a library, not one of those functions for which the compiler itself can generate code. The deep voodoo is for conditional inclusion of the declaration, not the definition. The two headers that declare this function do so with different preprocessor guard. What preprocessor symbols to define to get the declaration from unistd.h is your other question.

    – Gilles
    Feb 1 at 7:35













    0














    You should ignore unistd.h. That declaration is there for POSIX compatibility but GLIB has removed the definition for crypt when they migrated to libxcrypt to develop those features in isolation of glibc. This means you can still get ABI-compatibility but must link in the crypt. You can read more about that here




    Availability in glibc



    The crypt (), encrypt (), and setkey () functions are part of the POSIX.1-2008 XSI Options Group for Encryption and are optional. If the interfaces are not available then the symbolic constant _XOPEN_CRYPT is either not defined or defined to -1, and can be checked at runtime with sysconf ().



    This may be the case if the downstream distribution has switched from glibc crypt to libxcrypt. When recompiling applications in such distributions the
    user must detect if _XOPEN_CRPYT is not available and include crypt.h for the function prototypes; otherwise libxcrypt is a ABI compatible drop-in replacement.




    As for why even if you link the definition isn't pulled down with



    #define _XOPEN_VERSION 700
    #define _POSIX_VERSION 200809L
    #define __USE_MISC 1
    #define _XOPEN_SOURCE


    Well there are a few things that happening there



    1. The only header that matters in unistd.h is __USE_MISC.


    2. unistd.h includes features.h which undefs the __USE_ macros to start with a "clean slate"

    3. The only way to define __USE_MISC is to have defined _GNU_SOURCE.

    If you want to pull in the declaration of crypt.h from unistd.h you must define _GNU_SOURCE! Those two examples cited from man page of crypt.h do the same thing and whether you include unistd.h or crypt.h you MUST also define _GNU_SOURCE in contemporary versions of glibc.



    So you can either do,



    #define _GNU_SOURCE
    #include <unistd.h>


    Or,



    #define _GNU_SOURCE
    #include <crypt.h>


    But because you must link against crypt (-lcrypt) I would suggest using the declaration in crypt.h for sanity.






    share|improve this answer





























      0














      You should ignore unistd.h. That declaration is there for POSIX compatibility but GLIB has removed the definition for crypt when they migrated to libxcrypt to develop those features in isolation of glibc. This means you can still get ABI-compatibility but must link in the crypt. You can read more about that here




      Availability in glibc



      The crypt (), encrypt (), and setkey () functions are part of the POSIX.1-2008 XSI Options Group for Encryption and are optional. If the interfaces are not available then the symbolic constant _XOPEN_CRYPT is either not defined or defined to -1, and can be checked at runtime with sysconf ().



      This may be the case if the downstream distribution has switched from glibc crypt to libxcrypt. When recompiling applications in such distributions the
      user must detect if _XOPEN_CRPYT is not available and include crypt.h for the function prototypes; otherwise libxcrypt is a ABI compatible drop-in replacement.




      As for why even if you link the definition isn't pulled down with



      #define _XOPEN_VERSION 700
      #define _POSIX_VERSION 200809L
      #define __USE_MISC 1
      #define _XOPEN_SOURCE


      Well there are a few things that happening there



      1. The only header that matters in unistd.h is __USE_MISC.


      2. unistd.h includes features.h which undefs the __USE_ macros to start with a "clean slate"

      3. The only way to define __USE_MISC is to have defined _GNU_SOURCE.

      If you want to pull in the declaration of crypt.h from unistd.h you must define _GNU_SOURCE! Those two examples cited from man page of crypt.h do the same thing and whether you include unistd.h or crypt.h you MUST also define _GNU_SOURCE in contemporary versions of glibc.



      So you can either do,



      #define _GNU_SOURCE
      #include <unistd.h>


      Or,



      #define _GNU_SOURCE
      #include <crypt.h>


      But because you must link against crypt (-lcrypt) I would suggest using the declaration in crypt.h for sanity.






      share|improve this answer



























        0












        0








        0







        You should ignore unistd.h. That declaration is there for POSIX compatibility but GLIB has removed the definition for crypt when they migrated to libxcrypt to develop those features in isolation of glibc. This means you can still get ABI-compatibility but must link in the crypt. You can read more about that here




        Availability in glibc



        The crypt (), encrypt (), and setkey () functions are part of the POSIX.1-2008 XSI Options Group for Encryption and are optional. If the interfaces are not available then the symbolic constant _XOPEN_CRYPT is either not defined or defined to -1, and can be checked at runtime with sysconf ().



        This may be the case if the downstream distribution has switched from glibc crypt to libxcrypt. When recompiling applications in such distributions the
        user must detect if _XOPEN_CRPYT is not available and include crypt.h for the function prototypes; otherwise libxcrypt is a ABI compatible drop-in replacement.




        As for why even if you link the definition isn't pulled down with



        #define _XOPEN_VERSION 700
        #define _POSIX_VERSION 200809L
        #define __USE_MISC 1
        #define _XOPEN_SOURCE


        Well there are a few things that happening there



        1. The only header that matters in unistd.h is __USE_MISC.


        2. unistd.h includes features.h which undefs the __USE_ macros to start with a "clean slate"

        3. The only way to define __USE_MISC is to have defined _GNU_SOURCE.

        If you want to pull in the declaration of crypt.h from unistd.h you must define _GNU_SOURCE! Those two examples cited from man page of crypt.h do the same thing and whether you include unistd.h or crypt.h you MUST also define _GNU_SOURCE in contemporary versions of glibc.



        So you can either do,



        #define _GNU_SOURCE
        #include <unistd.h>


        Or,



        #define _GNU_SOURCE
        #include <crypt.h>


        But because you must link against crypt (-lcrypt) I would suggest using the declaration in crypt.h for sanity.






        share|improve this answer















        You should ignore unistd.h. That declaration is there for POSIX compatibility but GLIB has removed the definition for crypt when they migrated to libxcrypt to develop those features in isolation of glibc. This means you can still get ABI-compatibility but must link in the crypt. You can read more about that here




        Availability in glibc



        The crypt (), encrypt (), and setkey () functions are part of the POSIX.1-2008 XSI Options Group for Encryption and are optional. If the interfaces are not available then the symbolic constant _XOPEN_CRYPT is either not defined or defined to -1, and can be checked at runtime with sysconf ().



        This may be the case if the downstream distribution has switched from glibc crypt to libxcrypt. When recompiling applications in such distributions the
        user must detect if _XOPEN_CRPYT is not available and include crypt.h for the function prototypes; otherwise libxcrypt is a ABI compatible drop-in replacement.




        As for why even if you link the definition isn't pulled down with



        #define _XOPEN_VERSION 700
        #define _POSIX_VERSION 200809L
        #define __USE_MISC 1
        #define _XOPEN_SOURCE


        Well there are a few things that happening there



        1. The only header that matters in unistd.h is __USE_MISC.


        2. unistd.h includes features.h which undefs the __USE_ macros to start with a "clean slate"

        3. The only way to define __USE_MISC is to have defined _GNU_SOURCE.

        If you want to pull in the declaration of crypt.h from unistd.h you must define _GNU_SOURCE! Those two examples cited from man page of crypt.h do the same thing and whether you include unistd.h or crypt.h you MUST also define _GNU_SOURCE in contemporary versions of glibc.



        So you can either do,



        #define _GNU_SOURCE
        #include <unistd.h>


        Or,



        #define _GNU_SOURCE
        #include <crypt.h>


        But because you must link against crypt (-lcrypt) I would suggest using the declaration in crypt.h for sanity.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 1 at 18:01

























        answered Feb 1 at 17:52









        Evan CarrollEvan Carroll

        36k23145247




        36k23145247



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54475384%2fwhat-is-the-difference-between-crypt-in-unistd-h-and-crypt-h%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?