Here you have it:

#include <sys/types.h>
#include <errno.h>
#include <pwd.h>
#include <stdio.h>

int
main(int argc, char **argv)
{
        struct passwd   *p;
        int             e;

        e = errno, errno = 0;
        p = getpwuid(0);
        if (errno) {
                fprintf(stdout, "errno is: %u\n", errno);
                return 127;
        }
        errno = e;

        if (p) fprintf(stdout, "%s\n", p->pw_name);
        return 0;
}

Reply via email to