logo

utils

Old programs, got split in utils-std and utils-extra git clone https://hacktivis.me/git/utils.git
commit: b935e1df4baff492e2986717444ef15ff3a32521
parent 8344a73a488f14129789181d5a1d829e3ee31851
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 24 Sep 2023 17:28:08 +0200

lib/iso_parse: Remove

Diffstat:

MMakefile8--------
Dlib/iso_parse.c80-------------------------------------------------------------------------------
Dlib/iso_parse.h6------
3 files changed, 0 insertions(+), 94 deletions(-)

diff --git a/Makefile b/Makefile @@ -63,11 +63,3 @@ cmd/lolcat: cmd/lolcat.c Makefile cmd/xcd: cmd/xcd.c Makefile rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} $(CC) -std=c99 $(CFLAGS) -o $@ cmd/xcd.c -lm $(LDFLAGS) - -cmd/date: cmd/date.c lib/iso_parse.c Makefile - rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} - $(CC) -std=c99 $(CFLAGS) -o $@ cmd/date.c lib/iso_parse.c $(LDFLAGS) - -cmd/touch: cmd/touch.c lib/iso_parse.c Makefile - rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} - $(CC) -std=c99 $(CFLAGS) -o $@ cmd/touch.c lib/iso_parse.c $(LDFLAGS) diff --git a/lib/iso_parse.c b/lib/iso_parse.c @@ -1,80 +0,0 @@ -// Collection of Unix tools, comparable to coreutils -// SPDX-FileCopyrightText: 2023 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -// SPDX-License-Identifier: MPL-2.0 - -#define _DEFAULT_SOURCE // tm_gmtoff/tm_zone -#define _XOPEN_SOURCE 700 // strptime (NetBSD) -#define _POSIX_C_SOURCE 200809L // st_atim/st_mtim - -#include <ctype.h> /* isdigit */ -#include <errno.h> /* errno */ -#include <stdio.h> /* perror, sscanf */ -#include <stdlib.h> /* exit */ -#include <string.h> /* memset */ -#include <time.h> /* strptime, tm */ - -// Calls exit() on failure -struct timespec -iso_parse(char *arg) -{ - // YYYY-MM-DD[T ]hh:mm:SS([,\.]frac)?Z? - // Dammit Unixes why no nanoseconds in `struct tm` nor `strptime` - struct timespec time = {.tv_sec = 0, .tv_nsec = 0}; - - // For Alpine's abuild compatibility - if(arg[0] == '@') - { - arg++; - errno = 0; - - time.tv_sec = strtol(arg, NULL, 10); - if(errno != 0) - { - perror("strtol"); - exit(EXIT_FAILURE); - } - return time; - } - - struct tm tm; - memset(&tm, 0, sizeof(tm)); - - // No %F in POSIX - char *s = strptime(arg, "%Y-%m-%d", &tm); - - if(s[0] != 'T' && s[0] != ' ') exit(EXIT_FAILURE); - s++; - - s = strptime(s, "%H:%M:%S", &tm); - - if(s[0] == ',' || s[0] == '.') - { - double fraction = 0.0; - int parsed = 0; - - if(s[0] == ',') s[0] = '.'; - - if(sscanf(s, "%10lf%n", &fraction, &parsed) < 1) exit(EXIT_FAILURE); - - time.tv_nsec = fraction * 1000000000; - s += parsed; - - // too many digits - if(isdigit(s[0])) exit(EXIT_FAILURE); - } - - if(s[0] == 'Z') - { - tm.tm_gmtoff = 0; - tm.tm_zone = "UTC"; - } - - time.tv_sec = mktime(&tm); - if(time.tv_sec == (time_t)-1) - { - perror("mktime"); - exit(EXIT_FAILURE); - } - - return time; -} diff --git a/lib/iso_parse.h b/lib/iso_parse.h @@ -1,6 +0,0 @@ -// Collection of Unix tools, comparable to coreutils -// SPDX-FileCopyrightText: 2023 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -// SPDX-License-Identifier: MPL-2.0 - -#include <time.h> /* struct timespec */ -extern struct timespec iso_parse(char *);