2 .TH DIRNAME 3 04-Jan-2007 MinGW "Programmer's Reference Manual"
6 .BR dirname ,\0 basename
7 \- parse path name components
15 .B char *dirname( char
19 .B char *basename( char
30 functions parse a null\-terminated path name string,
36 Splitting is performed on the basis of the location of the
37 .B directory separator
40 for this MS\-Windows(\(tm) implementation,
45 each of which is interpreted as being equivalent.
53 the first two characters of
55 are interpreted as an MS\-Windows(\(tm) drive designator,
56 which will be included in the
60 but is never considered to form part of the
67 returns a pointer to a string representing the path name component of
69 up to but not including the rightmost directory separator,
72 returns a pointer to the component following this separator.
73 Any trailing directory separators present in
76 when determining the rightmost separator,
77 and, in the case of the return value from
79 any internal sequences of recurring separator characters
80 are each reduced to a single such character.
85 contains no MS\-Windows(\(tm) drive designator,
86 and no directory separator character,
97 does commence with an MS\-Windows(\(tm) drive designator,
98 but contains no directory separators,
105 represents the drive designator,
110 with its initial two characters,
111 (i.e.\ the drive designator),
118 or is a pointer to an empty string,
148 two directory separator characters,
149 which must be similar,
152 will preserve these two characters in the returned path name.
153 This construct does not affect the string returned by
155 neither is this behaviour replicated by
159 includes an MS\-Windows(\(tm) drive designator.
167 two identical directory separator characters,
168 with no MS\-Windows(\(tm) drive designator,
169 and no following path name,
175 normalises the return string to only a single character,
180 matching the characters used to specify
184 Concatenating the string returned by
190 and the string returned by
192 yields a complete path name.
199 functions conform generally to SUSv3,
200 extended to accommodate the handling of
204 as alternative directory separator characters,
205 and also to accommodate the likelihood of MS\-Windows(\(tm)
206 drive designators appearing in any path name specification.
209 illustrates the conformance to SUSv3,
210 and also the effects of the extended behaviour.
215 To verify the behaviour of the
220 the test program defines the following function:\(em
229 void result( char *path )
231 char *dir = strdup( path );
232 char *file = strdup( path );
234 printf( " %-15s%-15s%-12s", path, dirname( dir ),
243 This illustrates the correct use of the
248 with copies of the original
250 string being passed in the function calls.
251 Note that the return values from each function are used immediately,
255 and the temporary copies of
258 and the associated memory is freed,
259 before these go out of scope.
262 Calling this example function illustrates the effect of each of the
267 for various values of
271 illustrate general conformance with the standard:\(em
276 lw(15n) lw(10n) lw(10n).
277 \0path!\0dirname!\0basename
279 \0/usr/lib!\0/usr!\0lib
280 \0//usr//lib//!\0//usr!\0lib
281 \0///usr//lib//!\0/usr!\0lib
293 for the case where path names are expressed using the MS\-Windows(\(tm)
295 directory separator notation,
296 calling the example function displays:\(em
301 lw(15n) lw(10n) lw(10n).
302 \0path!\0dirname!\0basename
304 \0\eusr\elib!\0\eusr!\0lib
305 \0\e\eusr\e\elib\e\e!\0\e\eusr!\0lib
306 \0\e\e\eusr\e\elib\e\e!\0\eusr!\0lib
318 when an MS\-Windows(\(tm) drive designator is also specified,
324 lw(15n) lw(10n) lw(10n).
325 \0path!\0dirname!\0basename
327 \0d:\eusr\elib!\0d:\eusr!\0lib
328 \0d:\e\eusr\e\elib\e\e!\0d:\eusr!\0lib
329 \0d:\e\e\eusr\e\elib\e\e!\0d:\eusr!\0lib
330 \0d:\eusr\e!\0d:\e!\0usr
342 the special handling of path names which begin with
344 two directory separator characters,
345 and also that this special handling is suppressed
346 when these two characters are dissimilar,
347 or when an MS\-Windows(\(tm) drive designator is specified:\(em
352 lw(15n) lw(10n) lw(10n).
353 \0path!\0dirname!\0basename
355 \0//usr//lib//!\0//usr!\0lib
356 \0\e\eusr\e\elib\e\e!\0\e\eusr!\0lib
357 \0/\eusr\e\elib\e\e!\0/usr!\0lib
358 \0\e/usr\e\elib\e\e!\0\eusr!\0lib
359 \0d:\e\eusr\e\elib\e\e!\0d:\eusr!\0lib
373 function returns a pointer to a null terminated string,
374 which represents the directory path component of the passed
377 without any trailing directory separator character,
378 and with all internal sequences of directory separator characters
379 normalised to a single separator at each level of directory nesting.
385 returns a pointer to a null terminated string,
386 which represents the rightmost element of the passed
389 with all trailing directory separator characters removed.
392 If any MS\-Windows(\(tm) drive designator is specified in the input
395 it is included in the return value of the
398 but not in that of the
414 functions may modify the
416 string passed to them.
417 Therefore, it is an error to pass a character constant as the
420 to do so may result in memory violation errors,
421 (segmentation faults),
422 and consequent abnormal program termination.
427 argument may be modified by the
432 if you wish to preserve the original content of
434 you should pass a copy to the function.
436 either function may return its result in a statically allocated buffer,
437 which may be overwritten on a subsequent function call.
443 functions parse path name strings,
444 they are basically just
447 The presence of an MS\-Windows(\(tm) drive designator is determined
448 by the appearance of a colon
450 as the second character of the
453 but neither function performs any check
454 to ensure that the first character represents a valid file system device;
455 neither is any form of validation performed,
456 to ensure that the remainder of the string
457 represents a valid path name.
462 This manpage was written for the MinGW implementation of the
466 functions by Keith\ Marshall,
467 <keithmarshall@users.sourceforge.net>.
468 It may copied, modified and redistributed,
469 without restriction of copyright,
470 provided this acknowledgement of contribution by
471 the original author remains unchanged.