~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to src/whoami.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* whoami -- print effective userid
2
2
 
3
 
   Copyright (C) 1989-1997, 1999-2002, 2004-2005, 2007-2011 Free Software
4
 
   Foundation, Inc.
 
3
   Copyright (C) 1989-2012 Free Software Foundation, Inc.
5
4
 
6
5
   This program is free software: you can redistribute it and/or modify
7
6
   it under the terms of the GNU General Public License as published by
16
15
   You should have received a copy of the GNU General Public License
17
16
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
17
 
19
 
/* Equivalent to `id -un'. */
 
18
/* Equivalent to 'id -un'. */
20
19
/* Written by Richard Mlynarik. */
21
20
 
22
21
#include <config.h>
30
29
#include "long-options.h"
31
30
#include "quote.h"
32
31
 
33
 
/* The official name of this program (e.g., no `g' prefix).  */
 
32
/* The official name of this program (e.g., no 'g' prefix).  */
34
33
#define PROGRAM_NAME "whoami"
35
34
 
36
35
#define AUTHORS proper_name ("Richard Mlynarik")
39
38
usage (int status)
40
39
{
41
40
  if (status != EXIT_SUCCESS)
42
 
    fprintf (stderr, _("Try `%s --help' for more information.\n"),
43
 
             program_name);
 
41
    emit_try_help ();
44
42
  else
45
43
    {
46
44
      printf (_("Usage: %s [OPTION]...\n"), program_name);
61
59
{
62
60
  struct passwd *pw;
63
61
  uid_t uid;
 
62
  uid_t NO_UID = -1;
64
63
 
65
64
  initialize_main (&argc, &argv);
66
65
  set_program_name (argv[0]);
81
80
      usage (EXIT_FAILURE);
82
81
    }
83
82
 
 
83
  errno = 0;
84
84
  uid = geteuid ();
85
 
  pw = getpwuid (uid);
 
85
  pw = (uid == NO_UID && errno ? NULL : getpwuid (uid));
86
86
  if (pw)
87
87
    {
88
88
      puts (pw->pw_name);