This commit is contained in:
parent
d00ca0d3ed
commit
df10544e84
23
libc/include/libgen.h
Normal file
23
libc/include/libgen.h
Normal file
@ -0,0 +1,23 @@
|
||||
/* libgen.h: Path parsing functions. */
|
||||
|
||||
#ifndef _LIBGEN_H
|
||||
#define _LIBGEN_H
|
||||
|
||||
// These functions are implemented in libluna (CPath.h)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* Returns path's base name. Will modify path. */
|
||||
char* basename(char* path);
|
||||
|
||||
/* Returns path's parent directory. Will modify path. */
|
||||
char* dirname(char* path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,4 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
char* basename(char*);
|
||||
char* dirname(char*);
|
||||
extern "C"
|
||||
{
|
||||
char* basename(char*);
|
||||
char* dirname(char*);
|
||||
}
|
||||
|
@ -3,8 +3,10 @@
|
||||
|
||||
static char dot[] = ".";
|
||||
|
||||
char* basename(char* path)
|
||||
extern "C"
|
||||
{
|
||||
char* basename(char* path)
|
||||
{
|
||||
// If path is NULL, or the string's length is 0, return .
|
||||
if (!path) return dot;
|
||||
usize len = strlen(path);
|
||||
@ -21,10 +23,10 @@ char* basename(char* path)
|
||||
char* beg = strrchr(path, '/');
|
||||
if (!beg) return path;
|
||||
return beg + 1;
|
||||
}
|
||||
}
|
||||
|
||||
char* dirname(char* path)
|
||||
{
|
||||
char* dirname(char* path)
|
||||
{
|
||||
// If path is NULL, or the string's length is 0, return .
|
||||
if (!path) return dot;
|
||||
usize len = strlen(path);
|
||||
@ -44,4 +46,5 @@ char* dirname(char* path)
|
||||
else
|
||||
*(end + 1) = 0;
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user