1833784 Members
2290 Online
110063 Solutions
New Discussion

crypt () function

 
Mehdi_1
Regular Advisor

crypt () function

Hi

I am compiling a program that, uses crypt( ) funtion. I check the man page, and this funtion should be in :

#include
#include

But I can 't find any reference to crypt ( ) funtion in any of the above headers, but there is plenty reference to obsolescent one "crypt_r ( )".

Does anyone know any patch that I should use, I couldn't find any.

Thanks


__Mehdi
8 REPLIES 8
Dietmar Konermann
Honored Contributor

Re: crypt () function

On my 11.11 system it's here:

/usr/include/sys/unistd.h: extern char *crypt __((const char *, const char *));

Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
A. Clay Stephenson
Acclaimed Contributor

Re: crypt () function

The function prototype isd iin unistd.h. You could, in fact, simply

extern char *crypt(const char *key, const char *salt);

without the header but there's no need. Simply #include and all is well.
If it ain't broke, I can fix that.
Robert-Jan Goossens
Honored Contributor

Re: crypt () function

Hi,

11.0
/usr/include/crypt.h

/usr/conf/h/unistd.h
/usr/include/sys/unistd.h
/usr/include/unistd.h

Hope it helps,

Robert-Jan.
Mehdi_1
Regular Advisor

Re: crypt () function

Hi

Thanks for the replies.

I 've got 11.00 box, and I can't see any sign of "crypt()" prototype any any of the :

#include
#include

headers. I 've added the prototype from the man pages:

char *crypt(const char *key, const char *salt);

and the program compiles fine, but in the link time it fails:

/usr/ccs/bin/ld: Unsatisfied symbols:
crypt(char const*, char const*)(code)

Aparently, the function is in "libc.2 not in libcrypt.* !!!. In theory gcc ( or g++ ) should load "-lc" library. But to be in a safe side I even added the -lc to tthe link line, but it still the not linking.

Any help please.


Thanks


__Mehdi



Umapathy S
Honored Contributor

Re: crypt () function

crypt_r() is not obsolescent. In fact you should practice to use them as they are the reentrant form of crypt().

refer to man 3 crypt.

HTH
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
Dietmar Konermann
Honored Contributor

Re: crypt () function

Just checked 10.20, 11.00 and 11.22. The prototype IS in /usr/include/sys/unistd.h which is included by /usr/include/unistd.h. It gets only defined if _INCLUDE_XOPEN_SOURCE is defined also.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Joseph A Benaiah_1
Regular Advisor

Re: crypt () function

Mehdi,

I thought that you were using the standard HP-UX C compiler which does work.

If you are using the gcc compiler, you need to compile your source code as follows:

gcc -lcrypt crypt.c

This will link your code to the cryt libray file.

Cheers,

Joseph.
Mehdi_1
Regular Advisor

Re: crypt () function

Hi

Thanks for the good replies.

Yes, I should have mentioned that before, I am using gcc not HP cc. In fact I am using g++. It seems it works ok with gcc, But it doesn't work with g++. Any idea on that please.

Thanks