File: gnu_basename.c

package info (click to toggle)
picolibc 1.8.11-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 50,064 kB
  • sloc: ansic: 404,031; asm: 24,984; sh: 2,585; python: 2,289; perl: 680; pascal: 329; exp: 287; makefile: 222; cpp: 71; xml: 40
file content (28 lines) | stat: -rw-r--r-- 719 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef _NO_BASENAME
/* Copyright 2015 Red Hat, Inc.
 * Permission to use, copy, modify, and distribute this software
 * is freely granted, provided that this notice is preserved.
 */

/* The differences with the POSIX version (unix/basename.c):
 * - declared in <string.h> (instead of <libgen.h>);
 * - the argument is never modified, and therefore is marked const;
 * - the empty string is returned if path is an empty string, "/", or ends
 *   with a trailing slash.
 */

#define _GNU_SOURCE
#include <string.h>

__typeof(basename) __gnu_basename;

char *
__gnu_basename(const char *path)
{
    char *p;
    if ((p = strrchr(path, '/')))
        return p + 1;
    return (char *)path;
}

#endif /* !_NO_BASENAME  */