Function: user-full-name

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

Signature

(user-full-name &optional UID)

Documentation

Return the full name of the user logged in, as a string.

If the full name corresponding to Emacs's userid is not known, return "unknown".

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

If the full name includes commas, remove everything starting with the first comma, because the 'gecos' field of the '/etc/passwd' file is in general a comma-separated list.

View in manual

Probably introduced at or before Emacs version 19.29.

Source Code

// Defined in /usr/src/emacs/src/editfns.c
{
  struct passwd *pw;
  register char *p, *q;
  Lisp_Object full;

  if (NILP (uid))
    return Vuser_full_name;
  else if (NUMBERP (uid))
    {
      uid_t u;
      CONS_TO_INTEGER (uid, uid_t, u);
      block_input ();
      pw = getpwuid (u);
      unblock_input ();
    }
  else if (STRINGP (uid))
    {
      block_input ();
      pw = getpwnam (SSDATA (uid));
      unblock_input ();
    }
  else
    error ("Invalid UID specification");

  if (!pw)
    return Qnil;

  p = USER_FULL_NAME;
  /* Chop off everything after the first comma, since 'pw_gecos' is a
     comma-separated list. */
  q = strchr (p, ',');
  full = make_string (p, q ? q - p : strlen (p));

#ifdef AMPERSAND_FULL_NAME
  p = SSDATA (full);
  q = strchr (p, '&');
  /* Substitute the login name for the &, upcasing the first character.  */
  if (q)
    {
      Lisp_Object login = Fuser_login_name (INT_TO_INTEGER (pw->pw_uid));
      if (!NILP (login))
	{
	  USE_SAFE_ALLOCA;
	  char *r = SAFE_ALLOCA (strlen (p) + SBYTES (login) + 1);
	  memcpy (r, p, q - p);
	  char *s = lispstpcpy (&r[q - p], login);
	  r[q - p] = upcase ((unsigned char) r[q - p]);
	  strcpy (s, q + 1);
	  full = build_string (r);
	  SAFE_FREE ();
	}
    }
#endif /* AMPERSAND_FULL_NAME */

  return full;
}