diff options
author | Ian Moffett <ian@osmora.org> | 2024-03-07 17:28:00 -0500 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-03-07 17:28:32 -0500 |
commit | bd5969fc876a10b18613302db7087ef3c40f18e1 (patch) | |
tree | 7c2b8619afe902abf99570df2873fbdf40a4d1a1 /lib/mlibc/sysdeps/ironclad/generic/utmpx.cpp | |
parent | a95b38b1b92b172e6cc4e8e56a88a30cc65907b0 (diff) |
lib: Add mlibc
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/sysdeps/ironclad/generic/utmpx.cpp')
-rw-r--r-- | lib/mlibc/sysdeps/ironclad/generic/utmpx.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/mlibc/sysdeps/ironclad/generic/utmpx.cpp b/lib/mlibc/sysdeps/ironclad/generic/utmpx.cpp new file mode 100644 index 0000000..ec74e22 --- /dev/null +++ b/lib/mlibc/sysdeps/ironclad/generic/utmpx.cpp @@ -0,0 +1,76 @@ +#include <bits/ensure.h> +#include <stddef.h> +#include <errno.h> +#include <utmpx.h> +#include <stdio.h> +#include <time.h> +#include <paths.h> +#include <unistd.h> +#include <fcntl.h> + +int utmpx_file = -1; + +void updwtmpx(const char *, const struct utmpx *) { + // Empty as musl does +} + +void endutxent(void) { + if (utmpx_file >= 0) { + close(utmpx_file); + } +} + +void setutxent(void) { + if (utmpx_file < 0) { + utmpx_file = open(UTMPX_FILE, O_RDWR | O_CREAT, 0755); + } else { + lseek(utmpx_file, 0, SEEK_SET); + } +} + +struct utmpx returned; + +struct utmpx *getutxent(void) { + if (utmpx_file < 0) { + setutxent(); + if (utmpx_file < 0) { + return NULL; + } + } + + if (read(utmpx_file, &returned, sizeof(struct utmpx)) != sizeof(struct utmpx)) { + return NULL; + } + + return &returned; +} + +struct utmpx *pututxline(const struct utmpx *added) { + if (utmpx_file < 0) { + setutxent(); + if (utmpx_file < 0) { + return NULL; + } + } + + lseek(utmpx_file, 0, SEEK_END); + if (write(utmpx_file, added, sizeof(struct utmpx)) != sizeof(struct utmpx)) { + return NULL; + } + + return (struct utmpx *)added; +} + +int utmpxname(const char *path) { + if (utmpx_file > 0) { + close(utmpx_file); + } + + utmpx_file = open(path, O_RDWR | O_CREAT, 0755); + if (utmpx_file > 0) { + lseek(utmpx_file, 0, SEEK_END); + return 1; + } else { + return 0; + } +} |