Elektrine lite

← Feed

@bert_hubert@fosstodon.org

Post #2239343

2025-01-18 16:01 UTC

I have finally found an up to date standard that covers mktime(), https://pubs.opengroup.org/onlinepubs/9799919799/functions/mktime.html - and in it we learn that on error mktime returns the valid timestamp -1 (which happened in 1969 UTC). To detect if this was an actual error, callers must set tm.tm_wday to -1, and check if after a call it is still -1. In that case, an error happened.

Replies (7)

  • @bert_hubert@fosstodon.org 2025-01-18 16:47

    Similarly, if your copy of the strptime() manpage left you with any hope on what it would do for you wrt timezones, I can highly recommend https://pubs.opengroup.org/onlinepubs/9799919799/functions/strptime.html "%z: The effect of this offset, if any, on the tm structure pointed to by tm is unspecified." %Z meanwhile is -somewhat- specified, but likely does not do what you'd think.

    Open ##2239344

  • @revk@toot.me.uk 2025-01-18 16:02

    @bert_hubert@fosstodon.org yeh, sorry, that I knew!

    Open ##2239427

  • @fubaroque@mastodon.social 2025-01-18 16:53

    @bert_hubert@fosstodon.org Sweet. Better wrap that straight away in something more sensible. 🥳

    Open ##2239431

  • @raven667@hachyderm.io 2025-01-18 16:56

    @bert_hubert@fosstodon.org Its this kind of shit I want to wave at people when they act like UNIX, C and the "old way" was some kind of perfection that should be worshiped, and that any *new* API or language design is unnecessary and perverts the "Unix Philosophy" rather than seeing Unix as a hacky work-in-progress, made by different people with very different preferences and ideas, that got solidified and standardized mid development with parts from divergent forks with different visions. This is an example of a half-baked API that works well enough, but I think most people would agree that returning -1 on error is not a sufficiently rich error path, a stopgap for simpler machines from a simpler era, and this kind of magic incantation needed to actually _use_ it is the kind of thing that very few people would intuit when using the API, so is probably a source of infrequent bugs due to "incorrect" usage.

    Open ##2239432

  • @lmk@infosec.exchange 2025-01-18 17:21

    @bert_hubert@fosstodon.org The phrasing of "wishing to check for error" is so nonchalant as if error checking was a whimsical curiosity. How many dependencies on this I wonder, and how many check for error?

    Open ##2239433

  • @derryh@mastodon.scot 2025-01-18 17:40

    @bert_hubert@fosstodon.org and, since the UK did not use GMT/UTC in either 1969, or 1970, that unexpectedly turns out to be almost an hour into 1970 if you have your time zone set to "Europe/London".

    Open ##2239434

  • @alzimon@mastodon.nl 2025-01-19 16:12

    @bert_hubert@fosstodon.org

    Open ##2239435