diff options
| author | Emil Williams | 2026-02-20 23:14:51 +0000 |
|---|---|---|
| committer | Emil Williams | 2026-02-20 23:14:51 +0000 |
| commit | 5977e472ae122bd8135b7428d9093652d51a2cba (patch) | |
| tree | 3ba84f26033306a2bc147100d02b350b900f1c20 | |
| parent | 88e12f4a22111903fc23488898f073502639635c (diff) | |
| download | libchad-5977e472ae122bd8135b7428d9093652d51a2cba.tar.xz libchad-5977e472ae122bd8135b7428d9093652d51a2cba.tar.zst | |
per notes
| -rw-r--r-- | chad.h | 2 | ||||
| -rw-r--r-- | chad/experimental/macros.h | 17 | ||||
| -rw-r--r-- | chad/experimental/program_directory.c | 13 | ||||
| -rw-r--r-- | chad/experimental/program_directory.h | 4 | ||||
| -rw-r--r-- | chad/experimental/root.c | 13 | ||||
| -rw-r--r-- | chad/experimental/root.h | 5 | ||||
| -rw-r--r-- | chad/experimental/timespec.c | 25 | ||||
| -rw-r--r-- | chad/experimental/timespec.h | 18 |
8 files changed, 21 insertions, 76 deletions
@@ -1,10 +1,10 @@ #ifndef CHAD_H #define CHAD_H // internal code -#include "chad/experimental/macros.h" #include "chad/experimental/timespec.h" #include "chad/experimental/bits.h" #include "chad/experimental/terminal.h" +#include "chad/experimental/program_directory.h" #include "chad/dictate.h" #include "chad/qx.h" #include "chad/terry.h" 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 <limits.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <chad/experimental/program_directory.h> +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 <limits.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <chad/experimental/root.h> -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 <time.h> -#include <chad/experimental/macros.h> #include <chad/terry.h> /* -- 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); |
