vtgl

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

Commit: 9e4ce3d75c61473f0378817ff74cb878ba6602f5
Parent: 0ec5ac0404faac569d1dac4f5d6a1b9d4a2ae112
Author: Randy Palamar
Date:   Tue, 10 Sep 2024 21:13:35 -0600

move die() into the platform layer

this also drops usage of stdlib exit() in favour of the syscall.
We are not using libc streams so there is really no loss.

Diffstat:
Mfont.c | 2+-
Mmain.c | 10+++++-----
Mos_unix.c | 30+++++++++++++++++++++++-------
Mterminal.c | 2+-
Mutil.c | 16----------------
5 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/font.c b/font.c @@ -8,7 +8,7 @@ init_font(FontAtlas *fa, Font *f, FontDesc *fdesc) f->buf = map.data; if (!stbtt_InitFont(&f->font_info, f->buf, 0)) - die("stbtt_InitFont: failed on %s\n", fdesc->path); + os_die("stbtt_InitFont: failed on %s\n", fdesc->path); f->fontsize = fdesc->height; f->stbtt_scale = stbtt_ScaleForPixelHeight(&f->font_info, f->fontsize); } diff --git a/main.c b/main.c @@ -98,13 +98,13 @@ static void init_window(Term *t, Arena arena, iv2 requested_size) { if (!glfwInit()) - die("Failed to init GLFW\n"); + os_die("Failed to init GLFW\n"); glfwSetErrorCallback(error_callback); GLFWmonitor *mon = glfwGetPrimaryMonitor(); if (!mon) { glfwTerminate(); - die("Failed to get GLFW monitor\n"); + os_die("Failed to get GLFW monitor\n"); } iv2 ws; @@ -126,7 +126,7 @@ init_window(Term *t, Arena arena, iv2 requested_size) t->gl.window = glfwCreateWindow(t->gl.window_size.w, t->gl.window_size.h, "vtgl", NULL, NULL); if (!t->gl.window) { glfwTerminate(); - die("Failed to spawn GLFW window\n"); + os_die("Failed to spawn GLFW window\n"); } glfwMakeContextCurrent(t->gl.window); glfwSetWindowUserPointer(t->gl.window, t); @@ -287,7 +287,7 @@ check_shaders(GLCtx *gl, Arena a) static void usage(char *argv0) { - die("usage: %s [-v] [-g COLxROW]\n", argv0); + os_die("usage: %s [-v] [-g COLxROW]\n", argv0); } i32 @@ -324,7 +324,7 @@ main(i32 argc, char *argv[]) argc--; break; case 'v': - die("%s " VERSION "\n", argv0); + os_die("%s " VERSION "\n", argv0); default: usage(argv0); } diff --git a/os_unix.c b/os_unix.c @@ -2,6 +2,9 @@ #include <fcntl.h> #include <pty.h> #include <pwd.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> #include <sys/mman.h> #include <sys/select.h> #include <sys/stat.h> @@ -24,6 +27,19 @@ typedef struct { #define OS_MAP_READ PROT_READ #define OS_MAP_PRIVATE MAP_PRIVATE +__attribute__((noreturn)) +static void +os_die(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + _exit(1); +} + static Arena os_new_arena(size cap) { @@ -107,7 +123,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) - die("os_alloc_ring_buffer: failed to open mem_fd\n"); + os_die("os_alloc_ring_buffer: failed to open mem_fd\n"); shm_unlink(mfd_name); ftruncate(fd, capacity); @@ -117,13 +133,13 @@ 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) - die("os_alloc_ring_buffer: initial mmap failed\n"); + os_die("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) - die("os_alloc_ring_buffer: mmap(%d) failed\n", i); + os_die("os_alloc_ring_buffer: mmap(%d) failed\n", i); } close(fd); @@ -186,7 +202,7 @@ execsh(char *defcmd) struct passwd *pw; if ((pw = getpwuid(getuid())) == NULL) - die("are you real?\n"); + os_die("are you real?\n"); if ((sh = getenv("SHELL")) == NULL) sh = pw->pw_shell[0] ? pw->pw_shell : defcmd; @@ -213,7 +229,7 @@ os_fork_child(char *cmd) switch (pid) { case -1: - die("os_fork_child: failed to spawn child: %s\n", cmd); + os_die("os_fork_child: failed to spawn child: %s\n", cmd); case 0: /* child */ execsh(cmd); break; @@ -221,9 +237,9 @@ os_fork_child(char *cmd) i32 flags = fcntl(cfd, F_GETFL); if (flags == -1) - die("os_fork_child: fcntl: F_GETFL\n"); + os_die("os_fork_child: fcntl: F_GETFL\n"); if (fcntl(cfd, F_SETFL, flags | O_NONBLOCK) == -1) - die("os_fork_child: fcntl: F_SETFL\n"); + os_die("os_fork_child: fcntl: F_SETFL\n"); return (os_child){ .pid = pid, .fd = cfd }; } diff --git a/terminal.c b/terminal.c @@ -772,7 +772,7 @@ parse_osc(s8 *raw, OSC *osc) } if (cp != ';' || osc->cmd > 1000) - die("parse_osc: malformed\n"); + os_die("parse_osc: malformed\n"); osc->arg.data = raw->data; while (raw->len) { diff --git a/util.c b/util.c @@ -1,8 +1,4 @@ /* See LICENSE for copyright details */ -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> - static b32 equal_iv2(iv2 a, iv2 b) { @@ -40,18 +36,6 @@ normalize_range(Range r) return result; } -static void __attribute__((noreturn)) -die(char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - - exit(1); -} - static void mem_copy(s8 src, s8 dest) {