diff mrjunejune/latex_renderer.c @ 248:b8b6e726964a

[style] Use Dowa type aliases in C Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Tue, 04 Aug 2026 02:44:06 -0700
parents 70f2a3dafc1c
children
line wrap: on
line diff
--- a/mrjunejune/latex_renderer.c	Mon Aug 03 20:20:06 2026 -0700
+++ b/mrjunejune/latex_renderer.c	Tue Aug 04 02:44:06 2026 -0700
@@ -12,7 +12,6 @@
 #include <limits.h>
 #include <poll.h>
 #include <signal.h>
-#include <stdbool.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -68,7 +67,7 @@
   };
 }
 
-static bool write_all(int fd, const uint8_t *data, size_t size)
+static boolean write_all(int fd, const uint8 *data, size_t size)
 {
   while (size > 0)
   {
@@ -77,12 +76,12 @@
     {
       if (errno == EINTR)
         continue;
-      return false;
+      return FALSE;
     }
     data += written;
     size -= (size_t)written;
   }
-  return true;
+  return TRUE;
 }
 
 static int remove_tree(const char *path, unsigned depth)
@@ -127,7 +126,7 @@
   return result == 0 ? rmdir(path) : result;
 }
 
-static bool set_limit(int resource, rlim_t value)
+static boolean set_limit(int resource, rlim_t value)
 {
   struct rlimit limit = {
     .rlim_cur = value,
@@ -136,18 +135,18 @@
   return setrlimit(resource, &limit) == 0;
 }
 
-static bool add_landlock_path_rule(
+static boolean add_landlock_path_rule(
     int ruleset_fd,
     const char *path,
-    uint64_t access,
-    bool required)
+    uint64 access,
+    boolean required)
 {
   int path_fd = open(path, O_PATH | O_CLOEXEC);
   if (path_fd < 0)
     return !required && errno == ENOENT;
 
   struct stat status;
-  bool ok = fstat(path_fd, &status) == 0;
+  boolean ok = fstat(path_fd, &status) == 0;
   if (ok && !S_ISDIR(status.st_mode))
   {
     access &= LANDLOCK_ACCESS_FS_EXECUTE |
@@ -170,26 +169,26 @@
   return ok;
 }
 
-static bool add_landlock_tree_rules(
+static boolean add_landlock_tree_rules(
     int ruleset_fd,
     const char *path,
-    uint64_t access,
+    uint64 access,
     unsigned depth)
 {
   if (depth > 32 ||
-      !add_landlock_path_rule(ruleset_fd, path, access, true))
-    return false;
+      !add_landlock_path_rule(ruleset_fd, path, access, TRUE))
+    return FALSE;
 
   struct stat status;
   if (lstat(path, &status) != 0)
-    return false;
+    return FALSE;
   if (!S_ISDIR(status.st_mode))
-    return true;
+    return TRUE;
 
   DIR *directory = opendir(path);
   if (!directory)
-    return false;
-  bool ok = true;
+    return FALSE;
+  boolean ok = TRUE;
   struct dirent *entry;
   while (ok && (entry = readdir(directory)) != NULL)
   {
@@ -215,7 +214,7 @@
   return ok;
 }
 
-static bool apply_filesystem_sandbox(
+static boolean apply_filesystem_sandbox(
     const char *job_directory,
     const char *compiler,
     const char *cache_directory,
@@ -227,13 +226,13 @@
       0,
       LANDLOCK_CREATE_RULESET_VERSION);
   if (abi < 1)
-    return false;
+    return FALSE;
 
-  uint64_t read_access =
+  uint64 read_access =
       LANDLOCK_ACCESS_FS_EXECUTE |
       LANDLOCK_ACCESS_FS_READ_FILE |
       LANDLOCK_ACCESS_FS_READ_DIR;
-  uint64_t write_access =
+  uint64 write_access =
       LANDLOCK_ACCESS_FS_WRITE_FILE |
       LANDLOCK_ACCESS_FS_REMOVE_DIR |
       LANDLOCK_ACCESS_FS_REMOVE_FILE |
@@ -258,15 +257,15 @@
       sizeof(ruleset),
       0);
   if (ruleset_fd < 0)
-    return false;
+    return FALSE;
 
-  bool ok = true;
+  boolean ok = TRUE;
   if (ok)
     ok = add_landlock_path_rule(
         ruleset_fd,
         compiler,
         LANDLOCK_ACCESS_FS_EXECUTE | LANDLOCK_ACCESS_FS_READ_FILE,
-        true);
+        TRUE);
   if (ok)
     ok = add_landlock_tree_rules(
         ruleset_fd,
@@ -284,19 +283,19 @@
         ruleset_fd,
         "/dev/null",
         LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_WRITE_FILE,
-        true);
+        TRUE);
   if (ok)
     ok = add_landlock_path_rule(
         ruleset_fd,
         "/dev/urandom",
         LANDLOCK_ACCESS_FS_READ_FILE,
-        false);
+        FALSE);
   if (ok)
     ok = add_landlock_path_rule(
         ruleset_fd,
         job_directory,
         read_access | write_access,
-        true);
+        TRUE);
   if (ok)
     ok = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == 0;
   if (ok)
@@ -308,10 +307,10 @@
   return ok;
 }
 
-static bool apply_network_sandbox(void)
+static boolean apply_network_sandbox(void)
 {
   if (LATEX_AUDIT_ARCH == 0)
-    return false;
+    return FALSE;
 
   struct sock_filter filters[64];
   size_t count = 0;
@@ -469,7 +468,7 @@
     int output_fd,
     char *diagnostics,
     size_t diagnostics_size,
-    bool *timed_out)
+    boolean *timed_out)
 {
   int flags = fcntl(output_fd, F_GETFL, 0);
   if (flags >= 0)
@@ -477,7 +476,7 @@
 
   size_t used = 0;
   int child_status = 0;
-  bool child_done = false;
+  boolean child_done = FALSE;
   struct timespec start;
   clock_gettime(CLOCK_MONOTONIC, &start);
 
@@ -499,7 +498,7 @@
     pid_t waited = waitpid(child, &child_status, WNOHANG);
     if (waited == child)
     {
-      child_done = true;
+      child_done = TRUE;
       break;
     }
     if (waited < 0 && errno != EINTR)
@@ -509,12 +508,12 @@
     clock_gettime(CLOCK_MONOTONIC, &now);
     if (elapsed_seconds(&start, &now) >= LATEX_WALL_TIMEOUT_SECONDS)
     {
-      *timed_out = true;
+      *timed_out = TRUE;
       kill(-child, SIGKILL);
       while (waitpid(child, &child_status, 0) < 0 && errno == EINTR)
       {
       }
-      child_done = true;
+      child_done = TRUE;
       break;
     }
 
@@ -542,21 +541,21 @@
   return child_status;
 }
 
-static bool read_pdf(
+static boolean read_pdf(
     const char *path,
-    uint8_t **data,
+    uint8 **data,
     size_t *size)
 {
   int fd = open(path, O_RDONLY | O_CLOEXEC | O_NOFOLLOW);
   if (fd < 0)
-    return false;
+    return FALSE;
 
   struct stat status;
-  bool ok = fstat(fd, &status) == 0 &&
+  boolean ok = fstat(fd, &status) == 0 &&
       S_ISREG(status.st_mode) &&
       status.st_size > 4 &&
       status.st_size <= LATEX_PDF_MAX_BYTES;
-  uint8_t *content = NULL;
+  uint8 *content = NULL;
   if (ok)
   {
     content = malloc((size_t)status.st_size);
@@ -573,7 +572,7 @@
       continue;
     if (count <= 0)
     {
-      ok = false;
+      ok = FALSE;
       break;
     }
     offset += (size_t)count;
@@ -584,19 +583,19 @@
       memcmp(content, "%PDF-", 5) != 0)
   {
     free(content);
-    return false;
+    return FALSE;
   }
   *data = content;
   *size = offset;
-  return true;
+  return TRUE;
 }
 
-static bool resolve_runtime_path(
+static boolean resolve_runtime_path(
     const char *relative_path,
     char resolved[PATH_MAX])
 {
   if (realpath(relative_path, resolved))
-    return true;
+    return TRUE;
 
   const char *runfiles = getenv("RUNFILES_DIR");
   const char *workspace = getenv("TEST_WORKSPACE");
@@ -613,7 +612,7 @@
     if (length >= 0 &&
         (size_t)length < sizeof(candidate) &&
         realpath(candidate, resolved))
-      return true;
+      return TRUE;
   }
 
   char executable[PATH_MAX];
@@ -622,7 +621,7 @@
       executable,
       sizeof(executable) - 1);
   if (executable_length <= 0)
-    return false;
+    return FALSE;
   executable[executable_length] = '\0';
 
   char *last_slash = strrchr(executable, '/');
@@ -638,12 +637,12 @@
     if (length >= 0 &&
         (size_t)length < sizeof(candidate) &&
         realpath(candidate, resolved))
-      return true;
+      return TRUE;
   }
 
   char *package = strstr(executable, "/mrjunejune/");
   if (!package)
-    return false;
+    return FALSE;
   *package = '\0';
   int length = snprintf(
       candidate,
@@ -656,7 +655,7 @@
       realpath(candidate, resolved) != NULL;
 }
 
-Latex_Render_Result Latex_Render(const uint8_t *source, size_t source_size)
+Latex_Render_Result Latex_Render(const uint8 *source, size_t source_size)
 {
   if (!source || source_size == 0)
     return result_with_message(
@@ -755,7 +754,7 @@
         "Unable to allocate compiler diagnostics.");
   }
 
-  bool timed_out = false;
+  boolean timed_out = FALSE;
   int child_status = wait_for_compiler(
       child,
       output_pipe[0],
@@ -841,7 +840,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-Latex_Render_Result Latex_Render(const uint8_t *source, size_t source_size)
+Latex_Render_Result Latex_Render(const uint8 *source, size_t source_size)
 {
   (void)source;
   (void)source_size;