?? library_26.html
字號(hào):
<!-- This HTML file has been created by texi2html 1.27
from library.texinfo on 3 March 1994 -->
<TITLE>The GNU C Library - System Information</TITLE>
<P>Go to the <A HREF="library_25.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_25.html">previous</A>, <A HREF="library_27.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_27.html">next</A> section.<P>
<H1><A NAME="SEC451" HREF="library_toc.html#SEC451" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC451">System Information</A></H1>
<P>
This chapter describes functions that return information about the
particular machine that is in use--the type of hardware, the type of
software, and the individual machine's name.
<P>
<H2><A NAME="SEC452" HREF="library_toc.html#SEC452" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC452">Host Identification</A></H2>
<P>
This section explains how to identify the particular machine that your
program is running on. The identification of a machine consists of its
Internet host name and Internet address; see section <A HREF="library_15.html#SEC227" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_15.html#SEC227">The Internet Namespace</A>.
<A NAME="IDX1846"></A>
<A NAME="IDX1847"></A>
<A NAME="IDX1848"></A>
<P>
Prototypes for these functions appear in <TT>`unistd.h'</TT>. The shell
commands <CODE>hostname</CODE> and <CODE>hostid</CODE> work by calling them.
<P>
<A NAME="IDX1849"></A>
<U>Function:</U> int <B>gethostname</B> <I>(char *<VAR>name</VAR>, size_t <VAR>size</VAR>)</I><P>
This function returns the name of the host machine in the array
<VAR>name</VAR>. The <VAR>size</VAR> argument specifies the size of this array,
in bytes.
<P>
The return value is <CODE>0</CODE> on success and <CODE>-1</CODE> on failure. In
the GNU C library, <CODE>gethostname</CODE> fails if <VAR>size</VAR> is not large
enough; then you can try again with a larger array. The following
<CODE>errno</CODE> error condition is defined for this function:
<P>
<DL COMPACT>
<DT><CODE>ENAMETOOLONG</CODE>
<DD>The <VAR>size</VAR> argument is less than the size of the host name plus one.
</DL>
<A NAME="IDX1850"></A>
<P>
On some systems, there is a symbol for the maximum possible host name
length: <CODE>MAXHOSTNAMELEN</CODE>. It is defined in <TT>`sys/param.h'</TT>.
But you can't count on this to exist, so it is cleaner to handle
failure and try again.
<P>
<CODE>gethostname</CODE> stores the beginning of the host name in <VAR>name</VAR>
even if the host name won't entirely fit. For some purposes, a
truncated host name is good enough. If it is, you can ignore the
error code.
<P>
<A NAME="IDX1851"></A>
<U>Function:</U> int <B>sethostname</B> <I>(const char *<VAR>name</VAR>, size_t <VAR>length</VAR>)</I><P>
The <CODE>sethostname</CODE> function sets the name of the host machine to
<VAR>name</VAR>, a string with length <VAR>length</VAR>. Only privileged
processes are allowed to do this. Usually it happens just once, at
system boot time.
<P>
The return value is <CODE>0</CODE> on success and <CODE>-1</CODE> on failure.
The following <CODE>errno</CODE> error condition is defined for this function:
<P>
<DL COMPACT>
<DT><CODE>EPERM</CODE>
<DD>This process cannot set the host name because it is not privileged.
</DL>
<P>
<A NAME="IDX1852"></A>
<U>Function:</U> long int <B>gethostid</B> <I>(void)</I><P>
This function returns the Internet address of the machine the program is
running on.
<P>
<A NAME="IDX1853"></A>
<U>Function:</U> int <B>sethostid</B> <I>(long int <VAR>id</VAR>)</I><P>
The <CODE>sethostid</CODE> function sets the address of the host machine to
<VAR>id</VAR>. Only privileged processes are allowed to do this. Usually it
happens just once, at system boot time.
<P>
The return value is <CODE>0</CODE> on success and <CODE>-1</CODE> on failure.
The following <CODE>errno</CODE> error condition is defined for this function:
<P>
<DL COMPACT>
<DT><CODE>EPERM</CODE>
<DD>This process cannot set the host name because it is not privileged.
</DL>
<P>
<H2><A NAME="SEC453" HREF="library_toc.html#SEC453" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC453">Hardware/Software Type Identification</A></H2>
<P>
You can use the <CODE>uname</CODE> function to find out some information about
the type of computer your program is running on. This function and the
associated data type are declared in the header file
<TT>`sys/utsname.h'</TT>.
<A NAME="IDX1854"></A>
<P>
<A NAME="IDX1855"></A>
<U>Data Type:</U> <B>struct utsname</B><P>
The <CODE>utsname</CODE> structure is used to hold information returned
by the <CODE>uname</CODE> function. It has the following members:
<P>
<DL COMPACT>
<DT><CODE>char sysname[]</CODE>
<DD>This is the name of the operating system in use.
<P>
<DT><CODE>char nodename[]</CODE>
<DD>This is the network name of this particular computer. In the GNU
library, the value is the same as that returned by <CODE>gethostname</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>
<DT><CODE>char release[]</CODE>
<DD>This is the current release level of the operating system implementation.
<P>
<DT><CODE>char version[]</CODE>
<DD>This is the current version level within the release of the operating
system.
<P>
<DT><CODE>char machine[]</CODE>
<DD>This is a description of the type of hardware that is in use.
<P>
The GNU C Library fills in this field based on the configuration name
that was specified when building and installing the library. GNU uses a
three-part name to describe a system configuration; the three parts are
<VAR>cpu</VAR>, <VAR>manufacturer</VAR> and <VAR>system-type</VAR>, and they are
separated with dashes. Any possible combination of three names is
potentially meaningful, but most such combinations are meaningless in
practice and even the meaningful ones are not necessarily supported by
any particular GNU program.
<P>
Since the value in <CODE>machine</CODE> is supposed to describe just the
hardware, it consists of the first two parts of the configuration name:
<SAMP>`<VAR>cpu</VAR>-<VAR>manufacturer</VAR>'</SAMP>.
<P>
Here is a list of all the possible alternatives:
<P>
<BLOCKQUOTE>
<CODE>"i386-<VAR>anything</VAR>"</CODE>, <CODE>"m68k-hp"</CODE>, <CODE>"sparc-sun"</CODE>,
<CODE>"m68k-sun"</CODE>, <CODE>"m68k-sony"</CODE>, <CODE>"mips-dec"</CODE>
</BLOCKQUOTE>
</DL>
<P>
<A NAME="IDX1856"></A>
<U>Function:</U> int <B>uname</B> <I>(struct utsname *<VAR>info</VAR>)</I><P>
The <CODE>uname</CODE> function fills in the structure pointed to by
<VAR>info</VAR> with information about the operating system and host machine.
A non-negative value indicates that the data was successfully stored.
<P>
<CODE>-1</CODE> as the value indicates an error. The only error possible is
<CODE>EFAULT</CODE>, which we normally don't mention as it is always a
possibility.
<P>
<P>Go to the <A HREF="library_25.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_25.html">previous</A>, <A HREF="library_27.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_27.html">next</A> section.<P>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -