aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicholas <nbnoll@eml.cc>2021-11-20 17:07:23 -0800
committerNicholas <nbnoll@eml.cc>2021-11-20 17:07:23 -0800
commitc9a32c1a43d2bdded07eaa45732c3a6e195a5442 (patch)
treecb7e9cb8c34cbe6551b801eff4201afcf71dd0fd /src
parente97c8c469db0aa27985dab2879dc1f14905c7387 (diff)
Chore: cleaned up the exit code to cleanly interface with libc
We use weak linking to ensure we clean up at exit time correctly. If libc is linked, then we call our cleanup function by registering an atexit callback with the library. If libc is not linked, we have a weak symbol that results in a noop. Similarly, if we call rt·exit while linked with libc, this immediately calls libc's exit (which will call our cleanup as we registered it). If we are not linked to libc, exit() is given as a weak link to a noop function.
Diffstat (limited to 'src')
-rw-r--r--src/base/bufio/internal.h2
-rw-r--r--src/base/fmt/test.c9
-rw-r--r--src/base/gz/seek.c2
-rw-r--r--src/base/io/interface.c2
-rw-r--r--src/base/io/seek.c4
-rw-r--r--src/rules.mk8
6 files changed, 19 insertions, 8 deletions
diff --git a/src/base/bufio/internal.h b/src/base/bufio/internal.h
index a1a006a..a59e787 100644
--- a/src/base/bufio/internal.h
+++ b/src/base/bufio/internal.h
@@ -1,2 +1,4 @@
#include <u.h>
#include <base.h>
+
+#define header(io) ((io·Header*)(io))
diff --git a/src/base/fmt/test.c b/src/base/fmt/test.c
index 73f5e7c..3f7f070 100644
--- a/src/base/fmt/test.c
+++ b/src/base/fmt/test.c
@@ -15,9 +15,18 @@ Xfmt(fmt·State *io)
return fmt·write(io, "(real=%g,imag=%g)", c.r, c.i);
}
+static void
+saygoodbye(void *arg)
+{
+ intptr n;
+ sys·write(1, 9, "goodbye\n", &n);
+}
+
int
main(int argc, char *argv[])
{
+ rt·atexit(saygoodbye, nil);
+
fmt·print("basic tests\n");
fmt·print("\tx: %x\n", 0x87654321);
fmt·print("\tu: %u\n", 0x87654321);
diff --git a/src/base/gz/seek.c b/src/base/gz/seek.c
index 328886d..8230a79 100644
--- a/src/base/gz/seek.c
+++ b/src/base/gz/seek.c
@@ -1,7 +1,7 @@
#include "internal.h"
int
-gz·seek(gz·Stream *s, long off, enum SeekPos whence)
+gz·seek(gz·Stream *s, long off, int whence)
{
return gzseek(s, off, whence);
}
diff --git a/src/base/io/interface.c b/src/base/io/interface.c
index bc9d5ff..80469bf 100644
--- a/src/base/io/interface.c
+++ b/src/base/io/interface.c
@@ -44,7 +44,7 @@ int
static
int
-·seek(void *skr, long off, enum SeekPos whence)
+·seek(void *skr, long off, int whence)
{
return io·seek((io·Stream *)skr, off, whence);
}
diff --git a/src/base/io/seek.c b/src/base/io/seek.c
index d0e7488..1be4ee7 100644
--- a/src/base/io/seek.c
+++ b/src/base/io/seek.c
@@ -1,7 +1,7 @@
#include "internal.h"
int
-io·seek(io·Stream *s, long off, enum SeekPos origin)
+io·seek(io·Stream *s, long off, int whence)
{
- return fseek(s, off, origin);
+ return fseek(s, off, whence);
}
diff --git a/src/rules.mk b/src/rules.mk
index 8e8594c..368479c 100644
--- a/src/rules.mk
+++ b/src/rules.mk
@@ -8,10 +8,10 @@ include $(DIR)/rules.mk
DIR := $(d)/base
include $(DIR)/rules.mk
-# DIR := $(d)/libmath
-# include $(DIR)/rules.mk
+DIR := $(d)/libmath
+include $(DIR)/rules.mk
-# DIR := $(d)/libbio
-# include $(DIR)/rules.mk
+DIR := $(d)/libbio
+include $(DIR)/rules.mk
include share/pop.mk