logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

dirname.3p (4333B)


  1. '\" et
  2. .TH DIRNAME "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. dirname
  12. \(em report the parent directory name of a file pathname
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <libgen.h>
  17. .P
  18. char *dirname(char *\fIpath\fP);
  19. .fi
  20. .SH DESCRIPTION
  21. The
  22. \fIdirname\fR()
  23. function shall take a pointer to a character string that contains a
  24. pathname, and return a pointer to a string that is a pathname of the
  25. parent directory of that file. The
  26. \fIdirname\fR()
  27. function shall not perform pathname resolution; the result shall not be
  28. affected by whether or not
  29. .IR path
  30. exists or by its file type. Trailing
  31. .BR '/'
  32. characters in the path that are not also leading
  33. .BR '/'
  34. characters shall not be counted as part of the path.
  35. .P
  36. If
  37. .IR path
  38. does not contain a
  39. .BR '/' ,
  40. then
  41. \fIdirname\fR()
  42. shall return a pointer to the string
  43. .BR \(dq.\(dq .
  44. If
  45. .IR path
  46. is a null pointer or points to an empty string,
  47. \fIdirname\fR()
  48. shall return a pointer to the string
  49. .BR \(dq.\(dq .
  50. .P
  51. The
  52. \fIdirname\fR()
  53. function may modify the string pointed to by
  54. .IR path ,
  55. and may return a pointer to static storage that may then be
  56. overwritten by a subsequent call to
  57. \fIdirname\fR().
  58. .P
  59. The
  60. \fIdirname\fR()
  61. function need not be thread-safe.
  62. .SH "RETURN VALUE"
  63. The
  64. \fIdirname\fR()
  65. function shall return a pointer to a string as described above.
  66. .P
  67. The
  68. \fIdirname\fR()
  69. function may modify the string pointed to by
  70. .IR path ,
  71. and may return a pointer to internal storage. The returned pointer
  72. might be invalidated or the storage might be overwritten by a
  73. subsequent call to
  74. \fIdirname\fR().
  75. The returned pointer might also be invalidated if the calling
  76. thread is terminated.
  77. .SH ERRORS
  78. No errors are defined.
  79. .LP
  80. .IR "The following sections are informative."
  81. .SH EXAMPLES
  82. The following code fragment reads a pathname, changes the current
  83. working directory to the parent directory, and opens the file.
  84. .sp
  85. .RS 4
  86. .nf
  87. char *path = NULL, *pathcopy;
  88. size_t buflen = 0;
  89. ssize_t linelen = 0;
  90. int fd;
  91. .P
  92. linelen = getline(&path, &buflen, stdin);
  93. .P
  94. path[linelen-1] = 0;
  95. pathcopy = strdup(path);
  96. if (chdir(dirname(pathcopy)) < 0) {
  97. ...
  98. }
  99. if ((fd = open(basename(path), O_RDONLY)) >= 0) {
  100. ...
  101. close (fd);
  102. }
  103. \&...
  104. free (pathcopy);
  105. free (path);
  106. .fi
  107. .P
  108. .RE
  109. .P
  110. The EXAMPLES section of the
  111. \fIbasename\fR()
  112. function (see
  113. .IR "\fIbasename\fR\^(\|)")
  114. includes a table showing examples of the results of processing
  115. several sample pathnames by the
  116. \fIbasename\fR()
  117. and
  118. \fIdirname\fR()
  119. functions and by the
  120. .IR basename
  121. and
  122. .IR dirname
  123. utilities.
  124. .SH "APPLICATION USAGE"
  125. The
  126. \fIdirname\fR()
  127. and
  128. \fIbasename\fR()
  129. functions together yield a complete pathname. The expression
  130. \fIdirname\fP\^(\fIpath\fP) obtains the pathname of the directory where
  131. \fIbasename\fP\^(\fIpath\fP) is found.
  132. .P
  133. Since the meaning of the leading
  134. .BR \(dq//\(dq
  135. is implementation-defined,
  136. .IR dirname ("\c
  137. .BR //foo ")
  138. may return either
  139. .BR \(dq//\(dq
  140. or
  141. .BR '/'
  142. (but nothing else).
  143. .SH RATIONALE
  144. None.
  145. .SH "FUTURE DIRECTIONS"
  146. None.
  147. .SH "SEE ALSO"
  148. .IR "\fIbasename\fR\^(\|)"
  149. .P
  150. The Base Definitions volume of POSIX.1\(hy2017,
  151. .IR "\fB<libgen.h>\fP"
  152. .P
  153. The Shell and Utilities volume of POSIX.1\(hy2017,
  154. .IR "\fIbasename\fR\^",
  155. .IR "\fIdirname\fR\^"
  156. .\"
  157. .SH COPYRIGHT
  158. Portions of this text are reprinted and reproduced in electronic form
  159. from IEEE Std 1003.1-2017, Standard for Information Technology
  160. -- Portable Operating System Interface (POSIX), The Open Group Base
  161. Specifications Issue 7, 2018 Edition,
  162. Copyright (C) 2018 by the Institute of
  163. Electrical and Electronics Engineers, Inc and The Open Group.
  164. In the event of any discrepancy between this version and the original IEEE and
  165. The Open Group Standard, the original IEEE and The Open Group Standard
  166. is the referee document. The original Standard can be obtained online at
  167. http://www.opengroup.org/unix/online.html .
  168. .PP
  169. Any typographical or formatting errors that appear
  170. in this page are most likely
  171. to have been introduced during the conversion of the source files to
  172. man page format. To report such errors, see
  173. https://www.kernel.org/doc/man-pages/reporting_bugs.html .