From: Trent Huber Date: Wed, 23 Jul 2025 08:20:01 +0000 (-0400) Subject: Updating for Linux portability X-Git-Url: https://trenthuber.com/code?a=commitdiff_plain;h=f1e828b32d5b23ad318223475f55db1d53f24e12;p=xpmview.git Updating for Linux portability --- diff --git a/external/cbs b/external/cbs index 280a887..7b11a95 160000 --- a/external/cbs +++ b/external/cbs @@ -1 +1 @@ -Subproject commit 280a887eb0b54773a149cbc15b0f911c981edb97 +Subproject commit 7b11a95b82052299c2844578034b6336c051593a diff --git a/src/build.c b/src/build.c index 3ac92bc..7046058 100644 --- a/src/build.c +++ b/src/build.c @@ -100,8 +100,8 @@ static void buildfont(void) { lflags = LLRAYLIB; load('x', "buildfont", LIST("buildfont", RLLIB)); - if ((cpid = fork()) == 0) - run("buildfont", LIST("buildfont"), "run", "buildfont"); + if ((cpid = fork()) == -1) err(EXIT_FAILURE, "Unable to fork"); + else if (cpid == 0) run("buildfont", LIST("buildfont"), "run", "buildfont"); await(cpid, "run", "buildfont"); cflags = c; diff --git a/src/cbs.h b/src/cbs.h index 70e4f85..0c6593b 100644 --- a/src/cbs.h +++ b/src/cbs.h @@ -4,8 +4,11 @@ #define DYEXT ".so" #endif +#define NONE (char *[]){NULL} #define LIST(...) (char *[]){__VA_ARGS__, NULL} +extern char **cflags, **lflags; + void *allocate(size_t s); void compile(char *src); void load(char type, char *target, char **objs); diff --git a/src/xpm.c b/src/xpm.c index 5821c3b..d3ca721 100644 --- a/src/xpm.c +++ b/src/xpm.c @@ -217,7 +217,7 @@ static Image process(char *xpm) { int xpmfd, srcfd, e, cpid, status; struct stat xstat; size_t l, offset; - char *map, *p, *a, *tmp, **data; + char *map, *p, *a, *src, *lib, **data; void *d; long *sizep; @@ -246,42 +246,55 @@ static Image process(char *xpm) { goto munmap; } - if ((srcfd = open(TMPSRC, O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) { - warn("Unable to open `" TMPSRC "'"); + src = "/tmp/xpm.c"; + if ((srcfd = open(src, O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) { + warn("Unable to open `%s'", src); goto munmap; } e = !writeall(srcfd, p, l - offset) || dprintf(srcfd, "\n\nlong size = sizeof %s / sizeof*%s;\n", a, a) < 0; if (close(srcfd) == -1) { - warn("Unable to close `" TMPSRC "'"); + warn("Unable to close `%s'", src); goto munmap; } if (e) { - warn("Unable to write to `" TMPSRC "'"); + warn("Unable to write to `%s'", src); goto munmap; } - if ((cpid = fork()) == 0) { - compile(TMP); - load('d', TMP, LIST(TMP)); - exit(EXIT_SUCCESS); + lib = "/tmp/libxpm" DYEXT; + if ((cpid = fork()) == -1) { + warn("Unable to fork process to create `%s'", lib); + goto munmap; + } else if (cpid == 0) { + cflags = NONE; + compile("/tmp/xpm"); + + lflags = NONE; + load('d', "/tmp/xpm", LIST("/tmp/xpm")); + + _exit(EXIT_SUCCESS); } if (cpid == -1 || waitpid(cpid, &status, 0) == -1) { - warn("Unable to create `" TMPLIB "'"); + warn("Creation of `%s' terminated unexpectedly", lib); + goto munmap; + } + if (WIFEXITED(status) && WEXITSTATUS(status) != EXIT_SUCCESS + || WIFSIGNALED(status)) { + warnx("Creation of `%s' was unsuccessful", lib); goto munmap; } - if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS) goto munmap; - if ((d = dlopen(TMPLIB, RTLD_LAZY)) == NULL) { - warnx("Unable to load `" TMPLIB "': %s", dlerror()); + if ((d = dlopen(lib, RTLD_LAZY)) == NULL) { + warnx("Unable to load `%s': %s", lib, dlerror()); goto munmap; } if ((data = (char **)dlsym(d, a)) == NULL) { - warnx("Unable to load image data from `" TMPLIB "': `%s'", dlerror()); + warnx("Unable to load image data from `%s': `%s'", lib, dlerror()); goto dlclose; } if ((sizep = (long *)dlsym(d, "size")) == NULL) { - warnx("Unable to load image size from `" TMPLIB "': `%s'", dlerror()); + warnx("Unable to load image size from `%s': `%s'", lib, dlerror()); goto dlclose; } @@ -289,7 +302,7 @@ static Image process(char *xpm) { dlclose: if (dlclose(d)) { - warnx("Unable to unload `" TMPLIB "': %s", dlerror()); + warnx("Unable to unload `%s': %s", lib, dlerror()); result.mipmaps = 0; }