using crypt(3C) in a C++ program on Solaris 2.6

using crypt(3C) in a C++ program on Solaris 2.6

Post by Ling Jian » Sat, 21 Apr 2001 23:32:40



Could anybody tell me what am I missing?

I am trying to use crypt(3C) in a c++ program compiled with gcc (2.95.2) on a
solaris 2.6 machine (sun4u).

The man page of crypt(3C) tells me to do this:

        #include <unistd.h>

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

And here is a test program:

        #include <unistd.h>

        int main ( int argc, char * argv[] ) {
                char slat[] = "salt";
                char key[]  = "mypassword";
                char *encrypted = crypt( salt, key );
        }

When compiles, gcc (not g++) tells me to add a (char *) cast to the crypt call.
I did and it
works fine.

The problem I have is when I compile this as a c++ program, g++ tells me that I
am
implicitly declaring  an int crypt( .. ).

Any help is appreciated.

Ling

 
 
 

using crypt(3C) in a C++ program on Solaris 2.6

Post by Fletcher Glen » Sun, 22 Apr 2001 01:23:50



> Could anybody tell me what am I missing?

> I am trying to use crypt(3C) in a c++ program compiled with gcc (2.95.2) on a
> solaris 2.6 machine (sun4u).

> The man page of crypt(3C) tells me to do this:

>         #include <unistd.h>

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

> And here is a test program:

>         #include <unistd.h>

>         int main ( int argc, char * argv[] ) {
>                 char slat[] = "salt";
>                 char key[]  = "mypassword";
>                 char *encrypted = crypt( salt, key );
>         }

> When compiles, gcc (not g++) tells me to add a (char *) cast to the crypt call.
> I did and it
> works fine.

> The problem I have is when I compile this as a c++ program, g++ tells me that I
> am
> implicitly declaring  an int crypt( .. ).

> Any help is appreciated.

> Ling

I believe that if you compile your program with the -E option,
it will output everything after the preprocessor is done, and
before compile.  Examine this output to see if crypt() has
a defined prototype.

--
                Fletcher Glenn


 
 
 

using crypt(3C) in a C++ program on Solaris 2.6

Post by Ling Jian » Sun, 22 Apr 2001 01:47:04


Thanks, Fletcher.

I tried the -E option with both g++ and gcc. I did not find from the output the
prototype.

Ling


> I believe that if you compile your program with the -E option,
> it will output everything after the preprocessor is done, and
> before compile.  Examine this output to see if crypt() has
> a defined prototype.

> --
>                 Fletcher Glenn


 
 
 

using crypt(3C) in a C++ program on Solaris 2.6

Post by Ling Jian » Sun, 22 Apr 2001 02:54:10


Fletcher,

Never mind. It is one of those things that happens when you are a true believer
of the man page or documentation. It turns out that there is a separate header
file under /usr/include  that comes with the OS. The man page of crypt(3C) does
not even mention it. The only header it does is unistd.h

Thanks.

Ling


> I believe that if you compile your program with the -E option,
> it will output everything after the preprocessor is done, and
> before compile.  Examine this output to see if crypt() has
> a defined prototype.

> --
>                 Fletcher Glenn


 
 
 

using crypt(3C) in a C++ program on Solaris 2.6

Post by Nithyanandha » Sun, 22 Apr 2001 13:17:51



> Never mind. It is one of those things that happens when you are a true believer
> of the man page or documentation. It turns out that there is a separate header
> file under /usr/include  that comes with the OS. The man page of crypt(3C) does
> not even mention it. The only header it does is unistd.h

An excerpt from the  " unistd.h "

...............................
#if (defined(_XOPEN_SOURCE) && (_XOPEN_VERSION - 0 == 4)) || \
        defined(__EXTENSIONS__)
extern size_t confstr(int, char *, size_t);
extern char *crypt(const char *, const char *);
#endif /* (defined(XOPEN_SOURCE) && (_XOPEN_VERSION - 0 == 4))... */
.................................

I think your compiler doesn't define these macros or atleast  __EXTENSIONS__.
That's why including just unistd.h was not suffecient.....crypt( ) is there in
crypt.h.
But if you still want to include only unistd.h and wants this to work you can
compile the code as " CC -D__EXTENSIONS__  <filename> ".  See, whether it works for
you.

--Nithyanand.

 
 
 

using crypt(3C) in a C++ program on Solaris 2.6

Post by Ling Jian » Mon, 23 Apr 2001 01:08:13


Thanks, Nithyanand.

I did extamine the header file and tried the macro but it did not work with both Sun's
CC compiler and g++.
If it had worked, how would a programmer know to include a macro definition without
examining the header or those it refers to?

Reguard.

Ling



> > Never mind. It is one of those things that happens when you are a true believer
> > of the man page or documentation. It turns out that there is a separate header
> > file under /usr/include  that comes with the OS. The man page of crypt(3C) does
> > not even mention it. The only header it does is unistd.h

> An excerpt from the  " unistd.h "

> ...............................
> #if (defined(_XOPEN_SOURCE) && (_XOPEN_VERSION - 0 == 4)) || \
>         defined(__EXTENSIONS__)
> extern size_t confstr(int, char *, size_t);
> extern char *crypt(const char *, const char *);
> #endif /* (defined(XOPEN_SOURCE) && (_XOPEN_VERSION - 0 == 4))... */
> .................................

> I think your compiler doesn't define these macros or atleast  __EXTENSIONS__.
> That's why including just unistd.h was not suffecient.....crypt( ) is there in
> crypt.h.
> But if you still want to include only unistd.h and wants this to work you can
> compile the code as " CC -D__EXTENSIONS__  <filename> ".  See, whether it works for
> you.

> --Nithyanand.

 
 
 

1. C++ program compiled on Solaris 8 doesn't run on Solaris 2.6

Writing in forward-compatibility would require being able to see the future.
The fact that it works at all with Solaris 8 compiled ANYTHING in Solaris 2.6
is pure dumb luck.

Also, the Sun Blade 1000 running Solaris 8 is a 64-bit system. You may be
automatically creating 64-bit binaries with Forte. These won't run on a 2.6 no
matter how long you hold your breath.

2. Linux support Evergreen 586 upgrade?

3. Error in linknig C++ STL code using CC 5.0 on Solaris 2.6

4. Disk Suite - Matching device numbers

5. total CPU load from solaris 2.5.1 2.6 using C or C++

6. Track Stable with cvsup?

7. current CPU load from solaris 2.5.1 & 2.6 using C or C++

8. New Hard Disk

9. Error in linknig C++ STL code using CC 5.0 on Solaris 2.6

10. Accessing I/O address space using C/C++ under Solaris 2.6??

11. Current CPU load from solaris 2.5.1 & 2.6 using C or C++

12. crypt algorithm in Solaris 2.6

13. crypt in C++ just like crypt in c library