aboutsummaryrefslogtreecommitdiffhomepage
path: root/io.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-10-13 19:06:52 +0200
committerlemon <lsof@mailbox.org>2025-10-13 19:09:48 +0200
commit9812f88a9a612144bea02c7acf499867eb0cbeb9 (patch)
tree0575b7c6b6b72b0683c4ffae108292b3d44998be /io.c
parent3048a0b59baae16727d0c259353ff4be1ae559b4 (diff)
implement most of preprocessor
- concatenation (##) - builtin macros (__FILE__ etc) - fails in some edge cases, and code needs cleanup - add embedded system include files (stddef.h, stdarg.h for now) - can handle stdio.h now
Diffstat (limited to 'io.c')
-rw-r--r--io.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/io.c b/io.c
index 592cf48..2a9e876 100644
--- a/io.c
+++ b/io.c
@@ -627,6 +627,8 @@ bfmt(struct wbuf *buf, const char *fmt, ...)
static uint pagesiz;
+extern struct embedfile embedfilesdir[];
+
struct memfile
mapopen(const char **err, const char *path)
{
@@ -641,6 +643,14 @@ mapopen(const char **err, const char *path)
if (!pagesiz) pagesiz = sysconf(_SC_PAGESIZE);
*err = NULL;
+ if (*path == '@' && path[1] == ':') {
+ for (struct embedfile *e = embedfilesdir; e->name; ++e) {
+ if (!strcmp(e->name, path+2)) {
+ return (struct memfile) { (const uchar *)e->s, e->len, .statik = 1 };
+ }
+ }
+ }
+
if ((fd = open(path, O_RDONLY)) < 0)
goto Err;
if (fstat(fd, &stat) != 0)
@@ -707,7 +717,8 @@ void
mapclose(struct memfile *f)
{
assert(f->p);
- munmap((void *)f->p, alignup(f->n, pagesiz) + pagesiz);
+ if (!f->statik)
+ munmap((void *)f->p, alignup(f->n, pagesiz) + pagesiz);
memset(f, 0, sizeof *f);
}
@@ -793,8 +804,8 @@ getfilepos(int *line, int *col, int id, uint off)
else break;
}
i -= offs[i] > off;
- *line = i + 1;
- *col = off - offs[i] + 1;
+ if (line) *line = i + 1;
+ if (col) *col = off - offs[i] + 1;
}
void