0939-0942.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 425 行
HTML
425 行
<HTML>
<HEAD>
<TITLE>Linux Complete Command Reference:Library Functions:EarthWeb Inc.-</TITLE>
</HEAD>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311046 //-->
<!-- TITLE=Linux Complete Command Reference//-->
<!-- AUTHOR=Red Hat//-->
<!-- PUBLISHER=Macmillan Computer Publishing//-->
<!-- IMPRINT=Sams//-->
<!-- CHAPTER=03 //-->
<!-- PAGES=0891-1062 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0937-0938.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0943-0945.html">Next</A></CENTER></P>
<A NAME="PAGENUM-939"><P>Page 939</P></A>
<P><B>RETURN VALUE
</P></B>
<P>The getopt()function returns the option character if the option was found successfully,
: if there was a missing parameter for one of the options,
? for an unknown option character, or EOF for the end of the option list.</P>
<P>getopt_long() and getopt_long_only() also return the option character when a short option is recognized. For a long
option, they return val if flag is NULL, and 0 otherwise. Error and
EOF returns are the same as for getopt(), plus ? for an
ambiguous match or an extraneous parameter.</P>
<P><B>
ENVIROMENT VARIABLES
</P></B>
<TABLE>
<TR><TD>
POSIXLY_CORRECT
</TD><TD>
If this is set, option processing stops as soon as a non-option argument is encountered.
</TD></TR></TABLE>
<P><B>
EXAMPLE
</P></B>
<P>The following example program, from the source code, illustrates the use of
getopt_long() with most of its features:</P>
<!-- CODE //-->
<PRE>
#include <stdio.h>
int
main (argc, argv)
int argc;
char **argv;
{
int c;
int digit_optind = 0;
while (1)
{
int this_option_optind = optind ? optind : 1;
int option_index = 0;
static struct option long_options[] =
{
{"add", 1, 0, 0},
{"append", 0, 0, 0},
{"delete", 1, 0, 0},
{"verbose", 0, 0, 0},
{"create", 1, 0, `c'},
{"file", 1, 0, 0g, f0, 0, 0, 0}
};
c = getopt_long (argc, argv, "abc:d:012",
long_options, &option_index);
if (c == -1)
break;
switch(c)
{
case 0:
printf ("option %s", long_options[option_index].name);
if (optarg)
printf (" with arg %s", optarg);
printf ("\n");
break;
case `0':
case `1':
case `2':
if (digit_optind != 0 && digit_optind != this_option_optind)
printf ("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf ("option %c\n", c);
break;
case `a':
printf ("option a\n");
break;
case `b':
</PRE>
<!-- END CODE //-->
<A NAME="PAGENUM-940"><P>Page 940</P></A>
<!-- CODE //-->
<PRE>
printf ("option b\n");
break;
case `c':
printf ("option c with value `%s'\n", optarg);
break;
case `d':
printf ("option d with value `%s' \n", optarg);
break;
case `?':
break;
default:
printf ("?? getopt returned character code 0%o ??\n", c);
}
}
if (optind < argc)
{
printf ("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
printf ("\n");
}
exit (0);
}
</PRE>
<!-- END CODE //-->
<P><B>BUGS
</P></B>
<P>This man page is confusing.</P>
<P><B>CONFORMS TO
</P></B>
<TABLE>
<TR><TD>
getopt():
</TD><TD>
POSIX.1, provided the environment variable
POSIXLY_CORRECT is set. Otherwise, the elements of
argv aren't really const, because they get permuted. They're set
const in the prototype to be compatible with other systems.
</TD></TR></TABLE>
<P>GNU, 30 August 1995</P>
<H3><A NAME="ch03_ 85">
getpass
</A></H3>
<P>getpass—Gets a password</P>
<P><B>SYNOPSIS
</P></B>
<!-- CODE SNIP //-->
<PRE>
#include <pwd.h>
#include <unistd.h>
char *getpass( const char * prompt );
</PRE>
<!-- END CODE SNIP //-->
<P><B>DESCRIPTION
</P></B>
<P>The getpass function displays a prompt to, and reads in, a password from,
/dev/tty. If this file is not accessible, getpass displays the prompt on the standard error output and reads from the standard input.</P>
<P>The password may be up to _PASSWORD_LEN (currently 128) characters in length. Any additional characters and the
terminating newline character are discarded. (This might be different in Linux.)</P>
<P>getpass turns off character echoing while reading the password.</P>
<P><B>RETURN VALUE
</P></B>
<P>getpass returns a pointer to the null-terminated password.</P>
<A NAME="PAGENUM-941"><P>Page 941</P></A>
<P><B>
FILES
</P></B>
<!-- CODE SNIP //-->
<PRE>
/dev/tty
</PRE>
<!-- END CODE SNIP //-->
<P></B>SEE ALSO
</P></B>
<P>crypt(3)
<P><B>
HISTORY
</P></B>
<P>A getpass function appeared in Version 7 AT&T UNIX.</P>
<P><B>BUGS
</P></B>
<P>The getpass function leaves its result in an internal static object and returns a pointer to that object. Subsequent calls
to getpass will modify the same object.</P>
<P>The calling process should zero the password as soon as possible to avoid leaving the cleartext password visible in
the process's address space.</P>
<P>BSD Man Page 29 November 1993</P>
<H3><A NAME="ch03_ 86">
getprotoent, getprotobyname, getprotobynumber,<BR>
setprotoent, endprotoent
</A></H3>
<P>getprotoent, getprotobyname, getprotobynumber,
setprotoent, endprotoent—Get protocol entry</P>
<P><B>SYNOPSIS
</P></B>
<!-- CODE //-->
<PRE>
#include <netdb.h>
struct protoent *getprotoent(void);
struct protoent *getprotobyname(const char *name);
struct protoent *getprotobynumber(int proto);
void setprotoent(int stayopen);
void endprotoent(void);
</PRE>
<!-- END CODE //-->
<P><B>DESCRIPTION
</P></B>
<P>The getprotoent() function reads the next line from the file
/etc/protocols and returns a structure protoent containing
the broken-out fields from the line. The
/etc/protocols file is opened if necessary.</P>
<P>The getprotobyname() function returns a
protoent structure for the line from
/etc/protocols that matches the protocol name name.</P>
<P>The getprotobynumber() function returns a
protoent structure for the line that matches the protocol number
number.</P>
<P>The setprotoent() function opens and rewinds the
/etc/protocols file. If stayopen is true (1), the file will not be
closed between calls to getprotobyname() or
getprotobynumber().</P>
<P>The endprotoent() function closes
/etc/protocols.</P>
<P>The protoent structure is defined in
<netdb.h> as follows:</P>
<!-- CODE //-->
<PRE>
struct protoent {
char *p_name; /* official protocol name */
char **p_aliases; /* alias list */
int p_proto; /* protocol number */
}
</PRE>
<!-- END CODE //-->
<A NAME="PAGENUM-942"><P>Page 942</P></A>
<P>The members of the protoent structure are</P>
<TABLE>
<TR><TD>
p_name
</TD><TD>
The official name of the protocol.
</TD></TR><TR><TD>
p_aliases
</TD><TD>
A zero-terminated list of alternative names for the protocol.
</TD></TR><TR><TD>
p_proto
</TD><TD>
The protocol number.
</TD></TR></TABLE>
<P><B>RETURN VALUE
</P></B>
<P>The getprotoent(), getprotobyname(), and
getprotobynumber() functions return the protoent structure, or a
NULL pointer if an error occurs or the end of the file is reached.</P>
<P><B>
FILES
</P></B>
<P>/etc/protocols protocol database file</P>
<P><B>CONFORMS TO
</P></B>
<P>BSD 4.3</P>
<P></B>SEE ALSO
</P></B>
<P>getservent(3), getnetent(3), protocols(5)</P>
<P>BSD, 24 April 1993</P>
<H3><A NAME="ch03_ 87">
getpw
</A></H3>
<P>getpw—Reconstructs password line entry</P>
<P><B>SYNOPSIS
</P></B>
<!-- CODE SNIP //-->
<PRE>
#include <pwd.h>
#include <sys/types.h>
int getpw(uid_t uid, char *buf);
</PRE>
<!-- END CODE SNIP //-->
<P><B>DESCRIPTION
</P></B>
<P>The getpw() function reconstructs the password line entry for the given user UID
uid in the buffer buf. The returned buffer contains a line of format</P>
<!-- CODE SNIP //-->
<PRE>
name:passwd:uid:gid:gecos:dir:shell
</PRE>
<!-- END CODE SNIP //-->
<P>The passwd structure is defined in
<pwd.h> as follows:</P>
<!-- CODE //-->
<PRE>
struct passwd {
char *pw_name; /*username*/
char *pw_passwd; /* user password */
uid_t pw_uid; /* user id */
gid_t pw_gid; /* group id */
char *pw_gecos; /* real name */
char *pw_dir; /* home directory */
char *pw_shell; /* shell program */
};
</PRE>
<!-- END CODE //-->
<P><B>RETURN VALUE
</P></B>
<P>The getpw()function returns 0 on success, or _1 if an error occurs.</P>
<P><B>ERRORS
</P></B>
<TABLE>
<TR><TD>
ENOMEM
</TD><TD>
Insufficient memory to allocate passwd structure.
</TD></TR></TABLE>
<P><CENTER>
<a href="0937-0938.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0943-0945.html">Next</A></CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?