vtgl

terminal emulator implemented in OpenGL
git clone anongit@rnpnr.xyz:vtgl.git
Log | Files | Refs | Feed | LICENSE

Commit: 7805c91014126f6be0c923847cd36cb107e342f6
Parent: 8bb1ff95114b49c230f15310f6ffac5fcc1d709e
Author: Randy Palamar
Date:   Thu, 24 Oct 2024 21:48:18 -0600

drop stdarg.h

Diffstat:
Mmain.c | 13++++++++-----
Mos_unix.c | 34++++++++++++----------------------
Mterminal.c | 2+-
3 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/main.c b/main.c @@ -117,7 +117,7 @@ init_window(Term *t, Arena arena, iv2 window_size) t->gl.window = glfwCreateWindow(t->gl.window_size.w, t->gl.window_size.h, "vtgl", NULL, NULL); if (!t->gl.window) { glfwTerminate(); - os_die("Failed to spawn GLFW window\n"); + os_fatal(s8("Failed to spawn GLFW window\n")); } glfwMakeContextCurrent(t->gl.window); glfwSetWindowUserPointer(t->gl.window, t); @@ -314,7 +314,9 @@ check_shaders(GLCtx *gl, Arena a) static void usage(char *argv0) { - os_die("usage: %s [-v] [-g COLxROW]\n", argv0); + os_write_err_msg(s8("usage: ")); + os_write_err_msg(c_str_to_s8(argv0)); + os_fatal(s8(" [-v] [-g COLxROW]\n")); } i32 @@ -351,7 +353,8 @@ main(i32 argc, char *argv[]) argc--; break; case 'v': - os_die("%s " VERSION "\n", argv0); + os_write_err_msg(c_str_to_s8(argv0)); + os_fatal(s8(" " VERSION "\n")); default: usage(argv0); } @@ -360,13 +363,13 @@ main(i32 argc, char *argv[]) do_debug(NULL); if (!glfwInit()) - os_die("Failed to init GLFW\n"); + os_fatal(s8("Failed to init GLFW\n")); glfwSetErrorCallback(error_callback); GLFWmonitor *mon = glfwGetPrimaryMonitor(); if (!mon) { glfwTerminate(); - os_die("Failed to get GLFW monitor\n"); + os_fatal(s8("Failed to get GLFW monitor\n")); } iv2 ws; diff --git a/os_unix.c b/os_unix.c @@ -2,7 +2,6 @@ #include <fcntl.h> #include <pty.h> #include <pwd.h> -#include <stdarg.h> #include <stdio.h> #include <sys/mman.h> #include <sys/select.h> @@ -44,19 +43,6 @@ os_write_err_msg(s8 msg) __attribute__((noreturn)) static void -os_die(char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - - _exit(1); -} - -__attribute__((noreturn)) -static void os_fatal(s8 msg) { os_write_err_msg(msg); @@ -146,7 +132,7 @@ os_alloc_ring_buffer(RingBuf *rb, size capacity) char *mfd_name = "vtgl:rb"; i32 fd = shm_open(mfd_name, O_RDWR|O_CREAT, 0600); if (fd == -1) - os_die("os_alloc_ring_buffer: failed to open mem_fd\n"); + os_fatal(s8("os_alloc_ring_buffer: failed to open mem_fd\n")); shm_unlink(mfd_name); ftruncate(fd, capacity); @@ -156,13 +142,15 @@ os_alloc_ring_buffer(RingBuf *rb, size capacity) rb->buf = mmap(0, 3 * rb->cap, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); if (rb->buf == MAP_FAILED) - os_die("os_alloc_ring_buffer: initial mmap failed\n"); + os_fatal(s8("os_alloc_ring_buffer: initial mmap failed\n")); for (i32 i = 0; i < 3; i++) { void *ret = mmap(rb->buf + i * rb->cap, rb->cap, PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, fd, 0); - if (ret == MAP_FAILED) - os_die("os_alloc_ring_buffer: mmap(%d) failed\n", i); + if (ret == MAP_FAILED) { + fprintf(stderr, "os_alloc_ring_buffer: mmap(%d) failed\n", i); + _exit(1); + } } close(fd); @@ -225,7 +213,7 @@ execsh(char *defcmd) struct passwd *pw; if ((pw = getpwuid(getuid())) == NULL) - os_die("are you real?\n"); + os_fatal(s8("are you real?\n")); if ((sh = getenv("SHELL")) == NULL) sh = pw->pw_shell[0] ? pw->pw_shell : defcmd; @@ -252,7 +240,9 @@ os_fork_child(char *cmd) switch (pid) { case -1: - os_die("os_fork_child: failed to spawn child: %s\n", cmd); + os_write_err_msg(s8("os_fork_child: failed to spawn child: ")); + os_write_err_msg(c_str_to_s8(cmd)); + os_fatal(s8("\n")); case 0: /* child */ execsh(cmd); break; @@ -260,9 +250,9 @@ os_fork_child(char *cmd) i32 flags = fcntl(cfd, F_GETFL); if (flags == -1) - os_die("os_fork_child: fcntl: F_GETFL\n"); + os_fatal(s8("os_fork_child: fcntl: F_GETFL\n")); if (fcntl(cfd, F_SETFL, flags | O_NONBLOCK) == -1) - os_die("os_fork_child: fcntl: F_SETFL\n"); + os_fatal(s8("os_fork_child: fcntl: F_SETFL\n")); return (os_child){ .pid = pid, .fd = cfd }; } diff --git a/terminal.c b/terminal.c @@ -870,7 +870,7 @@ parse_osc(s8 *raw, OSC *osc) } if (cp != ';' || osc->cmd > 1000) - os_die("parse_osc: malformed\n"); + os_fatal(s8("parse_osc: malformed\n")); osc->arg.data = raw->data; while (raw->len) {