Functions

get_login_name.c File Reference

#include <stdlib.h>
#include <stdio.h>
#include "portability.h"
Include dependency graph for get_login_name.c:

Go to the source code of this file.

Functions

char * gs_get_login_name ()

Detailed Description

This file contains code to get a user's login name.

Definition in file get_login_name.c.


Function Documentation

char* gs_get_login_name (  ) 

Get the user's login name.

Returns:
newly allocated string containing the user's login name. NULL on failure.

Definition at line 22 of file get_login_name.c.

                          {
  char *name;

  if((name = getenv("LOGNAME")))
    return strdup(name);

  if((name = getenv("USER")))
    return strdup(name);

#ifdef HAVE_GETPWUID
# ifdef HAVE_GETEUID
  if((name = ((struct passwd *)getpwuid(geteuid()))->pw_name))
    return strdup(name);
# endif
#endif

#ifdef HAVE_GETLOGIN
  if((name = getlogin()))
    return strdup(name);
#endif

  return strdup("unknown");
}

Here is the caller graph for this function: