From 5977e472ae122bd8135b7428d9093652d51a2cba Mon Sep 17 00:00:00 2001 From: Emil Williams Date: Fri, 20 Feb 2026 23:14:51 +0000 Subject: per notes --- chad/experimental/macros.h | 17 ----------------- chad/experimental/program_directory.c | 13 +++++++++++++ chad/experimental/program_directory.h | 4 ++++ chad/experimental/root.c | 13 ------------- chad/experimental/root.h | 5 ----- chad/experimental/timespec.c | 25 +------------------------ chad/experimental/timespec.h | 18 ++---------------- 7 files changed, 20 insertions(+), 75 deletions(-) delete mode 100644 chad/experimental/macros.h create mode 100644 chad/experimental/program_directory.c create mode 100644 chad/experimental/program_directory.h delete mode 100644 chad/experimental/root.c delete mode 100644 chad/experimental/root.h (limited to 'chad') diff --git a/chad/experimental/macros.h b/chad/experimental/macros.h deleted file mode 100644 index 6b80cb3..0000000 --- a/chad/experimental/macros.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef CHAD_MACROS_H -#define CHAD_MACROS_H -/* Usage of this acknoledges your allegiance to GNU. */ - -/* make it such that [[attributes]] is used in C23 & use GCC otherwise */ -#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L) -# define attribute(...) [[__VA_ARGS__]] -#else -# if defined(__GNUC__) || defined(__clang__) -# define attribute(...) __attribute__((__VA_ARGS__)) -# else -# define attribute(...) -# define NO_ATTRIBUTE -# endif -#endif - -#endif /* CHAD_MACROS_H */ diff --git a/chad/experimental/program_directory.c b/chad/experimental/program_directory.c new file mode 100644 index 0000000..9cf4589 --- /dev/null +++ b/chad/experimental/program_directory.c @@ -0,0 +1,13 @@ +#include +#include +#include +#include +#include +#include +int program_directory(char * filename) { + char path[PATH_MAX], * terminator; + if (!realpath(filename, path) + || !(terminator = strrchr(path, '/'))) { return -1; } + *terminator = '\0'; + return chdir(path); +} diff --git a/chad/experimental/program_directory.h b/chad/experimental/program_directory.h new file mode 100644 index 0000000..d52e563 --- /dev/null +++ b/chad/experimental/program_directory.h @@ -0,0 +1,4 @@ +#ifdef PROGRAM_DIRECTORY_H +#define PROGRAM_DIRECTORY_H +int program_directory(char * filename); +#endif /* PROGRAM_DIRECTORY_H */ diff --git a/chad/experimental/root.c b/chad/experimental/root.c deleted file mode 100644 index f7447eb..0000000 --- a/chad/experimental/root.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include -#include -#include -void Root(char * filename) { - char path[PATH_MAX], * terminator; - if (!realpath(filename, path)) { return; } - if ((terminator = strrchr(path, '/'))) { - *terminator = '\0'; - chdir(path); - } -} diff --git a/chad/experimental/root.h b/chad/experimental/root.h deleted file mode 100644 index e54fd80..0000000 --- a/chad/experimental/root.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifdef CHAD_ROOT_H -#define CHAD_ROOT_H -/* check errno -- chdir */ -void Root(char * filename); -#endif /* CHAD_ROOT_H */ diff --git a/chad/experimental/timespec.c b/chad/experimental/timespec.c index dbcca82..7ce9d00 100644 --- a/chad/experimental/timespec.c +++ b/chad/experimental/timespec.c @@ -2,32 +2,9 @@ /* --- conversion --- */ -f64 timespec_to_f64(timespec_t ts) -{ return (f64) ts.tv_sec + ((f64) ts.tv_nsec / TIMESPEC_HZ); } - -f32 timespec_to_f32(timespec_t ts) -{ return (f32) ts.tv_sec + ((f32) ts.tv_nsec / TIMESPEC_HZ); } - -double timespec_to_double(timespec_t ts) +double timespec2unix(timespec_t ts) { return (double) ts.tv_sec + ((double) ts.tv_nsec / TIMESPEC_HZ); } -float timespec_to_float(timespec_t ts) -{ return (float) ts.tv_sec + ((float) ts.tv_nsec / TIMESPEC_HZ); } - -/* --- from --- */ - -void f64_from_timespec(timespec_t ts, f64 * r) -{ *r = (f64) ts.tv_sec + ((f64) ts.tv_nsec / TIMESPEC_HZ); } - -void f32_from_timespec(timespec_t ts, f32 * r) -{ *r = (f32) ts.tv_sec + ((f32) ts.tv_nsec / TIMESPEC_HZ); } - -void double_from_timespec(timespec_t ts, double * r) -{ *r = (double) ts.tv_sec + ((double) ts.tv_nsec / TIMESPEC_HZ); } - -void float_from_timespec(timespec_t ts, float * r) -{ *r = (float) ts.tv_sec + ((float) ts.tv_nsec / TIMESPEC_HZ); } - /* --- math --- */ timespec_t timespec_add(timespec_t a, timespec_t b) { diff --git a/chad/experimental/timespec.h b/chad/experimental/timespec.h index f72f431..075e0b0 100644 --- a/chad/experimental/timespec.h +++ b/chad/experimental/timespec.h @@ -1,8 +1,8 @@ #ifndef TIMESPEC_H #define TIMESPEC_H /* ripped partly from glibc */ + #include -#include #include /* -- pontentially over designed and undertested. */ @@ -15,21 +15,7 @@ typedef struct timespec timespec_t; static const timespec_t one_second = {1, 0}, zero_seconds = {0, 0}; -f64 timespec_to_f64(timespec_t ts); -f32 timespec_to_f32(timespec_t ts); -double timespec_to_double(timespec_t ts); -float timespec_to_float(timespec_t ts); - -#ifdef TERRY_SMALL_FLOAT_IMPRECISE -#define from_timespec(ts,to) _Generic((to), double *: double_from_timespec, float *: float_from_timespec)(ts,to) -#else -#define from_timespec(ts,to) _Generic((to), f64 *: f64_from_timespec, f32 *: f32_from_timespec, double *: double_from_timespec, float *: float_from_timespec)(ts,to) -#endif - -void f64_from_timespec(timespec_t ts, f64 * r); -void f32_from_timespec(timespec_t ts, f32 * r); -void double_from_timespec(timespec_t ts, double * r); -void float_from_timespec(timespec_t ts, float * r); +double timespec2unix(timespec_t ts); timespec_t timespec_add(timespec_t a, timespec_t b); timespec_t timespec_sub(timespec_t a, timespec_t b); -- cgit v1.2.3