Code:
#include <unistd.h>
uid_t myuid(void)
{
return getuid();
}
No offense meant, but setuid is a major security risk. Don't go implementing your code on your system unless it is a home desktop that can be trashed.
setuid requires either root or the so-called sticky bit set to allow the program to change it's username.
It may seem simple but there is a lot to writing a setuid program:
http://nob.cs.ucdavis.edu/bishop/sec...sproglogin.pdf