gitignore: add .cpio

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-05-13 04:47:59 -04:00
commit f0a9ff299b
27 changed files with 253 additions and 245 deletions

View file

@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include "kernel/spinlock.h"
#include <kernel/spinlock.h>
#include <kernel/types.h>
#include <kernel/slab.h>
#include <lib/list.h>

View file

@ -24,7 +24,7 @@ size_t log2(size_t n)
inline void bitmap_set(char *bitmap, size_t n, uint64_t b)
{
if(b)
if (b)
bitmap[n >> 3] |= (1 << (n & 7));
else
bitmap[n >> 3] &= (~(1 << (n & 7)));
@ -34,3 +34,32 @@ inline uint8_t bitmap_get(char *bitmap, size_t n)
{
return bitmap[n >> 3] & (1 << (n & 7));
}
static int hexc_to_int(char c)
{
if (c >= '0' && c <= '9')
return c - '0';
else if (c >= 'A' && c <= 'F')
return c - 'F';
else if (c >= 'a' && c <= 'f')
return c - 'a';
else
return -1;
}
u64 hex_to_int(char *ascii_hex, size_t n)
{
u64 ret = 0;
for (size_t i = 0; i < n; i++) {
char c = ascii_hex[i];
int i = hexc_to_int(c);
if (i < 0)
break;
ret <<= 4;
ret |= i;
}
return ret;
}

View file

@ -171,3 +171,75 @@ bool strempty(const char *s)
return true;
}
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 ".";
if (last_slash_idx == 0)
return "/";
path[last_slash_idx] = '\0';
return path;
}
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)
return "/";
return &path[last_slash_idx + 1];
}
char *dirname(const char *path)
{
if (!path)
return strdup(".");
char *copy = strdup(path);
char *res = udirname(copy);
char *ret = strdup(res);
kfree(copy);
return ret;
}
char *basename(const char *path)
{
if (!path)
return strdup(".");
char *copy = strdup(path);
char *res = ubasename(copy);
char *ret = strdup(res);
kfree(copy);
return ret;
}