Jari Aalto | b72432f | 1999-02-19 17:11:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * whoami - print out username of current user |
| 3 | */ |
| 4 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 5 | /* |
| 6 | Copyright (C) 1999-2009 Free Software Foundation, Inc. |
| 7 | |
| 8 | This file is part of GNU Bash. |
| 9 | Bash is free software: you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation, either version 3 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | Bash is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with Bash. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ |
| 22 | |
Jari Aalto | b72432f | 1999-02-19 17:11:39 +0000 | [diff] [blame] | 23 | #include <config.h> |
| 24 | #include <stdio.h> |
| 25 | |
| 26 | #include "builtins.h" |
| 27 | #include "shell.h" |
| 28 | #include "bashgetopt.h" |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 29 | #include "common.h" |
Jari Aalto | b72432f | 1999-02-19 17:11:39 +0000 | [diff] [blame] | 30 | |
| 31 | whoami_builtin (list) |
| 32 | WORD_LIST *list; |
| 33 | { |
| 34 | int opt; |
| 35 | |
| 36 | reset_internal_getopt (); |
| 37 | while ((opt = internal_getopt (list, "")) != -1) |
| 38 | { |
| 39 | switch (opt) |
| 40 | { |
| 41 | default: |
| 42 | builtin_usage (); |
| 43 | return (EX_USAGE); |
| 44 | } |
| 45 | } |
| 46 | list = loptend; |
| 47 | if (list) |
| 48 | { |
| 49 | builtin_usage (); |
| 50 | return (EX_USAGE); |
| 51 | } |
| 52 | |
| 53 | if (current_user.user_name == 0) |
| 54 | get_current_user_info (); |
| 55 | printf ("%s\n", current_user.user_name); |
| 56 | return (EXECUTION_SUCCESS); |
| 57 | } |
| 58 | |
| 59 | char *whoami_doc[] = { |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 60 | "Print user name", |
| 61 | "", |
| 62 | "Display name of current user.", |
Jari Aalto | b72432f | 1999-02-19 17:11:39 +0000 | [diff] [blame] | 63 | (char *)NULL |
| 64 | }; |
| 65 | |
| 66 | struct builtin whoami_struct = { |
| 67 | "whoami", |
| 68 | whoami_builtin, |
| 69 | BUILTIN_ENABLED, |
| 70 | whoami_doc, |
| 71 | "whoami", |
| 72 | 0 |
| 73 | }; |