annotate toys/posix/logname.c @ 653:2986aa63a021

Move commands into "posix", "lsb", and "other" menus/directories.
author Rob Landley <rob@landley.net>
date Sat, 25 Aug 2012 14:25:22 -0500
parents toys/logname.c@d5fb52b428ed
children 6df4ccc0acbe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
568
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
2 *
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
3 * logname.c - Print user's login name.
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
4 *
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
5 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
6 *
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
7 * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/logname.html
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
8
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
9 USE_LOGNAME(NEWTOY(logname, ">0", TOYFLAG_BIN))
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
10
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
11 config LOGNAME
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
12 bool "logname"
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
13 default y
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
14 help
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
15 usage: logname
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
16
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
17 Prints the calling user's name or an error when this cannot be
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
18 determined.
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
19 */
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
20
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
21 #include "toys.h"
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
22
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
23 void logname_main(void)
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
24 {
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
25 if (getlogin_r(toybuf, sizeof(toybuf))){
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
26 error_exit("no login name");
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
27 }
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
28 xputs(toybuf);
d5fb52b428ed Adding logname
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
29 }