aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-12-05 16:53:55 -0800
committerNicholas Noll <nbnoll@eml.cc>2021-12-05 16:53:55 -0800
commitb4cb7c06f94e2e91b22b7d82efd7943a82331d86 (patch)
tree99fa7085855875efa7422ee58f322f8c94bda860 /include
parent07e77936d535e58b0aeb4f2a11400c1050556739 (diff)
Chore: updated fs·walk to use new data structures
Completes the port to our standard library (up to malloc).
Diffstat (limited to 'include')
-rw-r--r--include/base.h31
-rw-r--r--include/base/fs.h25
-rw-r--r--include/sys.h2
3 files changed, 28 insertions, 30 deletions
diff --git a/include/base.h b/include/base.h
index 99cd40b..7c8afbb 100644
--- a/include/base.h
+++ b/include/base.h
@@ -6,30 +6,14 @@
#include <rt.h>
#include <sys.h>
-// TODO: remove dependency system headers
-#include <assert.h>
-/* remaining libc functions we depend upon */
+// TODO: remove dependency on malloc
+
+/* all libc functions we depend upon */
void *malloc(uintptr size);
void *calloc(uintptr n, uintptr size);
void *realloc(void *ptr, uintptr size);
void free(void *ptr);
-void abort(void);
-#if 0
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <wchar.h>
-#include <errno.h>
-#include <pwd.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-
-typedef wchar_t wchar;
-#endif
-#include <sys/stat.h>
+noreturn void abort(void);
/* must be included first */
#include <base/memory.h>
@@ -52,6 +36,13 @@ typedef wchar_t wchar;
// -----------------------------------------------------------------------------
// variable arguments
+noreturn void ·failassert(const char *, const char *, int, const char *);
+#ifdef NDEBUG
+# define assert(x) (void)0;
+#else
+# define assert(x) ((void)((x) || (·failassert(#x, __FILE__, __LINE__, __func__),0)))
+#endif
+
/* from plan9 libc */
#define ERRMAX 128 /* max length of error string */
diff --git a/include/base/fs.h b/include/base/fs.h
index 0c77f3a..bc639f8 100644
--- a/include/base/fs.h
+++ b/include/base/fs.h
@@ -1,5 +1,20 @@
#pragma once
+/* directories */
+typedef sys·DirEntry fs·DirEntry;
+typedef sys·Directory fs·Directory;
+
+int fs·open(char *path, fs·Directory *dir);
+int fs·openfd(int fd, fs·Directory *dir);
+int fs·close(fs·Directory *dir);
+
+int fs·read(fs·Directory *, fs·DirEntry **);
+
+/* small utilities */
+int fs·access(byte *path, int flag);
+byte *fs·dirname(byte *path);
+byte *fs·basename(byte *path);
+
#define iota(x) 1 << (x)
enum
{
@@ -12,9 +27,6 @@ enum
typedef struct fs·Walker fs·Walker;
typedef struct fs·History fs·History;
-typedef sys·DirEntry fs·DirEntry;
-typedef sys·Directory fs·Directory;
-
/* node in filesystem */
// XXX: simplify with our newer code
@@ -26,7 +38,7 @@ struct fs·Walker
fs·History *hist;
struct {
void *data;
- int (*func)(void *data, char *relp, char *absp, struct stat *info);
+ int (*func)(void *data, char *relp, char *absp, sys·Info *info);
};
char *base, *end, path[4096];
};
@@ -34,8 +46,3 @@ struct fs·Walker
int fs·init(fs·Walker *, char *path);
void fs·fini(fs·Walker *);
void fs·walk(fs·Walker *);
-
-/* small utilities */
-int fs·access(byte *path, int flag);
-byte *fs·dirname(byte *path);
-byte *fs·basename(byte *path);
diff --git a/include/sys.h b/include/sys.h
index 95ed93c..20dafa9 100644
--- a/include/sys.h
+++ b/include/sys.h
@@ -58,7 +58,7 @@ int sys·chdirfd(int fd);
int sys·mkdir(char *path, uint mode);
int sys·mkdirat(int fd, char *path, uint mode);
-int sys·direntry(int fd, int len, void *buffer, uintptr *size);
+int sys·direntry(int fd, void *buffer, uintptr len, uintptr *size);
/* file node */
int sys·mknode(char *path, uint mode, uint64 dev);