dirname.html
来自「unix 下的C开发手册,还用详细的例程。」· HTML 代码 · 共 109 行
HTML
109 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>dirname</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_003_100"> </a>NAME</h4><blockquote>dirname - report the parent directory name of a file pathname</blockquote><h4><a name = "tag_000_003_101"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="libgen.h.html">libgen.h</a>>char *dirname(char *<i>path</i>);</code></pre></blockquote><h4><a name = "tag_000_003_102"> </a>DESCRIPTION</h4><blockquote>The<i>dirname()</i>function takes a pointer to a character string that contains a pathname, andreturns a pointer to a string that is a pathname of the parent directory ofthat file. Trailing '/' characters in the path are not counted as part of thepath.<p>If<i>path</i>does not contain a '/', then<i>dirname()</i>returns a pointer to the string "." . If<i>path</i>is a null pointer or points to an empty string,<i>dirname()</i>returns a pointer to the string "." .<p>This interface need not be reentrant.</blockquote><h4><a name = "tag_000_003_103"> </a>RETURN VALUE</h4><blockquote>The<i>dirname()</i>function returns a pointer to a string that is the parent directory of<i>path</i>.If<i>path</i>is a null pointer or points to an empty string, a pointer to a string "." isreturned.<p>The<i>dirname()</i>function may modify the string pointed to by <i>path</i>, and may return apointer to static storage that may then be overwritten by subsequent calls to<i>dirname()</i>.</blockquote><h4><a name = "tag_000_003_104"> </a>ERRORS</h4><blockquote>No errors are defined.</blockquote><h4><a name = "tag_000_003_105"> </a>EXAMPLES</h4><blockquote><p><table bordercolor=#000000 border=1 align=center><tr valign=top><th align=left><b>Input String</b><th align=left><b>Output String</b><tr valign=top><td align=left>"/usr/lib"<td align=left>"/usr"<tr valign=top><td align=left>"/usr/"<td align=left>"/"<tr valign=top><td align=left>"usr"<td align=left>"."<tr valign=top><td align=left>"/"<td align=left>"/"<tr valign=top><td align=left>"."<td align=left>"."<tr valign=top><td align=left>".."<td align=left>"."</table><p>The following code fragment reads a pathname, changes the current workingdirectory to the parent directory, and opens the file.<pre><code>char path[MAXPATHLEN], *pathcopy;int fd;fgets(path, MAXPATHLEN, stdin);pathcopy = strdup(path);chdir(dirname(pathcopy));fd = open(basename(path), O_RDONLY);</code></pre></blockquote><h4><a name = "tag_000_003_106"> </a>APPLICATION USAGE</h4><blockquote>The<i>dirname()</i>and<i><a href="basename.html">basename()</a></i>functions together yield a complete pathname. The expression<i>dirname</i>(<i>path</i>) obtains the pathname of the directory where<i>basename</i>(<i>path</i>) is found.</blockquote><h4><a name = "tag_000_003_107"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_003_108"> </a>SEE ALSO</h4><blockquote><i><a href="basename.html">basename()</a></i>,<i><a href="libgen.h.html"><libgen.h></a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?