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

basename.3p (4096B)


  1. '\" et
  2. .TH BASENAME "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. basename
  12. \(em return the last component of a pathname
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <libgen.h>
  17. .P
  18. char *basename(char *\fIpath\fP);
  19. .fi
  20. .SH DESCRIPTION
  21. The
  22. \fIbasename\fR()
  23. function shall take the pathname pointed to by
  24. .IR path
  25. and return a pointer to the final component of the pathname, deleting
  26. any trailing
  27. .BR '/'
  28. characters.
  29. .P
  30. If the string pointed to by
  31. .IR path
  32. consists entirely of the
  33. .BR '/'
  34. character,
  35. \fIbasename\fR()
  36. shall return a pointer to the string
  37. .BR \(dq/\(dq .
  38. If the string pointed to by
  39. .IR path
  40. is exactly
  41. .BR \(dq//\(dq ,
  42. it is implementation-defined whether
  43. .BR '/'
  44. or
  45. .BR \(dq//\(dq
  46. is returned.
  47. .P
  48. If
  49. .IR path
  50. is a null pointer or points to an empty string,
  51. \fIbasename\fR()
  52. shall return a pointer to the string
  53. .BR \(dq.\(dq .
  54. .P
  55. The
  56. \fIbasename\fR()
  57. function may modify the string pointed to by
  58. .IR path ,
  59. and may return a pointer to internal storage. The returned pointer
  60. might be invalidated or the storage might be overwritten by a
  61. subsequent call to
  62. \fIbasename\fR().
  63. The returned pointer might also be invalidated if the calling
  64. thread is terminated.
  65. .P
  66. The
  67. \fIbasename\fR()
  68. function need not be thread-safe.
  69. .SH "RETURN VALUE"
  70. The
  71. \fIbasename\fR()
  72. function shall return a pointer to the final component of
  73. .IR path .
  74. .SH ERRORS
  75. No errors are defined.
  76. .LP
  77. .IR "The following sections are informative."
  78. .SH EXAMPLES
  79. .SS "Using basename(\|)"
  80. .P
  81. The following program fragment returns a pointer to the value
  82. .IR lib ,
  83. which is the base name of
  84. .BR /usr/lib .
  85. .sp
  86. .RS 4
  87. .nf
  88. #include <libgen.h>
  89. \&...
  90. char name[] = "/usr/lib";
  91. char *base;
  92. .P
  93. base = basename(name);
  94. \&...
  95. .fi
  96. .P
  97. .RE
  98. .SS "Sample Input and Output Strings for the basename(\|) and dirname(\|) Functions and the basename and dirname Utilities"
  99. .S -1
  100. .TS
  101. center box tab(!);
  102. cB | cB | cB | cB | cB | cB
  103. cB | cB | cB | cB | cB | cB
  104. cB | cB | cB | cB | cB | cB
  105. cB | cB | cB | cB | cB | cB
  106. lf51 | lf51 | lf51 | lf51 | lf51 | lf5.
  107. basename(\|)!!!basename!Output!Output
  108. and dirname(\|)!String!String!and dirname!Written by!Written by
  109. Functions path!Returned by!Returned by!Utilities!basename!dirname
  110. Argument!basename(\|)!dirname(\|)!string Operand!Utility!Utility
  111. _
  112. "usr"!"usr"!"."!usr!usr!.
  113. _
  114. "usr/"!"usr"!"."!usr/!usr!.
  115. _
  116. ""!"."!"."!""!. \fRor empty string\fR!.
  117. _
  118. "/"!"/"!"/"!/!/!/
  119. _
  120. "//"!"/" \fRor\fR "//"!"/" \fRor\fR "//"!//!/ \fRor\fR //!/ \fRor\fR //
  121. _
  122. "///"!"/"!"/"!///!/!/
  123. _
  124. "/usr/"!"usr"!"/"!/usr/!usr!/
  125. _
  126. "/usr/lib"!"lib"!"/usr"!/usr/lib!lib!/usr
  127. _
  128. "//usr//lib//"!"lib"!"//usr"!//usr//lib//!lib!//usr
  129. _
  130. "/home//dwc//!"test"!"/home//dwc"!/home//dwc//!test!/home//dwc
  131. test"!!!test
  132. .TE
  133. .S +1
  134. .SH "APPLICATION USAGE"
  135. None.
  136. .SH RATIONALE
  137. None.
  138. .SH "FUTURE DIRECTIONS"
  139. None.
  140. .SH "SEE ALSO"
  141. .IR "\fIdirname\fR\^(\|)"
  142. .P
  143. The Base Definitions volume of POSIX.1\(hy2017,
  144. .IR "\fB<libgen.h>\fP"
  145. .P
  146. The Shell and Utilities volume of POSIX.1\(hy2017,
  147. .IR "\fIbasename\fR\^"
  148. .\"
  149. .SH COPYRIGHT
  150. Portions of this text are reprinted and reproduced in electronic form
  151. from IEEE Std 1003.1-2017, Standard for Information Technology
  152. -- Portable Operating System Interface (POSIX), The Open Group Base
  153. Specifications Issue 7, 2018 Edition,
  154. Copyright (C) 2018 by the Institute of
  155. Electrical and Electronics Engineers, Inc and The Open Group.
  156. In the event of any discrepancy between this version and the original IEEE and
  157. The Open Group Standard, the original IEEE and The Open Group Standard
  158. is the referee document. The original Standard can be obtained online at
  159. http://www.opengroup.org/unix/online.html .
  160. .PP
  161. Any typographical or formatting errors that appear
  162. in this page are most likely
  163. to have been introduced during the conversion of the source files to
  164. man page format. To report such errors, see
  165. https://www.kernel.org/doc/man-pages/reporting_bugs.html .