summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNathan Lee <me@nwlee.tech>2026-08-03 20:40:24 -0500
committerNathan Lee <me@nwlee.tech>2026-08-03 20:40:24 -0500
commit0aaaaa9bdf4c883c75f3ec15a491231ed21d6e8d (patch)
treeb2cc5ea032b5f267452d3b2117b763e7202c59e6 /include
parent30c8810932c704f81b2d25b43e7715fa4238342f (diff)
create a simple CPIO parser for initrd's
Diffstat (limited to 'include')
-rw-r--r--include/common.h13
-rw-r--r--include/cpio.h23
2 files changed, 36 insertions, 0 deletions
diff --git a/include/common.h b/include/common.h
index 88ee8c4..d26b8ae 100644
--- a/include/common.h
+++ b/include/common.h
@@ -16,6 +16,19 @@ static inline int strcmp(const char *str1, const char* str2) {
return *(const unsigned char *)str1 - *(const unsigned char *)str2;
}
+static inline int memcmp(const void *s1, const void *s2, size_t n) {
+ const unsigned char *p1 = (const unsigned char *)s1;
+ const unsigned char *p2 = (const unsigned char *)s2;
+
+ for (size_t i = 0; i < n; i++) {
+ if (p1[i] != p2[i]) {
+ return p1[i] - p2[i];
+ }
+ }
+
+ return 0;
+}
+
static inline void *memcpy(void *restrict dest, const void* restrict src, size_t size) {
unsigned char *d = (unsigned char *)dest;
unsigned char *s = (unsigned char *)src;
diff --git a/include/cpio.h b/include/cpio.h
new file mode 100644
index 0000000..3bb40c0
--- /dev/null
+++ b/include/cpio.h
@@ -0,0 +1,23 @@
+#pragma once
+#include <types.h>
+#define CPIO_HEADER_LEN 110
+
+struct cpio_newc_hdr {
+ char magic[6];
+ char ino[8];
+ char mode[8];
+ char uid[8];
+ char gid[8];
+ char nlink[8];
+ char mtime[8];
+ char filesize[8];
+ char devmajor[8];
+ char devminor[8];
+ char rdevmajor[8];
+ char rdevminor[8];
+ char namesize[8];
+ char check[8];
+};
+
+void *cpio_get_file(void *archive, size_t size, const char *filename);
+