* [musl] [PATCH] POSIX 2024: strptime %F
@ 2024-08-01 4:24 Oliver Webb
2024-08-01 4:43 ` Oliver Webb
0 siblings, 1 reply; 3+ messages in thread
From: Oliver Webb @ 2024-08-01 4:24 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 504 bytes --]
Looking at POSIX 2024, One of the features that I
noticed wasn't in musl was some of the strptime()
specifiers.
Out of the strptime specifiers that POSIX 2024 added
(https://sortix.org/blog/posix-2024/), %F seems to be
the only specifier that can be implemented without
significantly changing the structure of the function
(i.e. Running code after the numeric range code with a
jump or function pointer, with that %s, %u, etc. become
much easier)
- Oliver Webb <aquahobbyist@proton.me>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-strptime-F.patch --]
[-- Type: text/x-patch; name=0001-strptime-F.patch, Size: 709 bytes --]
From 9365250e4e95369f2a708707a9c43840211f2314 Mon Sep 17 00:00:00 2001
From: Oliver Webb <aquahobbyist@proton.me>
Date: Wed, 31 Jul 2024 23:13:53 -0500
Subject: [PATCH] strptime %F
---
src/time/strptime.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/time/strptime.c b/src/time/strptime.c
index c54a0d8c..05c28b71 100644
--- a/src/time/strptime.c
+++ b/src/time/strptime.c
@@ -55,6 +55,10 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
min = 1;
range = 31;
goto numeric_range;
+ case 'F':
+ s = strptime(s, "%Y-%m-%d", tm);
+ if (!s) return 0;
+ break;
case 'D':
s = strptime(s, "%m/%d/%y", tm);
if (!s) return 0;
--
2.46.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [musl] [PATCH] POSIX 2024: strptime %F
2024-08-01 4:24 [musl] [PATCH] POSIX 2024: strptime %F Oliver Webb
@ 2024-08-01 4:43 ` Oliver Webb
2024-08-01 6:30 ` Rich Felker
0 siblings, 1 reply; 3+ messages in thread
From: Oliver Webb @ 2024-08-01 4:43 UTC (permalink / raw)
To: musl
I think I have discovered a way to implement strptime %s, %U, etc, with function pointers
to call back to code after numeric_range is done (i.e "if (after) after(*dest, tm)" at the
end of the numeric_range code with "after" being a function pointer set in a case statement).
This, however, would add a fair amount of complexity to the code (multiple static functions
in src/time/strptime.c). I can implement it without much trouble. But I wanna know if this
complexity is considered worth it before I put effort into implementing/testing it.
Maybe there's a alternative way to do it without duplicating code or splitting functions?
- Oliver Webb aquahobbyist@proton.me
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [musl] [PATCH] POSIX 2024: strptime %F
2024-08-01 4:43 ` Oliver Webb
@ 2024-08-01 6:30 ` Rich Felker
0 siblings, 0 replies; 3+ messages in thread
From: Rich Felker @ 2024-08-01 6:30 UTC (permalink / raw)
To: Oliver Webb; +Cc: musl
On Thu, Aug 01, 2024 at 04:43:17AM +0000, Oliver Webb wrote:
> I think I have discovered a way to implement strptime %s, %U, etc,
> with function pointers to call back to code after numeric_range is
> done (i.e "if (after) after(*dest, tm)" at the end of the
> numeric_range code with "after" being a function pointer set in a
> case statement).
>
> This, however, would add a fair amount of complexity to the code
> (multiple static functions in src/time/strptime.c). I can implement
> it without much trouble. But I wanna know if this complexity is
> considered worth it before I put effort into implementing/testing
> it. Maybe there's a alternative way to do it without duplicating
> code or splitting functions?
See commit fced99e93daeefb0192fd16304f978d4401d1d77 which already did
all of the new specifiers.
You seem to be overlooking that the new additions to POSIX do not
specify doing any kind of conversion for these specifiers, just
parsing (the effect on the struct tm is unspecified).
Rich
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-08-01 6:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-01 4:24 [musl] [PATCH] POSIX 2024: strptime %F Oliver Webb
2024-08-01 4:43 ` Oliver Webb
2024-08-01 6:30 ` Rich Felker
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).