20 |
* a diagnostic message and an error return. |
* a diagnostic message and an error return. |
21 |
*/ |
*/ |
22 |
|
|
23 |
#include <stdio.h> |
#include "libbb.h" |
|
#include <stdlib.h> |
|
|
#include <unistd.h> |
|
|
#include "busybox.h" |
|
24 |
|
|
25 |
int logname_main(int argc, char ATTRIBUTE_UNUSED **argv) |
/* This is a NOFORK applet. Be very careful! */ |
26 |
|
|
27 |
|
int logname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
28 |
|
int logname_main(int argc, char **argv UNUSED_PARAM) |
29 |
{ |
{ |
30 |
const char *p; |
char buf[128]; |
31 |
|
|
32 |
if (argc > 1) { |
if (argc > 1) { |
33 |
bb_show_usage(); |
bb_show_usage(); |
34 |
} |
} |
35 |
|
|
36 |
if ((p = getlogin()) != NULL) { |
/* Using _r function - avoid pulling in static buffer from libc */ |
37 |
puts(p); |
if (getlogin_r(buf, sizeof(buf)) == 0) { |
38 |
fflush_stdout_and_exit(EXIT_SUCCESS); |
puts(buf); |
39 |
|
return fflush(stdout); |
40 |
} |
} |
41 |
|
|
42 |
bb_perror_msg_and_die("getlogin"); |
bb_perror_msg_and_die("getlogin"); |