⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 library_10.html

📁 Linux程序员的工作手册
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<A NAME="IDX427"></A><A NAME="IDX428"></A><P>A <DFN>directory</DFN> is a file that contains information to associate otherfiles with names; these associations are called <DFN>links</DFN> or<DFN>directory entries</DFN>.  Sometimes, people speak of "files in adirectory", but in reality, a directory only contains pointers tofiles, not the files themselves.<A NAME="IDX429"></A><P>The name of a file contained in a directory entry is called a <DFN>filename component</DFN>.  In general, a file name consists of a sequence of oneor more such components, separated by the slash character (<SAMP>`/'</SAMP>).  Afile name which is just one component names a file with respect to itsdirectory.  A file name with multiple components names a directory, andthen 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 afile name component.  We don't use this terminology because a "path"is something completely different (a list of directories to search), andwe think that "pathname" used for something else will confuse users.We always use "file name" and "file name component" (or sometimesjust "component", where the context is obvious) in GNU documentation.<P>You can find more detailed information about operations on directoriesin 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 thecomponents that make up a file name in left-to-right order, and locatingeach successive component in the directory named by the previouscomponent.  Of course, each of the files that are referenced asdirectories must actually exist, be directories instead of regularfiles, and have the appropriate permissions to be accessible by theprocess; 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 filename is located in the <DFN>root directory</DFN> of the process.  Such a filename is called an <DFN>absolute file name</DFN>.<A NAME="IDX433"></A><P>Otherwise, the first component in the file name is located in thecurrent 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 offile 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 namecomponents.  The file name component <TT>`.'</TT> refers to the directoryitself, while the file name component <TT>`..'</TT> refers to its<DFN>parent directory</DFN> (the directory that contains the link for thedirectory 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 workingdirectory.</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 torefer 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 anybuilt-in support for file types (or extensions) or file versions as partof its file name syntax.  Many programs and utilities use conventionsfor file names--for example, files containing C source code usuallyhave names suffixed with <SAMP>`.c'</SAMP>---but there is nothing in the filesystem 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.  Theseerrors are referred to throughout this manual as the <DFN>usual filename 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 isgreater than <CODE>PATH_MAX</CODE>, or when an individual file name componenthas 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 namelength, but some file systems may place limits on the length of acomponent.<P><DT><CODE>ENOENT</CODE><DD>This error is reported when a file referenced as a directory componentin the file name doesn't exist.<P><DT><CODE>ENOTDIR</CODE><DD>A file that is referenced as a directory component in the file nameexists, 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 POSIXsystems.  However, other operating systems may use other conventions.<P>There are two reasons why it can be important for you to be aware offile name portability issues:<P><UL><LI>If your program makes assumptions about file name syntax, or containsembedded literal file name strings, it is more difficult to get it torun under other operating systems that use different syntax conventions.<P><LI>Even if you are not concerned about running your program on machinesthat run other operating systems, it may still be possible to accessfiles that use different naming conventions.  For example, you may beable to access file systems on another computer running a differentoperating system over a network, or read and write disks in formats usedby other operating systems.</UL><P>The ANSI C standard says very little about file name syntax, only thatfile names are strings.  In addition to varying restrictions on thelength of file names and what characters can validly appear in a filename, different operating systems use different conventions and syntaxfor concepts such as structured directories and file types orextensions.  Some concepts such as file versions might be supported insome operating systems and not by others.<P>The POSIX.1 standard allows implementations to put additionalrestrictions on file name syntax, concerning what characters arepermitted in file names and on the length of file name and file namecomponent strings.  However, in the GNU system, you do not need to worryabout these restrictions; any character except the null character ispermitted in a file name string, and there are no limits on the lengthof 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 + -