vfs: add vfs_open
vfs_open parses a path and returns the correct inode. The out inode is a double pointer argument passed to vfs_open, and the return value is an error code, or 0 Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
913b91189b
commit
a8540494a9
11 changed files with 345 additions and 137 deletions
|
|
@ -17,9 +17,10 @@ static const char *errno_str[] = {
|
|||
[EAGAIN] = "Try again",
|
||||
[EBUSY] = "Device or resource busy",
|
||||
[ENOSYS] = "Function not implemented",
|
||||
[ENAMETOOLONG] = "Name too long",
|
||||
};
|
||||
|
||||
inline const char *strerror(int errnum)
|
||||
const char *strerror(int errnum)
|
||||
{
|
||||
if (errnum < 0 || (size_t)errnum >= ARRAY_SIZE(errno_str))
|
||||
return "Unknown error";
|
||||
|
|
|
|||
24
lib/string.c
24
lib/string.c
|
|
@ -15,9 +15,7 @@ void *memcpy(void *dest, const void *src, size_t num)
|
|||
|
||||
int strcmp(const char *a, const char *b)
|
||||
{
|
||||
while (*a && *b) {
|
||||
if (*a != *b)
|
||||
return *a - *b;
|
||||
while (*a && *a == *b) {
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
|
|
@ -26,12 +24,14 @@ int strcmp(const char *a, const char *b)
|
|||
|
||||
int strncmp(const char *a, const char *b, size_t n)
|
||||
{
|
||||
if (n == 0)
|
||||
return 0;
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
if (a[i] != b[i])
|
||||
if (a[i] != b[i] || !a[i] || !b[i])
|
||||
return a[i] - b[i];
|
||||
if (!a[i] || !b[i])
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -177,24 +177,21 @@ static char *udirname(char *path)
|
|||
if (!path || !*path)
|
||||
return ".";
|
||||
|
||||
|
||||
size_t len = strlen(path);
|
||||
while (len > 1 && path[len - 1] == '/')
|
||||
path[--len] = '\0';
|
||||
|
||||
|
||||
int last_slash_idx = -1;
|
||||
for (int i = 0; path[i] != '\0'; i++)
|
||||
if (path[i] == '/')
|
||||
last_slash_idx = i;
|
||||
|
||||
|
||||
if (last_slash_idx == -1)
|
||||
return ".";
|
||||
return ".";
|
||||
if (last_slash_idx == 0)
|
||||
return "/";
|
||||
return "/";
|
||||
|
||||
path[last_slash_idx] = '\0';
|
||||
path[last_slash_idx] = '\0';
|
||||
return path;
|
||||
}
|
||||
|
||||
|
|
@ -203,18 +200,15 @@ static char *ubasename(char *path)
|
|||
if (!path || !*path)
|
||||
return ".";
|
||||
|
||||
|
||||
size_t len = strlen(path);
|
||||
while (len > 1 && path[len - 1] == '/')
|
||||
path[--len] = '\0';
|
||||
|
||||
|
||||
int last_slash_idx = -1;
|
||||
for (int i = 0; path[i] != '\0'; i++)
|
||||
if (path[i] == '/')
|
||||
last_slash_idx = i;
|
||||
|
||||
|
||||
if (last_slash_idx == -1)
|
||||
return path;
|
||||
if (path[last_slash_idx + 1] == '\0' && last_slash_idx == 0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue