mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] support the __STDC_WANT_LIB_EXT2__ feature test macro
@ 2021-07-16 11:58 John Scott
  2021-07-16 16:06 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: John Scott @ 2021-07-16 11:58 UTC (permalink / raw)
  To: musl


[-- Attachment #1.1: Type: text/plain, Size: 524 bytes --]

Hello,

As a feature, I suggest that musl supports the __STDC_WANT_LIB_EXT2__
feature test macro specified in the ISO/IEC Dynamic Allocations TR.
I've attached a patch to accomplish this and which makes minimal
changes to the headers to get musl's support comparable to glibc's.

I was not able to get my hands on the official publication, so I only
referred to the latest draft, which is available here:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1388.pdf

I'm not subscribed, so please CC me on replies.

[-- Attachment #1.2: git format-patch-style patch --]
[-- Type: text/x-patch, Size: 4784 bytes --]

From e923a4fc391909428914d3bebfb02b5431be338a Mon Sep 17 00:00:00 2001
From: John Scott <jscott@posteo.net>
Date: Fri, 16 Jul 2021 07:34:29 -0400
Subject: [PATCH] support the __STDC_WANT_LIB_EXT2__ feature test macro

this is intended to aid applications that wish to use the functionality
specified in ISO/IEC TR 24731-2:2010. Most of these functions are
specified by POSIX, except for (v)asprintf and some of the wide
character functions.

we don't define __STDC_ALLOC_LIB__ since the latter are not implemented.
Also, implementations are required to diagnose when the definition of
__STDC_WANT_LIB_EXT2__ changes after including additional headers, but
we currently don't check this.
---
 include/stdio.h  | 16 +++++++++++-----
 include/string.h |  9 +++++++--
 include/wchar.h  |  7 ++++++-
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/include/stdio.h b/include/stdio.h
index 3604198c..15687ba3 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -131,9 +131,19 @@ FILE *tmpfile(void);
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
- || defined(_BSD_SOURCE)
+ || defined(_BSD_SOURCE) \
+ ||(defined(__STDC_WANT_LIB_EXT2__) && __STDC_WANT_LIB_EXT2__)
 FILE *fmemopen(void *__restrict, size_t, const char *__restrict);
 FILE *open_memstream(char **, size_t *);
+int asprintf(char **, const char *, ...);
+int vasprintf(char **, const char *, __isoc_va_list);
+ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict);
+ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict);
+#endif
+
+#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 FILE *fdopen(int, const char *);
 FILE *popen(const char *, const char *);
 int pclose(FILE *);
@@ -149,8 +159,6 @@ int getc_unlocked(FILE *);
 int getchar_unlocked(void);
 int putc_unlocked(int, FILE *);
 int putchar_unlocked(int);
-ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict);
-ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict);
 int renameat(int, const char *, int, const char *);
 char *ctermid(char *);
 #define L_ctermid 20
@@ -180,8 +188,6 @@ int fileno_unlocked(FILE *);
 int getw(FILE *);
 int putw(int, FILE *);
 char *fgetln(FILE *, size_t *);
-int asprintf(char **, const char *, ...);
-int vasprintf(char **, const char *, __isoc_va_list);
 #endif
 
 #ifdef _GNU_SOURCE
diff --git a/include/string.h b/include/string.h
index 795a2abc..fa3ad27e 100644
--- a/include/string.h
+++ b/include/string.h
@@ -65,14 +65,19 @@ int strerror_r (int, char *, size_t);
 char *stpcpy(char *__restrict, const char *__restrict);
 char *stpncpy(char *__restrict, const char *__restrict, size_t);
 size_t strnlen (const char *, size_t);
-char *strdup (const char *);
-char *strndup (const char *, size_t);
 char *strsignal(int);
 char *strerror_l (int, locale_t);
 int strcoll_l (const char *, const char *, locale_t);
 size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t);
 #endif
 
+#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \
+ ||(defined(__STDC_WANT_LIB_EXT2__) && __STDC_WANT_LIB_EXT2__)
+char *strdup (const char *);
+char *strndup (const char *, size_t);
+#endif
+
 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
  || defined(_BSD_SOURCE)
 void *memccpy (void *__restrict, const void *__restrict, int, size_t);
diff --git a/include/wchar.h b/include/wchar.h
index 88eb55b1..6f8af081 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -157,7 +157,6 @@ size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)  || defined(_BSD_SOURCE)
-FILE *open_wmemstream(wchar_t **, size_t *);
 size_t mbsnrtowcs(wchar_t *__restrict, const char **__restrict, size_t, size_t, mbstate_t *__restrict);
 size_t wcsnrtombs(char *__restrict, const wchar_t **__restrict, size_t, size_t, mbstate_t *__restrict);
 wchar_t *wcsdup(const wchar_t *);
@@ -172,6 +171,12 @@ int wcscoll_l(const wchar_t *, const wchar_t *, locale_t);
 size_t wcsxfrm_l(wchar_t *__restrict, const wchar_t *__restrict, size_t, locale_t);
 #endif
 
+#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \
+ ||(defined(__STDC_WANT_LIB_EXT2__) && __STDC_WANT_LIB_EXT2__)
+FILE *open_wmemstream(wchar_t **, size_t *);
+#endif
+
 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 int wcwidth (wchar_t);
 int wcswidth (const wchar_t *, size_t);
-- 
2.30.2


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-16 16:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-16 11:58 [musl] [PATCH] support the __STDC_WANT_LIB_EXT2__ feature test macro John Scott
2021-07-16 16:06 ` 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).