?? library_2.html
字號(hào):
An operation that cannot complete immediately was initiated on an object
that has non-blocking mode selected.
<P>
<A NAME="IDX87"></A>
<U>Macro:</U> int <B>EALREADY</B><P>
An operation is already in progress on an object that has non-blocking
mode selected.
<P>
<A NAME="IDX88"></A>
<U>Macro:</U> int <B>ENOTSOCK</B><P>
A file that isn't a socket was specified when a socket is required.
<P>
<A NAME="IDX89"></A>
<U>Macro:</U> int <B>EDESTADDRREQ</B><P>
No destination address was supplied on a socket operation.
<P>
<A NAME="IDX90"></A>
<U>Macro:</U> int <B>EMSGSIZE</B><P>
The size of a message sent on a socket was larger than the supported
maximum size.
<P>
<A NAME="IDX91"></A>
<U>Macro:</U> int <B>EPROTOTYPE</B><P>
The socket type does not support the requested communications protocol.
<P>
<A NAME="IDX92"></A>
<U>Macro:</U> int <B>ENOPROTOOPT</B><P>
You specified a socket option that doesn't make sense for the
particular protocol being used by the socket. See section <A HREF="library_15.html#SEC264" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_15.html#SEC264">Socket Options</A>.
<P>
<A NAME="IDX93"></A>
<U>Macro:</U> int <B>EPROTONOSUPPORT</B><P>
The socket domain does not support the requested communications protocol.
See section <A HREF="library_15.html#SEC241" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_15.html#SEC241">Creating a Socket</A>.
<P>
<A NAME="IDX94"></A>
<U>Macro:</U> int <B>ESOCKTNOSUPPORT</B><P>
The socket type is not supported.
<P>
<A NAME="IDX95"></A>
<U>Macro:</U> int <B>EOPNOTSUPP</B><P>
The operation you requested is not supported. Some socket functions
don't make sense for all types of sockets, and others may not be implemented
for all communications protocols.
<P>
<A NAME="IDX96"></A>
<U>Macro:</U> int <B>EPFNOSUPPORT</B><P>
The socket communications protocol family you requested is not supported.
<P>
<A NAME="IDX97"></A>
<U>Macro:</U> int <B>EAFNOSUPPORT</B><P>
The address family specified for a socket is not supported; it is
inconsistent with the protocol being used on the socket. See section <A HREF="library_15.html#SEC216" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_15.html#SEC216">Sockets</A>.
<P>
<A NAME="IDX98"></A>
<U>Macro:</U> int <B>EADDRINUSE</B><P>
The requested socket address is already in use. See section <A HREF="library_15.html#SEC219" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_15.html#SEC219">Socket Addresses</A>.
<P>
<A NAME="IDX99"></A>
<U>Macro:</U> int <B>EADDRNOTAVAIL</B><P>
The requested socket address is not available; for example, you tried
to give a socket a name that doesn't match the local host name.
See section <A HREF="library_15.html#SEC219" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_15.html#SEC219">Socket Addresses</A>.
<P>
<A NAME="IDX100"></A>
<U>Macro:</U> int <B>ENETDOWN</B><P>
A socket operation failed because the network was down.
<P>
<A NAME="IDX101"></A>
<U>Macro:</U> int <B>ENETUNREACH</B><P>
A socket operation failed because the subnet containing the remost host
was unreachable.
<P>
<A NAME="IDX102"></A>
<U>Macro:</U> int <B>ENETRESET</B><P>
A network connection was reset because the remote host crashed.
<P>
<A NAME="IDX103"></A>
<U>Macro:</U> int <B>ECONNABORTED</B><P>
A network connection was aborted locally.
<P>
<A NAME="IDX104"></A>
<U>Macro:</U> int <B>ECONNRESET</B><P>
A network connection was closed for reasons outside the control of the
local host, such as by the remote machine rebooting.
<P>
<A NAME="IDX105"></A>
<U>Macro:</U> int <B>ENOBUFS</B><P>
The kernel's buffers for I/O operations are all in use.
<P>
<A NAME="IDX106"></A>
<U>Macro:</U> int <B>EISCONN</B><P>
You tried to connect a socket that is already connected.
See section <A HREF="library_15.html#SEC245" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_15.html#SEC245">Making a Connection</A>.
<P>
<A NAME="IDX107"></A>
<U>Macro:</U> int <B>ENOTCONN</B><P>
The socket is not connected to anything. You get this error when you
try to transmit data over a socket, without first specifying a destination
for the data.
<P>
<A NAME="IDX108"></A>
<U>Macro:</U> int <B>ESHUTDOWN</B><P>
The socket has already been shut down.
<P>
<A NAME="IDX109"></A>
<U>Macro:</U> int <B>ETIMEDOUT</B><P>
A socket operation with a specified timeout received no response during
the timeout period.
<P>
<A NAME="IDX110"></A>
<U>Macro:</U> int <B>ECONNREFUSED</B><P>
A remote host refused to allow the network connection (typically because
it is not running the requested service).
<P>
<A NAME="IDX111"></A>
<U>Macro:</U> int <B>ELOOP</B><P>
Too many levels of symbolic links were encountered in looking up a file name.
This often indicates a cycle of symbolic links.
<P>
<A NAME="IDX112"></A>
<U>Macro:</U> int <B>ENAMETOOLONG</B><P>
Filename too long (longer than <CODE>PATH_MAX</CODE>; see section <A HREF="library_27.html#SEC463" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_27.html#SEC463">Limits on File System Capacity</A>) or host name too long (in <CODE>gethostname</CODE> or
<CODE>sethostname</CODE>; see section <A HREF="library_26.html#SEC452" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_26.html#SEC452">Host Identification</A>).
<P>
<A NAME="IDX113"></A>
<U>Macro:</U> int <B>EHOSTDOWN</B><P>
The remote host for a requested network connection is down.
<P>
<A NAME="IDX114"></A>
<U>Macro:</U> int <B>EHOSTUNREACH</B><P>
The remote host for a requested network connection is not reachable.
<P>
<A NAME="IDX115"></A>
<U>Macro:</U> int <B>ENOTEMPTY</B><P>
Directory not empty, where an empty directory was expected. Typically,
this error occurs when you are trying to delete a directory.
<P>
<A NAME="IDX116"></A>
<U>Macro:</U> int <B>EUSERS</B><P>
The file quota system is confused because there are too many users.
<P>
<A NAME="IDX117"></A>
<U>Macro:</U> int <B>EDQUOT</B><P>
The user's disk quota was exceeded.
<P>
<A NAME="IDX118"></A>
<U>Macro:</U> int <B>ESTALE</B><P>
Stale NFS file handle. This indicates an internal confusion in the NFS
system which is due to file system rearrangements on the server host.
Repairing this condition usually requires unmounting and remounting
the NFS file system on the local host.
<P>
<A NAME="IDX119"></A>
<U>Macro:</U> int <B>EREMOTE</B><P>
An attempt was made to NFS-mount a remote file system with a file name that
already specifies an NFS-mounted file.
(This is an error on some operating systems, but we expect it to work
properly on the GNU system, making this error code impossible.)
<P>
<A NAME="IDX120"></A>
<U>Macro:</U> int <B>ENOLCK</B><P>
No locks available. This is used by the file locking facilities;
see section <A HREF="library_12.html#SEC185" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_12.html#SEC185">File Locks</A>.
<P>
<A NAME="IDX121"></A>
<U>Macro:</U> int <B>ENOSYS</B><P>
Function not implemented. Some functions have commands or options defined
that might not be supported in all implementations, and this is the kind
of error you get if you request them and they are not supported.
<P>
<A NAME="IDX122"></A>
<U>Macro:</U> int <B>ED</B><P>
The experienced user will know what is wrong.
<P>
<A NAME="IDX123"></A>
<U>Macro:</U> int <B>EGRATUITOUS</B><P>
This error code has no purpose.
<P>
<H2><A NAME="SEC17" HREF="library_toc.html#SEC17" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC17">Error Messages</A></H2>
<P>
The library has functions and variables designed to make it easy for
your program to report informative error messages in the customary
format about the failure of a library call. The functions
<CODE>strerror</CODE> and <CODE>perror</CODE> give you the standard error message
for a given error code; the variable
<CODE>program_invocation_short_name</CODE> gives you convenient access to the
name of the program that encountered the error.
<P>
<A NAME="IDX124"></A>
<U>Function:</U> char * <B>strerror</B> <I>(int <VAR>errnum</VAR>)</I><P>
The <CODE>strerror</CODE> function maps the error code (see section <A HREF="library_2.html#SEC15" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_2.html#SEC15">Checking for Errors</A>) specified by the <VAR>errnum</VAR> argument to a descriptive error
message string. The return value is a pointer to this string.
<P>
The value <VAR>errnum</VAR> normally comes from the variable <CODE>errno</CODE>.
<P>
You should not modify the string returned by <CODE>strerror</CODE>. Also, if
you make subsequent calls to <CODE>strerror</CODE>, the string might be
overwritten. (But it's guaranteed that no library function ever calls
<CODE>strerror</CODE> behind your back.)
<P>
The function <CODE>strerror</CODE> is declared in <TT>`string.h'</TT>.
<P>
<A NAME="IDX125"></A>
<U>Function:</U> void <B>perror</B> <I>(const char *<VAR>message</VAR>)</I><P>
This function prints an error message to the stream <CODE>stderr</CODE>;
see section <A HREF="library_11.html#SEC119" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_11.html#SEC119">Standard Streams</A>.
<P>
If you call <CODE>perror</CODE> with a <VAR>message</VAR> that is either a null
pointer or an empty string, <CODE>perror</CODE> just prints the error message
corresponding to <CODE>errno</CODE>, adding a trailing newline.
<P>
If you supply a non-null <VAR>message</VAR> argument, then <CODE>perror</CODE>
prefixes its output with this string. It adds a colon and a space
character to separate the <VAR>message</VAR> from the error string corresponding
to <CODE>errno</CODE>.
<P>
The function <CODE>perror</CODE> is declared in <TT>`stdio.h'</TT>.
<P>
<CODE>strerror</CODE> and <CODE>perror</CODE> produce the exact same message for any
given error code; the precise text varies from system to system. On the
GNU system, the messages are fairly short; there are no multi-line
messages or embedded newlines. Each error message begins with a capital
letter and does not include any terminating punctuation.
<P>
<STRONG>Compatibility Note:</STRONG> The <CODE>strerror</CODE> function is a new
feature of ANSI C. Many older C systems do not support this function
yet.
<A NAME="IDX126"></A>
<A NAME="IDX127"></A>
<P>
Many programs that don't read input from the terminal are designed to
exit if any system call fails. By convention, the error message from
such a program should start with the program's name, sans directories.
You can find that name in the variable
<CODE>program_invocation_short_name</CODE>; the full file name is stored the
variable <CODE>program_invocation_name</CODE>:
<P>
<A NAME="IDX128"></A>
<U>Variable:</U> char * <B>program_invocation_name</B><P>
This variable's value is the name that was used to invoke the program
running in the current process. It is the same as <CODE>argv[0]</CODE>.
<P>
<A NAME="IDX129"></A>
<U>Variable:</U> char * <B>program_invocation_short_name</B><P>
This variable's value is the name that was used to invoke the program
running in the current process, with directory names removed. (That is
to say, it is the same as <CODE>program_invocation_name</CODE> minus
everything up to the last slash, if any.)
<P>
Both <CODE>program_invocation_name</CODE> and
<CODE>program_invocation_short_name</CODE> are set up by the system before
<CODE>main</CODE> is called.
<P>
<STRONG>Portability Note:</STRONG> These two variables are GNU extensions. If
you want your program to work with non-GNU libraries, you must save the
value of <CODE>argv[0]</CODE> in <CODE>main</CODE>, and then strip off the directory
names yourself. We added these extensions to make it possible to write
self-contained error-reporting subroutines that require no explicit
cooperation from <CODE>main</CODE>.
<P>
Here is an example showing how to handle failure to open a file
correctly. The function <CODE>open_sesame</CODE> tries to open the named file
for reading and returns a stream if successful. The <CODE>fopen</CODE>
library function returns a null pointer if it couldn't open the file for
some reason. In that situation, <CODE>open_sesame</CODE> constructs an
appropriate error message using the <CODE>strerror</CODE> function, and
terminates the program. If we were going to make some other library
calls before passing the error code to <CODE>strerror</CODE>, we'd have to
save it in a local variable instead, because those other library
functions might overwrite <CODE>errno</CODE> in the meantime.
<P>
<PRE>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *
open_sesame (char *name)
{
FILE *stream;
errno = 0;
stream = fopen (name, "r");
if (!stream) {
fprintf (stderr, "%s: Couldn't open file %s; %s\n",
program_invocation_short_name, name, strerror (errno));
exit (EXIT_FAILURE);
} else
return stream;
}
</PRE>
<P>
<P>Go to the <A HREF="library_1.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_1.html">previous</A>, <A HREF="library_3.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_3.html">next</A> section.<P>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -