📄 library_10.html
字号:
<A NAME="IDX427"></A>
<A NAME="IDX428"></A>
<P>
A <DFN>directory</DFN> is a file that contains information to associate other
files with names; these associations are called <DFN>links</DFN> or
<DFN>directory entries</DFN>. Sometimes, people speak of "files in a
directory", but in reality, a directory only contains pointers to
files, not the files themselves.
<A NAME="IDX429"></A>
<P>
The name of a file contained in a directory entry is called a <DFN>file
name component</DFN>. In general, a file name consists of a sequence of one
or more such components, separated by the slash character (<SAMP>`/'</SAMP>). A
file name which is just one component names a file with respect to its
directory. A file name with multiple components names a directory, and
then a file in that directory, and so on.
<P>
Some other documents, such as the POSIX standard, use the term
<DFN>pathname</DFN> for what we call a file name, and either
<DFN>filename</DFN> or <DFN>pathname component</DFN> for what this manual calls a
file name component. We don't use this terminology because a "path"
is something completely different (a list of directories to search), and
we think that "pathname" used for something else will confuse users.
We always use "file name" and "file name component" (or sometimes
just "component", where the context is obvious) in GNU documentation.
<P>
You can find more detailed information about operations on directories
in section <A HREF="library_13.html#SEC187" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_13.html#SEC187">File System Interface</A>.
<P>
<H3><A NAME="SEC114" HREF="library_toc.html#SEC114" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC114">File Name Resolution</A></H3>
<P>
A file name consists of file name components separated by slash
(<SAMP>`/'</SAMP>) characters. On the systems that that GNU library supports,
multiple successive <SAMP>`/'</SAMP> characters are equivalent to a single
<SAMP>`/'</SAMP> character.
<A NAME="IDX430"></A>
<P>
The process of determining what file a file name refers to is called
<DFN>file name resolution</DFN>. This is performed by examining the
components that make up a file name in left-to-right order, and locating
each successive component in the directory named by the previous
component. Of course, each of the files that are referenced as
directories must actually exist, be directories instead of regular
files, and have the appropriate permissions to be accessible by the
process; otherwise the file name resolution fails.
<A NAME="IDX431"></A>
<A NAME="IDX432"></A>
<P>
If a file name begins with a <SAMP>`/'</SAMP>, the first component in the file
name is located in the <DFN>root directory</DFN> of the process. Such a file
name is called an <DFN>absolute file name</DFN>.
<A NAME="IDX433"></A>
<P>
Otherwise, the first component in the file name is located in the
current working directory (see section <A HREF="library_13.html#SEC188" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_13.html#SEC188">Working Directory</A>). This kind of
file name is called a <DFN>relative file name</DFN>.
<A NAME="IDX434"></A>
<P>
The file name components <TT>`.'</TT> ("dot") and <TT>`..'</TT> ("dot-dot")
have special meanings. Every directory has entries for these file name
components. The file name component <TT>`.'</TT> refers to the directory
itself, while the file name component <TT>`..'</TT> refers to its
<DFN>parent directory</DFN> (the directory that contains the link for the
directory in question).
<P>
Here are some examples of file names:
<P>
<DL COMPACT>
<DT><TT>`/a'</TT>
<DD>The file named <TT>`a'</TT>, in the root directory.
<P>
<DT><TT>`/a/b'</TT>
<DD>The file named <TT>`b'</TT>, in the directory named <TT>`a'</TT> in the root directory.
<P>
<DT><TT>`a'</TT>
<DD>The file named <TT>`a'</TT>, in the current working directory.
<P>
<DT><TT>`/a/./b'</TT>
<DD>This is the same as <TT>`/a/b'</TT>.
<P>
<DT><TT>`./a'</TT>
<DD>The file named <TT>`a'</TT>, in the current working directory.
<P>
<DT><TT>`../a'</TT>
<DD>The file named <TT>`a'</TT>, in the parent directory of the current working
directory.
</DL>
<P>
A file name that names a directory may optionally end in a <SAMP>`/'</SAMP>.
You can specify a file name of <TT>`/'</TT> to refer to the root directory,
but the empty string is not a meaningful file name. If you want to
refer to the current working directory, use a file name of <TT>`.'</TT> or
<TT>`./'</TT>.
<P>
Unlike some other operating systems, the GNU system doesn't have any
built-in support for file types (or extensions) or file versions as part
of its file name syntax. Many programs and utilities use conventions
for file names--for example, files containing C source code usually
have names suffixed with <SAMP>`.c'</SAMP>---but there is nothing in the file
system itself that enforces this kind of convention.
<P>
<H3><A NAME="SEC115" HREF="library_toc.html#SEC115" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC115">File Name Errors</A></H3>
<A NAME="IDX435"></A>
<A NAME="IDX436"></A>
<P>
Functions that accept file name arguments usually detect these
<CODE>errno</CODE> error conditions relating to file name syntax. These
errors are referred to throughout this manual as the <DFN>usual file
name syntax errors</DFN>.
<P>
<DL COMPACT>
<DT><CODE>EACCES</CODE>
<DD>The process does not have search permission for a directory component
of the file name.
<P>
<DT><CODE>ENAMETOOLONG</CODE>
<DD>This error is used when either the the total length of a file name is
greater than <CODE>PATH_MAX</CODE>, or when an individual file name component
has a length greater than <CODE>NAME_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>.
<P>
In the GNU system, there is no imposed limit on overall file name
length, but some file systems may place limits on the length of a
component.
<P>
<DT><CODE>ENOENT</CODE>
<DD>This error is reported when a file referenced as a directory component
in the file name doesn't exist.
<P>
<DT><CODE>ENOTDIR</CODE>
<DD>A file that is referenced as a directory component in the file name
exists, but it isn't a directory.
</DL>
<P>
<H3><A NAME="SEC116" HREF="library_toc.html#SEC116" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC116">Portability of File Names</A></H3>
<P>
The rules for the syntax of file names discussed in section <A HREF="library_10.html#SEC112" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_10.html#SEC112">File Names</A>,
are the rules normally used by the GNU system and by other POSIX
systems. However, other operating systems may use other conventions.
<P>
There are two reasons why it can be important for you to be aware of
file name portability issues:
<P>
<UL>
<LI>
If your program makes assumptions about file name syntax, or contains
embedded literal file name strings, it is more difficult to get it to
run under other operating systems that use different syntax conventions.
<P>
<LI>
Even if you are not concerned about running your program on machines
that run other operating systems, it may still be possible to access
files that use different naming conventions. For example, you may be
able to access file systems on another computer running a different
operating system over a network, or read and write disks in formats used
by other operating systems.
</UL>
<P>
The ANSI C standard says very little about file name syntax, only that
file names are strings. In addition to varying restrictions on the
length of file names and what characters can validly appear in a file
name, different operating systems use different conventions and syntax
for concepts such as structured directories and file types or
extensions. Some concepts such as file versions might be supported in
some operating systems and not by others.
<P>
The POSIX.1 standard allows implementations to put additional
restrictions on file name syntax, concerning what characters are
permitted in file names and on the length of file name and file name
component strings. However, in the GNU system, you do not need to worry
about these restrictions; any character except the null character is
permitted in a file name string, and there are no limits on the length
of file name strings.
<P>
<P>Go to the <A HREF="library_9.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_9.html">previous</A>, <A HREF="library_11.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_11.html">next</A> section.<P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -