diff mbox series

<wchar.h>: Make wmempcy, wcwidth, wcswidth available by default

Message ID 87iliog9op.fsf@oldenburg.str.redhat.com
State New
Headers show
Series <wchar.h>: Make wmempcy, wcwidth, wcswidth available by default | expand

Commit Message

Florian Weimer Dec. 6, 2022, 9:31 a.m. UTC
This matches what FreeBSD does.  This helps to port software from
BSD using a C99 compiler that does not accept implicit function
declarations.

Tested on x86_64-linux-gnu.

---
 wcsmbs/wchar.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)


base-commit: 8fb923ddc38dd5f4bfac4869d70fd80483fdb87a

Comments

Andreas Schwab Dec. 6, 2022, 9:42 a.m. UTC | #1
On Dez 06 2022, Florian Weimer via Libc-alpha wrote:

> @@ -363,14 +363,14 @@ extern size_t wcsnrtombs (char *__restrict __dst,
>  
>  
>  /* The following functions are extensions found in X/Open CAE.  */
> -#ifdef __USE_XOPEN
> +#if defined __USE_XOPEN || defined __USE_MISC
>  /* Determine number of column positions required for C.  */
>  extern int wcwidth (wchar_t __c) __THROW;
>  
>  /* Determine number of column positions required for first N wide
>     characters (or fewer if S ends before this) in S.  */
>  extern int wcswidth (const wchar_t *__s, size_t __n) __THROW;
> -#endif	/* Use X/Open.  */
> +#endif /* __USE_XOPEN || __USE_MISC.  */

Again, I do not see how that matches what FreeBSD does.  Both
definitions are protected by __XSI_VISIBLE there.
Florian Weimer Dec. 6, 2022, 10:25 a.m. UTC | #2
* Andreas Schwab:

> On Dez 06 2022, Florian Weimer via Libc-alpha wrote:
>
>> @@ -363,14 +363,14 @@ extern size_t wcsnrtombs (char *__restrict __dst,
>>  
>>  
>>  /* The following functions are extensions found in X/Open CAE.  */
>> -#ifdef __USE_XOPEN
>> +#if defined __USE_XOPEN || defined __USE_MISC
>>  /* Determine number of column positions required for C.  */
>>  extern int wcwidth (wchar_t __c) __THROW;
>>  
>>  /* Determine number of column positions required for first N wide
>>     characters (or fewer if S ends before this) in S.  */
>>  extern int wcswidth (const wchar_t *__s, size_t __n) __THROW;
>> -#endif	/* Use X/Open.  */
>> +#endif /* __USE_XOPEN || __USE_MISC.  */
>
> Again, I do not see how that matches what FreeBSD does.  Both
> definitions are protected by __XSI_VISIBLE there.

Should we do this instead?

diff --git a/include/features.h b/include/features.h
index 123de9fd47..40d10a0fb5 100644
--- a/include/features.h
+++ b/include/features.h
@@ -393,6 +393,7 @@
 
 #if defined _DEFAULT_SOURCE
 # define __USE_MISC	1
+# define __USE_XOPEN	1
 #endif
 
 #ifdef	_ATFILE_SOURCE

Should we also define __USE_XOPEN_EXTENDED and __USE_XOPEN2K8 in this
case?  This would allow us to simplify a lot of conditionals involving
__USE_MISC.

Thanks,
Florian
Adhemerval Zanella Netto Dec. 8, 2022, 5:21 p.m. UTC | #3
On 06/12/22 07:25, Florian Weimer via Libc-alpha wrote:
> * Andreas Schwab:
> 
>> On Dez 06 2022, Florian Weimer via Libc-alpha wrote:
>>
>>> @@ -363,14 +363,14 @@ extern size_t wcsnrtombs (char *__restrict __dst,
>>>  
>>>  
>>>  /* The following functions are extensions found in X/Open CAE.  */
>>> -#ifdef __USE_XOPEN
>>> +#if defined __USE_XOPEN || defined __USE_MISC
>>>  /* Determine number of column positions required for C.  */
>>>  extern int wcwidth (wchar_t __c) __THROW;
>>>  
>>>  /* Determine number of column positions required for first N wide
>>>     characters (or fewer if S ends before this) in S.  */
>>>  extern int wcswidth (const wchar_t *__s, size_t __n) __THROW;
>>> -#endif	/* Use X/Open.  */
>>> +#endif /* __USE_XOPEN || __USE_MISC.  */
>>
>> Again, I do not see how that matches what FreeBSD does.  Both
>> definitions are protected by __XSI_VISIBLE there.
> 
> Should we do this instead?
> 
> diff --git a/include/features.h b/include/features.h
> index 123de9fd47..40d10a0fb5 100644
> --- a/include/features.h
> +++ b/include/features.h
> @@ -393,6 +393,7 @@
>  
>  #if defined _DEFAULT_SOURCE
>  # define __USE_MISC	1
> +# define __USE_XOPEN	1
>  #endif
>  
>  #ifdef	_ATFILE_SOURCE
> 
> Should we also define __USE_XOPEN_EXTENDED and __USE_XOPEN2K8 in this
> case?  This would allow us to simplify a lot of conditionals involving
> __USE_MISC.


What is the define flags used by this old programs? I don't see much trouble
adding __USE_XOPEN for _DEFAULT_SOURCE.
Florian Weimer Dec. 8, 2022, 6:14 p.m. UTC | #4
* Adhemerval Zanella Netto:

> On 06/12/22 07:25, Florian Weimer via Libc-alpha wrote:
>> * Andreas Schwab:
>> 
>>> On Dez 06 2022, Florian Weimer via Libc-alpha wrote:
>>>
>>>> @@ -363,14 +363,14 @@ extern size_t wcsnrtombs (char *__restrict __dst,
>>>>  
>>>>  
>>>>  /* The following functions are extensions found in X/Open CAE.  */
>>>> -#ifdef __USE_XOPEN
>>>> +#if defined __USE_XOPEN || defined __USE_MISC
>>>>  /* Determine number of column positions required for C.  */
>>>>  extern int wcwidth (wchar_t __c) __THROW;
>>>>  
>>>>  /* Determine number of column positions required for first N wide
>>>>     characters (or fewer if S ends before this) in S.  */
>>>>  extern int wcswidth (const wchar_t *__s, size_t __n) __THROW;
>>>> -#endif	/* Use X/Open.  */
>>>> +#endif /* __USE_XOPEN || __USE_MISC.  */
>>>
>>> Again, I do not see how that matches what FreeBSD does.  Both
>>> definitions are protected by __XSI_VISIBLE there.
>> 
>> Should we do this instead?
>> 
>> diff --git a/include/features.h b/include/features.h
>> index 123de9fd47..40d10a0fb5 100644
>> --- a/include/features.h
>> +++ b/include/features.h
>> @@ -393,6 +393,7 @@
>>  
>>  #if defined _DEFAULT_SOURCE
>>  # define __USE_MISC	1
>> +# define __USE_XOPEN	1
>>  #endif
>>  
>>  #ifdef	_ATFILE_SOURCE
>> 
>> Should we also define __USE_XOPEN_EXTENDED and __USE_XOPEN2K8 in this
>> case?  This would allow us to simplify a lot of conditionals involving
>> __USE_MISC.
>
>
> What is the define flags used by this old programs? I don't see much trouble
> adding __USE_XOPEN for _DEFAULT_SOURCE.

The program doesn't know anything about feature macros, so it uses
implicit _DEFAULT_SOURCE by default.

Thanks,
Florian
diff mbox series

Patch

diff --git a/wcsmbs/wchar.h b/wcsmbs/wchar.h
index c1321c7518..203ef9ac1d 100644
--- a/wcsmbs/wchar.h
+++ b/wcsmbs/wchar.h
@@ -271,7 +271,7 @@  extern wchar_t *wmemmove (wchar_t *__s1, const wchar_t *__s2, size_t __n)
 /* Set N wide characters of S to C.  */
 extern wchar_t *wmemset (wchar_t *__s, wchar_t __c, size_t __n) __THROW;
 
-#ifdef __USE_GNU
+#ifdef __USE_MISC
 /* Copy N wide characters of SRC to DEST and return pointer to following
    wide character.  */
 extern wchar_t *wmempcpy (wchar_t *__restrict __s1,
@@ -363,14 +363,14 @@  extern size_t wcsnrtombs (char *__restrict __dst,
 
 
 /* The following functions are extensions found in X/Open CAE.  */
-#ifdef __USE_XOPEN
+#if defined __USE_XOPEN || defined __USE_MISC
 /* Determine number of column positions required for C.  */
 extern int wcwidth (wchar_t __c) __THROW;
 
 /* Determine number of column positions required for first N wide
    characters (or fewer if S ends before this) in S.  */
 extern int wcswidth (const wchar_t *__s, size_t __n) __THROW;
-#endif	/* Use X/Open.  */
+#endif /* __USE_XOPEN || __USE_MISC.  */
 
 
 /* Convert initial portion of the wide string NPTR to `double'