Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 396
Igor Avatar asked Dec 19 '22 22:12

Igor


1 Answers

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.

like image 52
Yu Hao Avatar answered Jan 01 '23 03:01

Yu Hao