Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
947 views
in Technique[技术] by (71.8m points)

c - warning: implicit declaration of function ‘getresuid’ (and ‘seteuid’)

I would like to get rid of the warnings. When I compile the source code with

gcc -Wall -ansi -o test test.c  

I get back

test.c: In function ‘main’:
test.c:12: warning: implicit declaration of function ‘getresuid’
test.c:14: warning: implicit declaration of function ‘seteuid’

When I compile it without -ansi switch

gcc -Wall -o test test.c 

I see on the terminal

test.c: In function ‘main’:
test.c:12: warning: implicit declaration of function ‘getresuid’

I would like to use -ansi switch and get rid of warnings. How can I achieve my goal ?

/*  this is the test.c */
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

#define __USE_GNU 1
#define __USE_BSD 1

int main()
{
   static uid_t euid, ruid, suid;

   getresuid(&ruid, &euid, &suid);  

   seteuid(getuid()); 

   return 0;
}

Environment:

CentOS 6.3 32-bit
gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

getresuid() and seteuid() are GNU extension function, add

#define _GNU_SOURCE

before including all the headers, or add -D_GNU_SOURCE in GCC options.

You shouldn't define __USE_GNU macro directly, it's supposed to be used only internally in glibc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...