xref: /haiku/src/bin/logname.c (revision 99d1318ec02694fc520a0dc38ae38565db7e8c3c)
1 /*
2  * Haiku Command line apps
3  * logname.c
4  * Larry Cow <larrycow@free.fr>
5  */
6 
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 
11 #define DEFAULT_USER "baron"
12 
13 #define HELP_TIP "Try '%s --help' for more information.\n"
14 
15 #define HELP_MESSAGE "Usage: /bin/logname [OPTION]...
16 Print the name of the current
17 
18   --help\t display this help and exit
19   --version\t output version information and exit
20 
21 Reports bugs to <larrycow@free.fr>."
22 
23 #define VERSION_MESSAGE "logname (OBOS) 1.0
24 Written by Larry Cow
25 
26 Coded by Larry Cow 2002
27 Released under the MIT license with Haiku."
28 
29 void dispatch_args(char* av0, char* av1)
30 {
31 	if (!strcmp(av1, "--help"))
32 	{
33 		puts(HELP_MESSAGE);
34 		return;
35 	}
36 	if (!strcmp(av1, "--version"))
37 	{
38 		puts(VERSION_MESSAGE);
39 		return;
40 	}
41 	printf(HELP_TIP, av0);
42 }
43 
44 int main(int argc, char* argv[])
45 {
46 	if (argc > 1)
47 		dispatch_args(argv[0], argv[1]);
48 	else
49 	{
50 		char* user = getenv("USER");
51 		if (user == NULL)
52 			puts(DEFAULT_USER);
53 		else
54 			puts(user);
55 	}
56 	return 0;
57 }
58