The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing global variable to a function which is called by another function sars Shell Programming and Scripting 4 06-30-2008 11:39 AM
Log function Ernst Shell Programming and Scripting 17 03-19-2007 12:31 PM
Function within function (Recurance) chassis UNIX for Dummies Questions & Answers 2 09-19-2006 09:32 AM
function mpang_ Shell Programming and Scripting 1 07-26-2006 12:16 AM
How to convert the "select" function into a "poll" function rbolante High Level Programming 1 07-10-2001 10:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-22-2008
marconi marconi is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 41
Regarding cuserid() function in 'C'

Hi,

I am doing a (Make gapw), where I have the following line of code at Line No.96 :-

96 DISCARD strcpy(user , (char*) cuserid((char*)0));

But I am not able to compile due to the only 1 following error :-

gapw.c: In function `main':
gapw.c:96: warning: cast to pointer from integer of different size

I included #include <stdlib.h> and #include <libgen.h>, in the file, but still I am not able to compile.

I think, there is a problem with the usage of cuserid() function.

Request you to please help me to debug the error.

Thanks in advance.

Best Regards,
Marconi

Last edited by marconi; 07-22-2008 at 03:59 PM..
  #2 (permalink)  
Old 07-22-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
What platform are you on?
cuserid() will be removed some time in the future so it is recommended to use its replacements like getpwuid() or getlogin().
  #3 (permalink)  
Old 07-22-2008
marconi marconi is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 41
Hi,

I am currently on OS :- Red Hat Linux Version 3.0. The script I am running is a HP Tru64 Unix compatible script
which I am trying to run on the Linux Version 3.0.

Instead of :- DISCARD strcpy(user , (char*) cuserid((char*)0));

I used each of the following as per your suggestion :-

DISCARD strcpy(user, (char*) getlogin((char*)0));

or

DISCARD strcpy(user , (char*) getpwuid(getuid((char*)0)));

but still its showing me the following errors :-

$ make gapw
cc -c -o gapw.o gapw.c
gapw.c: In function `main':
gapw.c:101: error: too many arguments to function `getlogin'
make: *** [gapw.o] Error 1

or

$ make gapw
cc -c -o gapw.o gapw.c
gapw.c: In function `main':
gapw.c:102: error: too many arguments to function `getuid'
gapw.c:102: warning: cast to pointer from integer of different size
make: *** [gapw.o] Error 1


Request you to pls give ur inputs.

Regards,
Marconi.

Last edited by marconi; 07-22-2008 at 04:06 PM..
  #4 (permalink)  
Old 07-23-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,912
Are you including the required headers for getlogin() and/or getpwuid()?

getlogin() requires <unistd.h>
getpwuid() requires <sys/types.h> and <pwd.h>
  #5 (permalink)  
Old 07-23-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
corrected syntax for getlogin
Code:
/* top of file */
#include <unistd.h>
/* ..... some of your code here down to line 101 */
strcpy(user , getlogin() );
  #6 (permalink)  
Old 07-24-2008
marconi marconi is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 41
Hi,

I had already added the 3 header files as suggested by murphy as follows :-

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <limits.h>
#include "ifile.h"
#include <libgen.h>
#include <stdlib.h>
#include <pwd.h>


The earlier code had cuserid() as follows :-

1) DISCARD strcpy(user , (char*) cuserid((char*)0));

As cuserid() is not a valid function in linux, I can use either getlogin() or getpwuid()

As per Jim's suggestion, if I put the code like this :-

2) DISCARD strcpy(user, getlogin());

I don't have any errors, as follows :-


$ gcc gapw.c
/tmp/cc6K9ODh.o(.text+0x21d): In function `main':
: undefined reference to `getprofilestring'
/tmp/cc6K9ODh.o(.text+0x2ec): In function `main':
: undefined reference to `getprofilestring'
collect2: ld returned 1 exit status

$ make clean
rm -f getkey.o ifile.o bitt.o getkey getapp \
putkey getall getappkeys gapw filetime filetime.o gapw.o bitt \
libExtRelan.so envi envi.o

$ make gapw
cc -c -o gapw.o gapw.c
cc -c -o ifile.o ifile.c
cc -o gapw gapw.o ifile.o -lc_r
/usr/bin/ld: cannot find -lc_r
collect2: ld returned 1 exit status
make: *** [gapw] Error 1

$


But, I think the logic will be changed when we compare the code at 1) and 2), above.

Also, when I do a gcc gapw.c, I still get the above errors, though there are no errors
when I do a make gapw.


Request you to please give your inputs.

Thanks a lot in advance.

Best Regards,
Marconi.
Sponsored Links
Closed Thread

Bookmarks

Tags
solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0