2001-06-22 01:11:37 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
2003-03-19 14:43:01 +05:30
|
|
|
* dirname implementation for busybox (for libc's missing one)
|
2001-06-22 01:11:37 +05:30
|
|
|
*
|
2003-03-19 14:43:01 +05:30
|
|
|
* Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
|
2001-06-22 01:11:37 +05:30
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2003-03-19 14:43:01 +05:30
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Note: The previous busybox implementation did not handle NULL path
|
|
|
|
* and also moved a pointer before path, which is not portable in C.
|
|
|
|
* So I replaced it with my uClibc version.
|
2001-06-22 01:11:37 +05:30
|
|
|
*/
|
|
|
|
|
2001-06-30 00:29:32 +05:30
|
|
|
#include <string.h>
|
2001-06-22 01:11:37 +05:30
|
|
|
#include "libbb.h"
|
|
|
|
|
2003-03-19 14:43:01 +05:30
|
|
|
#if __GNU_LIBRARY__ < 5
|
2001-06-22 01:11:37 +05:30
|
|
|
|
2003-03-19 14:43:01 +05:30
|
|
|
extern
|
2001-08-25 02:05:45 +05:30
|
|
|
char *dirname(char *path)
|
2001-06-22 01:11:37 +05:30
|
|
|
{
|
2003-03-19 14:43:01 +05:30
|
|
|
static const char null_or_empty_or_noslash[] = ".";
|
|
|
|
register char *s;
|
|
|
|
register char *last;
|
|
|
|
char *first;
|
2001-06-22 01:11:37 +05:30
|
|
|
|
2003-03-19 14:43:01 +05:30
|
|
|
last = s = path;
|
2001-06-22 01:11:37 +05:30
|
|
|
|
2003-03-19 14:43:01 +05:30
|
|
|
if (s != NULL) {
|
2001-06-22 01:11:37 +05:30
|
|
|
|
2003-03-19 14:43:01 +05:30
|
|
|
LOOP:
|
|
|
|
while (*s && (*s != '/')) ++s;
|
|
|
|
first = s;
|
|
|
|
while (*s == '/') ++s;
|
|
|
|
if (*s) {
|
|
|
|
last = first;
|
|
|
|
goto LOOP;
|
|
|
|
}
|
2001-08-25 01:21:54 +05:30
|
|
|
|
2003-03-19 14:43:01 +05:30
|
|
|
if (last == path) {
|
|
|
|
if (*last != '/') {
|
|
|
|
goto DOT;
|
|
|
|
}
|
|
|
|
if ((*++last == '/') && (last[1] == 0)) {
|
|
|
|
++last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*last = 0;
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
DOT:
|
|
|
|
return (char *) null_or_empty_or_noslash;
|
2001-06-22 01:11:37 +05:30
|
|
|
}
|
2001-08-25 02:05:45 +05:30
|
|
|
|
|
|
|
#endif
|