1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1992-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A/*
1N/A * David Korn
1N/A * AT&T Research
1N/A *
1N/A * logname
1N/A */
1N/A
1N/Astatic const char usage[] =
1N/A"[-?\n@(#)$Id: logname (AT&T Research) 1999-04-30 $\n]"
1N/AUSAGE_LICENSE
1N/A"[+NAME?logname - return the user's login name]"
1N/A"[+DESCRIPTION?\blogname\b writes the users's login name to standard "
1N/A "output. The login name is the string that is returned by the "
1N/A "\bgetlogin\b(2) function. If \bgetlogin\b(2) does not return "
1N/A "successfully, the corresponding to the real user id of the calling "
1N/A "process is used instead.]"
1N/A
1N/A"\n"
1N/A"\n\n"
1N/A"\n"
1N/A"[+EXIT STATUS?]{"
1N/A "[+0?Successful Completion.]"
1N/A "[+>0?An error occurred.]"
1N/A"}"
1N/A"[+SEE ALSO?\bgetlogin\b(2)]"
1N/A;
1N/A
1N/A
1N/A#include <cmd.h>
1N/A
1N/Aint
1N/Ab_logname(int argc, char** argv, void* context)
1N/A{
1N/A register char* logname;
1N/A
1N/A cmdinit(argc, argv, context, ERROR_CATALOG, 0);
1N/A for (;;)
1N/A {
1N/A switch (optget(argv, usage))
1N/A {
1N/A case ':':
1N/A error(2, "%s", opt_info.arg);
1N/A continue;
1N/A case '?':
1N/A error(ERROR_usage(2), "%s", opt_info.arg);
1N/A continue;
1N/A }
1N/A break;
1N/A }
1N/A if (error_info.errors)
1N/A error(ERROR_usage(2), "%s", optusage(NiL));
1N/A if (!(logname = getlogin()))
1N/A logname = fmtuid(getuid());
1N/A sfputr(sfstdout, logname, '\n');
1N/A return 0;
1N/A}
1N/A