delorie.com/djgpp/doc/libc/libc_58.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

basename

Syntax

 
#include <unistd.h>

char * basename (const char *fname);

Description

This function returns the basename of the file, which is the last part of its full name given by fname, with the drive letter and leading directories stripped off. For example, the basename of c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo. Trailing slashes and backslashes are significant: the basename of c:/foo/bar/ is an empty string after the rightmost slash.

This function treats both forward- and backslashes like directory separators, so it can handle file names with mixed styles of slashes.

Return Value

A pointer into the original file name where the basename starts. Note that this is not a new buffer allocated with malloc. If fname is a NULL pointer, the function will return a NULL pointer.

Portability

ANSI/ISO C No
POSIX No

Example

 
  if (strcmp (basename (file_name), "gcc.exe") == 0)
    printf ("The file %s is the GNU C/C++ compiler\n", file_name);


  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004