path.c: removed unneeded functions.
This commit is contained in:
parent
de35c33c37
commit
f752e03943
3 changed files with 0 additions and 77 deletions
65
src/path.c
65
src/path.c
|
|
@ -21,27 +21,6 @@
|
||||||
|
|
||||||
static char path_null = '\0';
|
static char path_null = '\0';
|
||||||
|
|
||||||
/*
|
|
||||||
* allocates and initilizes a path
|
|
||||||
*/
|
|
||||||
static char* alloc_path(size_t s) {
|
|
||||||
|
|
||||||
char *ptr;
|
|
||||||
|
|
||||||
if (s < 1)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
ptr = malloc(s+1);
|
|
||||||
|
|
||||||
if (ptr == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
*ptr = '/';
|
|
||||||
memset(ptr+1, 0, s);
|
|
||||||
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char* path_clear(const char *path) {
|
static const char* path_clear(const char *path) {
|
||||||
|
|
||||||
while(*path == '/')
|
while(*path == '/')
|
||||||
|
|
@ -58,33 +37,6 @@ static inline int has_delim(const char *str) {
|
||||||
return strchr(str, '/') != NULL;
|
return strchr(str, '/') != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* copy a clean path to buf
|
|
||||||
* NOTE: buffer should be atleast of size pathlen(path)+1
|
|
||||||
*/
|
|
||||||
static char* cpy_path(char *buf, const char *path) {
|
|
||||||
|
|
||||||
if (*path == 0)
|
|
||||||
return buf;
|
|
||||||
|
|
||||||
while(*path) {
|
|
||||||
|
|
||||||
*(buf++) = *path;
|
|
||||||
|
|
||||||
if (*path == '/')
|
|
||||||
path = path_clear(path);
|
|
||||||
else
|
|
||||||
path++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*(buf-1) != '/')
|
|
||||||
*(buf++) = '/';
|
|
||||||
|
|
||||||
dassert(*buf == 0);
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
int is_abspath(const char *path) {
|
int is_abspath(const char *path) {
|
||||||
|
|
||||||
if (path == NULL || *path != '/')
|
if (path == NULL || *path != '/')
|
||||||
|
|
@ -104,23 +56,6 @@ int is_abspath(const char *path) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t pathlen(const char *path) {
|
|
||||||
|
|
||||||
size_t size = 0;
|
|
||||||
|
|
||||||
while(*path) {
|
|
||||||
|
|
||||||
size++;
|
|
||||||
|
|
||||||
if (*path == '/')
|
|
||||||
path = path_clear(path);
|
|
||||||
else
|
|
||||||
path++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char* expand_home() {
|
static char* expand_home() {
|
||||||
|
|
||||||
char *home = getenv("HOME");
|
char *home = getenv("HOME");
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
int is_abspath(const char *path);
|
int is_abspath(const char *path);
|
||||||
|
|
||||||
size_t pathlen(const char *path);
|
|
||||||
|
|
||||||
char* path_normalize(const char *base, const char *name, unsigned char dir);
|
char* path_normalize(const char *base, const char *name, unsigned char dir);
|
||||||
|
|
||||||
#endif /* __PATH_H */
|
#endif /* __PATH_H */
|
||||||
|
|
|
||||||
|
|
@ -37,15 +37,6 @@ void test_normalize() {
|
||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_pathlen() {
|
|
||||||
|
|
||||||
assert(pathlen("/usr/src/linux-2.6.30-r5/drivers") == 32);
|
|
||||||
assert(pathlen("/usr///src/") == 9);
|
|
||||||
assert(pathlen("/usr//include/sys//") == 17);
|
|
||||||
assert(pathlen("///var/lib/misc") == 13);
|
|
||||||
assert(pathlen("dir") == 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_isabspath() {
|
void test_isabspath() {
|
||||||
|
|
||||||
assert(is_abspath("file") == 0);
|
assert(is_abspath("file") == 0);
|
||||||
|
|
@ -108,7 +99,6 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
test_isabspath();
|
test_isabspath();
|
||||||
test_normalize();
|
test_normalize();
|
||||||
test_pathlen();
|
|
||||||
test_basename();
|
test_basename();
|
||||||
test_dirname();
|
test_dirname();
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue