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 &lt;stdio.h&gt;

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[] =

     {

       {&quot;add&quot;, 1, 0, 0},

       {&quot;append&quot;, 0, 0, 0},

       {&quot;delete&quot;, 1, 0, 0},

       {&quot;verbose&quot;, 0, 0, 0},

       {&quot;create&quot;, 1, 0, `c'},

       {&quot;file&quot;, 1, 0, 0g, f0, 0, 0, 0}

     };

     c = getopt_long (argc, argv, &quot;abc:d:012&quot;,

       long_options, &amp;option_index);

     if (c == -1)

       break;

     switch(c)

     {

       case 0:

         printf (&quot;option %s&quot;, long_options[option_index].name);

         if (optarg)

           printf (&quot; with arg %s&quot;, optarg);

         printf (&quot;\n&quot;);

         break;

       case `0':

       case `1':

       case `2':

         if (digit_optind != 0 &amp;&amp; digit_optind != this_option_optind)

           printf (&quot;digits occur in two different argv-elements.\n&quot;);

            digit_optind = this_option_optind;

         printf (&quot;option %c\n&quot;, c);

         break;

       case `a':

         printf (&quot;option a\n&quot;);

         break;

       case `b':

</PRE>

<!-- END CODE //-->





<A NAME="PAGENUM-940"><P>Page 940</P></A>





<!-- CODE //-->

<PRE>

         printf (&quot;option b\n&quot;);

         break;

       case `c':

         printf (&quot;option c with value `%s'\n&quot;, optarg);

         break;

       case `d':

         printf (&quot;option d with value `%s' \n&quot;, optarg);

         break;

       case `?':

         break;

       default:

         printf (&quot;?? getopt returned character code 0%o ??\n&quot;, c);

     }

   }

   if (optind &lt; argc)

   {

     printf (&quot;non-option ARGV-elements: &quot;);

     while (optind &lt; argc)

       printf (&quot;%s &quot;, argv[optind++]);

     printf (&quot;\n&quot;);

   }

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&#151;Gets a password</P>



<P><B>SYNOPSIS

</P></B>



<!-- CODE SNIP //-->

<PRE>

#include &lt;pwd.h&gt;

#include &lt;unistd.h&gt;

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&amp;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&#151;Get protocol entry</P>



<P><B>SYNOPSIS

</P></B>



<!-- CODE //-->

<PRE>

#include &lt;netdb.h&gt;

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

&lt;netdb.h&gt; 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&#151;Reconstructs password line entry</P>



<P><B>SYNOPSIS

</P></B>



<!-- CODE SNIP //-->

<PRE>

#include &lt;pwd.h&gt;

#include &lt;sys/types.h&gt;

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

&lt;pwd.h&gt; 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 + -
显示快捷键?