Skip to content

Commit 894eab6

Browse files
committed
tzfree now preserves errno
* Makefile, NEWS, newtzset.3: Mention this. * localtime.c (FREE_PRESERVES_ERRNO): Default to 1 if 'free' is known to preserve errno, 0 otherwise. (tzfree): Preserve errno if 'free' does not.
1 parent 8e43ecb commit 894eab6

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ LDLIBS=
239239
# -DEPOCH_OFFSET=N if the 'time' function returns a value N greater
240240
# than what POSIX specifies, assuming local time is UT.
241241
# For example, N is 252460800 on AmigaOS.
242+
# -DFREE_PRESERVES_ERRNO=[01] if the 'free' function munges or preserves errno
243+
# (default is guessed)
242244
# -DHAVE_DECL_ASCTIME_R=0 if <time.h> does not declare asctime_r
243245
# on POSIX platforms predating POSIX.1-2024
244246
# -DHAVE_DECL_ENVIRON if <unistd.h> declares 'environ'

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ Unreleased, experimental changes
9393
option is incompatible with POSIX.1-2024 and earlier. It also
9494
costs CPU time and memory.
9595

96+
tzfree now preserves errno, consistently with POSIX.1-2024 'free'.
97+
9698
tzcode now uses mempcpy if available, guessing its availability.
9799
Compile with -DHAVE_MEMPCPY=1 or 0 to override the guess.
98100

localtime.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,10 +2061,25 @@ tzalloc(char const *name)
20612061
return sp;
20622062
}
20632063

2064+
#ifndef FREE_PRESERVES_ERRNO
2065+
# if ((defined _POSIX_VERSION && 202405 <= _POSIX_VERSION) \
2066+
|| (defined __GLIBC__ && 2 < __GLIBC__ + (33 <= __GLIBC_MINOR__)) \
2067+
|| defined __OpenBSD__ || defined __sun)
2068+
# define FREE_PRESERVES_ERRNO 1
2069+
# else
2070+
# define FREE_PRESERVES_ERRNO 0
2071+
# endif
2072+
#endif
2073+
20642074
void
20652075
tzfree(timezone_t sp)
20662076
{
2077+
int err;
2078+
if (!FREE_PRESERVES_ERRNO)
2079+
err = errno;
20672080
free(sp);
2081+
if (!FREE_PRESERVES_ERRNO)
2082+
errno = err;
20682083
}
20692084

20702085
/*

newtzset.3

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ If successful, the
379379
function returns a nonnull pointer to the newly allocated object.
380380
Otherwise, it returns a null pointer and sets
381381
.IR errno .
382+
The
383+
.B tzfree
384+
function does not modify
385+
.IR errno .
382386
.SH ERRORS
383387
.TP
384388
.B EOVERFLOW

0 commit comments

Comments
 (0)