Function: user-login-name

user-login-name is a function defined in editfns.c.

Signature

(user-login-name &optional UID)

Documentation

Return the name under which the user logged in, as a string.

This is based on the effective uid, not the real uid. Also, if the environment variables LOGNAME or USER are set, that determines the value of this function.

If optional argument UID is an integer, return the login name of the user with that uid, or nil if there is no such user.

Probably introduced at or before Emacs version 14.

Aliases

user-original-login-name (obsolete since 28.1) eshell-user-name (obsolete since 28.1)

Source Code

// Defined in /usr/src/emacs/src/editfns.c
{
  struct passwd *pw;
  uid_t id;

  /* Set up the user name info if we didn't do it before.
     (That can happen if Emacs is dumpable
     but you decide to run `temacs -l loadup' and not dump.  */
  if (NILP (Vuser_login_name))
    init_editfns ();

  if (NILP (uid))
    return Vuser_login_name;

  CONS_TO_INTEGER (uid, uid_t, id);
  block_input ();
  pw = getpwuid (id);
  unblock_input ();
  return (pw ? build_string (pw->pw_name) : Qnil);
}