]> Trent Huber's Code - xpmview.git/commitdiff
Updating for Linux portability
authorTrent Huber <trentmhuber@gmail.com>
Wed, 23 Jul 2025 08:20:01 +0000 (04:20 -0400)
committerTrent Huber <trentmhuber@gmail.com>
Wed, 23 Jul 2025 08:20:01 +0000 (04:20 -0400)
external/cbs
src/build.c
src/cbs.h
src/xpm.c

index 280a887eb0b54773a149cbc15b0f911c981edb97..7b11a95b82052299c2844578034b6336c051593a 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 280a887eb0b54773a149cbc15b0f911c981edb97
+Subproject commit 7b11a95b82052299c2844578034b6336c051593a
index 3ac92bcebc4b06b0a8738c9c61e8d1f5b73cee0b..7046058d3fe236829f99fe24aa24477775d25fc0 100644 (file)
@@ -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;
index 70e4f85177b16f00a7725df26cb57de23a539ed0..0c6593bf6da7c7c1dce57e90a124436c942d40c3 100644 (file)
--- 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);
index 5821c3b5b824bc882f2e8e649d64477288c69255..d3ca7219837bb378ed1118ebd0dbff453afca72f 100644 (file)
--- 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;
    }