OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [unix/] [dirname.c] - Blame information for rev 297

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
#ifndef _NO_DIRNAME
2
 
3
/* Copyright 2005 Shaun Jackman
4
 * Permission to use, copy, modify, and distribute this software
5
 * is freely granted, provided that this notice is preserved.
6
 */
7
 
8
#include <libgen.h>
9
#include <string.h>
10
 
11
char *
12
_DEFUN (dirname, (path),
13
        char *path)
14
{
15
        char *p;
16
        if( path == NULL || *path == '\0' )
17
                return ".";
18
        p = path + strlen(path) - 1;
19
        while( *p == '/' ) {
20
                if( p == path )
21
                        return path;
22
                *p-- = '\0';
23
        }
24
        while( p >= path && *p != '/' )
25
                p--;
26
        return
27
                p < path ? "." :
28
                p == path ? "/" :
29
                (*p = '\0', path);
30
}
31
 
32
#endif /* !_NO_DIRNAME  */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.