diff options
87 files changed, 3190 insertions, 1049 deletions
diff --git a/distrib/sets/lists/base/md.amd64 b/distrib/sets/lists/base/md.amd64 index 02f323eb1cb..48b46ae2589 100644 --- a/distrib/sets/lists/base/md.amd64 +++ b/distrib/sets/lists/base/md.amd64 @@ -77,7 +77,7 @@ ./usr/lib/gcc-lib/amd64-unknown-openbsd6.2/4.2.1/collect2 ./usr/lib/gcc-lib/amd64-unknown-openbsd6.2/4.2.1/libgcc.a ./usr/lib/gcc-lib/amd64-unknown-openbsd6.2/4.2.1/specs -./usr/lib/libc++.so.0.0 +./usr/lib/libc++.so.1.0 ./usr/lib/libc++abi.so.0.0 ./usr/lib/libcompiler_rt.a ./usr/lib/libstdc++.so.57.0 diff --git a/distrib/sets/lists/base/md.arm64 b/distrib/sets/lists/base/md.arm64 index 04f6662ddc1..5da76da0879 100644 --- a/distrib/sets/lists/base/md.arm64 +++ b/distrib/sets/lists/base/md.arm64 @@ -34,7 +34,7 @@ ./usr/lib/crtbeginS.o ./usr/lib/crtend.o ./usr/lib/crtendS.o -./usr/lib/libc++.so.0.0 +./usr/lib/libc++.so.1.0 ./usr/lib/libc++abi.so.0.0 ./usr/lib/libcompiler_rt.a ./usr/libdata/perl5/aarch64-openbsd diff --git a/distrib/sets/lists/base/md.i386 b/distrib/sets/lists/base/md.i386 index 6afd986e45e..283eccca2e6 100644 --- a/distrib/sets/lists/base/md.i386 +++ b/distrib/sets/lists/base/md.i386 @@ -79,7 +79,7 @@ ./usr/lib/gcc-lib/i386-unknown-openbsd6.2/4.2.1/collect2 ./usr/lib/gcc-lib/i386-unknown-openbsd6.2/4.2.1/libgcc.a ./usr/lib/gcc-lib/i386-unknown-openbsd6.2/4.2.1/specs -./usr/lib/libc++.so.0.0 +./usr/lib/libc++.so.1.0 ./usr/lib/libc++abi.so.0.0 ./usr/lib/libcompiler_rt.a ./usr/lib/libstdc++.so.57.0 diff --git a/distrib/sets/lists/base/mi b/distrib/sets/lists/base/mi index 103dcfb9ae8..602f44c9cce 100644 --- a/distrib/sets/lists/base/mi +++ b/distrib/sets/lists/base/mi @@ -619,8 +619,8 @@ ./usr/games ./usr/include ./usr/lib -./usr/lib/libc.so.89.6 -./usr/lib/libc.so.89.6.a +./usr/lib/libc.so.90.0 +./usr/lib/libc.so.90.0.a ./usr/lib/libcrypto.so.42.0 ./usr/lib/libcrypto.so.42.0.a ./usr/lib/libcurses.so.14.0 diff --git a/distrib/sets/lists/comp/mi b/distrib/sets/lists/comp/mi index 40b4d8a25b7..7f433667c0a 100644 --- a/distrib/sets/lists/comp/mi +++ b/distrib/sets/lists/comp/mi @@ -2417,6 +2417,7 @@ ./usr/share/man/man3/nan.3 ./usr/share/man/man3/ndbm.3 ./usr/share/man/man3/nextafter.3 +./usr/share/man/man3/newlocale.3 ./usr/share/man/man3/nice.3 ./usr/share/man/man3/nl_langinfo.3 ./usr/share/man/man3/nlist.3 @@ -2656,6 +2657,7 @@ ./usr/share/man/man3/ungetwc.3 ./usr/share/man/man3/unvis.3 ./usr/share/man/man3/usbhid.3 +./usr/share/man/man3/uselocale.3 ./usr/share/man/man3/usleep.3 ./usr/share/man/man3/utime.3 ./usr/share/man/man3/uucplock.3 @@ -2667,6 +2669,7 @@ ./usr/share/man/man3/wcscat.3 ./usr/share/man/man3/wcschr.3 ./usr/share/man/man3/wcscmp.3 +./usr/share/man/man3/wcscoll.3 ./usr/share/man/man3/wcscpy.3 ./usr/share/man/man3/wcscspn.3 ./usr/share/man/man3/wcsdup.3 @@ -2683,6 +2686,7 @@ ./usr/share/man/man3/wcstol.3 ./usr/share/man/man3/wcstombs.3 ./usr/share/man/man3/wcswidth.3 +./usr/share/man/man3/wcsxfrm.3 ./usr/share/man/man3/wctob.3 ./usr/share/man/man3/wctomb.3 ./usr/share/man/man3/wctrans.3 diff --git a/include/ctype.h b/include/ctype.h index 13ade6c2c87..e90d375c8d2 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ctype.h,v 1.24 2014/05/26 01:49:36 guenther Exp $ */ +/* $OpenBSD: ctype.h,v 1.25 2017/09/05 03:16:13 schwarze Exp $ */ /* $NetBSD: ctype.h,v 1.14 1994/10/26 00:55:47 cgd Exp $ */ /* @@ -51,6 +51,13 @@ #define _X 0x40 #define _B 0x80 +#if __POSIX_VISIBLE >= 200809 +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif +#endif + __BEGIN_DECLS extern const char *_ctype_; @@ -84,9 +91,26 @@ int _tolower(int); int _toupper(int); #endif /* __BSD_VISIBLE || __XPG_VISIBLE */ +#if __POSIX_VISIBLE >= 200809 +int isalnum_l(int, locale_t); +int isalpha_l(int, locale_t); +int isblank_l(int, locale_t); +int iscntrl_l(int, locale_t); +int isdigit_l(int, locale_t); +int isgraph_l(int, locale_t); +int islower_l(int, locale_t); +int isprint_l(int, locale_t); +int ispunct_l(int, locale_t); +int isspace_l(int, locale_t); +int isupper_l(int, locale_t); +int isxdigit_l(int, locale_t); +int tolower_l(int, locale_t); +int toupper_l(int, locale_t); +#endif + #endif /* __GNUC__ || _ANSI_LIBRARY */ -#if !defined(_ANSI_LIBRARY) +#if !defined(_ANSI_LIBRARY) && !defined(__cplusplus) __only_inline int isalnum(int _c) { @@ -187,6 +211,92 @@ __only_inline int _toupper(int _c) } #endif /* __BSD_VISIBLE || __XPG_VISIBLE */ +#if __POSIX_VISIBLE >= 200809 +__only_inline int +isalnum_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isalnum(_c); +} + +__only_inline int +isalpha_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isalpha(_c); +} + +__only_inline int +isblank_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isblank(_c); +} + +__only_inline int +iscntrl_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return iscntrl(_c); +} + +__only_inline int +isdigit_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isdigit(_c); +} + +__only_inline int +isgraph_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isgraph(_c); +} + +__only_inline int +islower_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return islower(_c); +} + +__only_inline int +isprint_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isprint(_c); +} + +__only_inline int +ispunct_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return ispunct(_c); +} + +__only_inline int +isspace_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isspace(_c); +} + +__only_inline int +isupper_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isupper(_c); +} + +__only_inline int +isxdigit_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isxdigit(_c); +} + +__only_inline int +tolower_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return tolower(_c); +} + +__only_inline int +toupper_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return toupper(_c); +} +#endif /* __POSIX_VISIBLE >= 200809 */ + #endif /* !_ANSI_LIBRARY */ __END_DECLS diff --git a/include/langinfo.h b/include/langinfo.h index 62443094c59..dd37bfce30f 100644 --- a/include/langinfo.h +++ b/include/langinfo.h @@ -1,4 +1,4 @@ -/* $OpenBSD: langinfo.h,v 1.7 2012/12/05 23:19:57 deraadt Exp $ */ +/* $OpenBSD: langinfo.h,v 1.8 2017/09/05 03:16:13 schwarze Exp $ */ /* $NetBSD: langinfo.h,v 1.3 1995/04/28 23:30:54 jtc Exp $ */ /* @@ -70,8 +70,19 @@ #define CODESET 51 /* Codeset name */ +#if __POSIX_VISIBLE >= 200809 +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif +#endif + __BEGIN_DECLS char *nl_langinfo(nl_item); + +#if __POSIX_VISIBLE >= 200809 +char *nl_langinfo_l(nl_item, locale_t); +#endif __END_DECLS #endif /* _LANGINFO_H_ */ diff --git a/include/locale.h b/include/locale.h index 38d7a408439..78189962df4 100644 --- a/include/locale.h +++ b/include/locale.h @@ -1,4 +1,4 @@ -/* $OpenBSD: locale.h,v 1.10 2016/09/09 18:12:37 millert Exp $ */ +/* $OpenBSD: locale.h,v 1.11 2017/09/05 03:16:13 schwarze Exp $ */ /* $NetBSD: locale.h,v 1.6 1994/10/26 00:56:02 cgd Exp $ */ /* @@ -76,9 +76,37 @@ struct lconv { #include <sys/cdefs.h> +#if __POSIX_VISIBLE >= 200809 + +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif + +#define LC_COLLATE_MASK (1 << LC_COLLATE) +#define LC_CTYPE_MASK (1 << LC_CTYPE) +#define LC_MONETARY_MASK (1 << LC_MONETARY) +#define LC_NUMERIC_MASK (1 << LC_NUMERIC) +#define LC_TIME_MASK (1 << LC_TIME) +#define LC_MESSAGES_MASK (1 << LC_MESSAGES) + +#define LC_ALL_MASK ((1 << _LC_LAST) - 2) + +#define LC_GLOBAL_LOCALE ((locale_t)-1) + +#endif /* __POSIX_VISIBLE >= 200809 */ + + __BEGIN_DECLS struct lconv *localeconv(void); char *setlocale(int, const char *); + +#if __POSIX_VISIBLE >= 200809 +locale_t duplocale(locale_t); +void freelocale(locale_t); +locale_t newlocale(int, const char *, locale_t); +locale_t uselocale(locale_t); +#endif __END_DECLS #endif /* _LOCALE_H_ */ diff --git a/include/stdlib.h b/include/stdlib.h index 0374313a112..cc359ab32e1 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -1,4 +1,4 @@ -/* $OpenBSD: stdlib.h,v 1.71 2017/05/11 11:52:18 tom Exp $ */ +/* $OpenBSD: stdlib.h,v 1.72 2017/09/05 03:16:13 schwarze Exp $ */ /* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */ /*- @@ -82,8 +82,7 @@ typedef struct { #define RAND_MAX 0x7fffffff -extern size_t __mb_cur_max; -#define MB_CUR_MAX __mb_cur_max +#define MB_CUR_MAX __mb_cur_max() /* * Some header files may define an abs macro. @@ -132,7 +131,7 @@ unsigned long strtoul(const char *__restrict, char **__restrict, int); int system(const char *); -/* these are currently just stubs */ +size_t __mb_cur_max(void); int mblen(const char *, size_t); size_t mbstowcs(wchar_t *, const char *, size_t); int wctomb(char *, wchar_t); diff --git a/include/string.h b/include/string.h index b4c880ce3ac..9141c300004 100644 --- a/include/string.h +++ b/include/string.h @@ -1,4 +1,4 @@ -/* $OpenBSD: string.h,v 1.31 2016/09/09 18:12:37 millert Exp $ */ +/* $OpenBSD: string.h,v 1.32 2017/09/05 03:16:13 schwarze Exp $ */ /* $NetBSD: string.h,v 1.6 1994/10/26 00:56:30 cgd Exp $ */ /*- @@ -52,6 +52,13 @@ typedef __size_t size_t; #endif +#if __POSIX_VISIBLE >= 200809 +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif +#endif + __BEGIN_DECLS void *memchr(const void *, int, size_t); int memcmp(const void *, const void *, size_t); @@ -102,9 +109,13 @@ char *strdup(const char *); #if __POSIX_VISIBLE >= 200809 char *stpcpy(char *__restrict, const char *__restrict); char *stpncpy(char *__restrict, const char *__restrict, size_t); +int strcoll_l(const char *, const char *, locale_t); +char *strerror_l(int, locale_t); char *strndup(const char *, size_t); size_t strnlen(const char *, size_t); char *strsignal(int); +size_t strxfrm_l(char *__restrict, const char *__restrict, size_t, locale_t) + __attribute__ ((__bounded__(__string__,1,3))); #endif #if __BSD_VISIBLE diff --git a/include/strings.h b/include/strings.h index c9d4856da55..7108bbe041e 100644 --- a/include/strings.h +++ b/include/strings.h @@ -1,4 +1,4 @@ -/* $OpenBSD: strings.h,v 1.4 2015/11/20 23:40:32 millert Exp $ */ +/* $OpenBSD: strings.h,v 1.5 2017/09/05 03:16:13 schwarze Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -47,6 +47,13 @@ typedef __size_t size_t; #endif +#if __POSIX_VISIBLE >= 200809 +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif +#endif + __BEGIN_DECLS #if __BSD_VISIBLE || (__XPG_VISIBLE >= 420 && __POSIX_VISIBLE <= 200112) /* @@ -66,6 +73,8 @@ char *rindex(const char *, int); int ffs(int); int strcasecmp(const char *, const char *); int strncasecmp(const char *, const char *, size_t); +int strcasecmp_l(const char *, const char *, locale_t); +int strncasecmp_l(const char *, const char *, size_t, locale_t); #endif __END_DECLS diff --git a/include/time.h b/include/time.h index a73f9c3a6cc..fc9121e631d 100644 --- a/include/time.h +++ b/include/time.h @@ -1,4 +1,4 @@ -/* $OpenBSD: time.h,v 1.29 2016/09/09 18:12:37 millert Exp $ */ +/* $OpenBSD: time.h,v 1.30 2017/09/05 03:16:13 schwarze Exp $ */ /* $NetBSD: time.h,v 1.9 1994/10/26 00:56:35 cgd Exp $ */ /* @@ -99,6 +99,13 @@ typedef __pid_t pid_t; #endif #endif +#if __POSIX_VISIBLE >= 200809 +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif +#endif + struct tm { int tm_sec; /* seconds after the minute [0-60] */ int tm_min; /* minutes after the hour [0-59] */ @@ -160,6 +167,12 @@ int nanosleep(const struct timespec *, struct timespec *); int clock_getcpuclockid(pid_t, clockid_t *); #endif +#if __POSIX_VISIBLE >= 200809 +size_t strftime_l(char *__restrict, size_t, const char *__restrict, + const struct tm *__restrict, locale_t) + __attribute__ ((__bounded__(__string__,1,2))); +#endif + #if __BSD_VISIBLE void tzsetwall(void); time_t timelocal(struct tm *); diff --git a/include/wchar.h b/include/wchar.h index 7cdee59a0b8..309f812d65b 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wchar.h,v 1.30 2016/09/09 18:12:37 millert Exp $ */ +/* $OpenBSD: wchar.h,v 1.31 2017/09/05 03:16:13 schwarze Exp $ */ /* $NetBSD: wchar.h,v 1.16 2003/03/07 07:11:35 tshiozak Exp $ */ /*- @@ -96,6 +96,13 @@ typedef __size_t size_t; #define WCHAR_MAX 0x7fffffff #endif +#if __POSIX_VISIBLE >= 200809 +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif +#endif + __BEGIN_DECLS wint_t btowc(int); size_t mbrlen(const char * __restrict, size_t, mbstate_t * __restrict); @@ -155,9 +162,13 @@ unsigned long int wcstoul(const wchar_t * __restrict, wchar_t ** __restrict, #if __POSIX_VISIBLE >= 200809 FILE *open_wmemstream(wchar_t **, size_t *); +int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); wchar_t *wcsdup(const wchar_t *); int wcscasecmp(const wchar_t *, const wchar_t *); +int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); +int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); +size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t, locale_t); size_t mbsnrtowcs(wchar_t * __restrict, const char ** __restrict, size_t, size_t, mbstate_t * __restrict) diff --git a/include/wctype.h b/include/wctype.h index 5d4e55738e5..bf61d255779 100644 --- a/include/wctype.h +++ b/include/wctype.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wctype.h,v 1.5 2006/01/06 18:53:04 millert Exp $ */ +/* $OpenBSD: wctype.h,v 1.6 2017/09/05 03:16:13 schwarze Exp $ */ /* $NetBSD: wctype.h,v 1.5 2003/03/02 22:18:11 tshiozak Exp $ */ /*- @@ -54,6 +54,13 @@ typedef __wctype_t wctype_t; #define WEOF ((wint_t)-1) #endif +#if __POSIX_VISIBLE >= 200809 +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif +#endif + __BEGIN_DECLS int iswalnum(wint_t); int iswalpha(wint_t); @@ -73,6 +80,28 @@ wint_t towlower(wint_t); wint_t towupper(wint_t); wctrans_t wctrans(const char *); wctype_t wctype(const char *); + +#if __POSIX_VISIBLE >= 200809 +int iswalnum_l(wint_t, locale_t); +int iswalpha_l(wint_t, locale_t); +int iswblank_l(wint_t, locale_t); +int iswcntrl_l(wint_t, locale_t); +int iswdigit_l(wint_t, locale_t); +int iswgraph_l(wint_t, locale_t); +int iswlower_l(wint_t, locale_t); +int iswprint_l(wint_t, locale_t); +int iswpunct_l(wint_t, locale_t); +int iswspace_l(wint_t, locale_t); +int iswupper_l(wint_t, locale_t); +int iswxdigit_l(wint_t, locale_t); +int iswctype_l(wint_t, wctype_t, locale_t); +wint_t towctrans_l(wint_t, wctrans_t, locale_t); +wint_t towlower_l(wint_t, locale_t); +wint_t towupper_l(wint_t, locale_t); +wctrans_t wctrans_l(const char *, locale_t); +wctype_t wctype_l(const char *, locale_t); +#endif + __END_DECLS #endif /* _WCTYPE_H_ */ diff --git a/lib/libc/Symbols.list b/lib/libc/Symbols.list index ed44e82197b..ba40b90534f 100644 --- a/lib/libc/Symbols.list +++ b/lib/libc/Symbols.list @@ -938,19 +938,46 @@ SipHash_Update /* locale */ __mb_cur_max btowc +duplocale +freelocale +isalnum_l +isalpha_l +isblank_l +iscntrl_l +isdigit_l +isgraph_l +islower_l +isprint_l +ispunct_l +isspace_l +isupper_l iswalnum +iswalnum_l iswalpha +iswalpha_l iswblank +iswblank_l iswcntrl +iswcntrl_l iswctype +iswctype_l iswdigit +iswdigit_l iswgraph +iswgraph_l iswlower +iswlower_l iswprint +iswprint_l iswpunct +iswpunct_l iswspace +iswspace_l iswupper +iswupper_l iswxdigit +iswxdigit_l +isxdigit_l localeconv mblen mbrlen @@ -959,14 +986,23 @@ mbsinit mbsnrtowcs mbsrtowcs mbstowcs +newlocale mbtowc nl_langinfo +nl_langinfo_l setlocale +tolower_l +toupper_l towctrans +towctrans_l towlower +towlower_l towupper +towupper_l +uselocale wcrtomb wcscoll +wcscoll_l wcsnrtombs wcsrtombs wcstod @@ -980,10 +1016,13 @@ wcstoul wcstoull wcstoumax wcsxfrm +wcsxfrm_l wctob wctomb wctrans +wctrans_l wctype +wctype_l wcwidth /* asr */ @@ -1537,21 +1576,25 @@ rindex stpcpy stpncpy strcasecmp +strcasecmp_l strcasestr strcat strchr strcmp strcoll +strcoll_l strcpy strcspn strdup strerror +strerror_l strerror_r strlcat strlcpy strlen strmode strncasecmp +strncasecmp_l strncat strncmp strncpy @@ -1566,10 +1609,12 @@ strstr strtok strtok_r strxfrm +strxfrm_l swab timingsafe_bcmp timingsafe_memcmp wcscasecmp +wcscasecmp_l wcscat wcschr wcscmp @@ -1580,6 +1625,7 @@ wcslcat wcslcpy wcslen wcsncasecmp +wcsncasecmp_l wcsncat wcsncmp wcsncpy @@ -1662,6 +1708,7 @@ mktime offtime posix2time strftime +strftime_l strptime time2posix timegm diff --git a/lib/libc/gen/isalnum.3 b/lib/libc/gen/isalnum.3 index d272be2d229..436cdafd2c1 100644 --- a/lib/libc/gen/isalnum.3 +++ b/lib/libc/gen/isalnum.3 @@ -1,6 +1,7 @@ -.\" $OpenBSD: isalnum.3,v 1.11 2013/07/17 05:42:11 schwarze Exp $ +.\" $OpenBSD: isalnum.3,v 1.12 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -31,16 +32,19 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: July 17 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt ISALNUM 3 .Os .Sh NAME -.Nm isalnum -.Nd alphanumeric character test +.Nm isalnum , +.Nm isalnum_l +.Nd alphanumeric single-byte character test .Sh SYNOPSIS .In ctype.h .Ft int .Fn isalnum "int c" +.Ft int +.Fn isalnum_l "int c" "locale_t locale" .Sh DESCRIPTION The .Fn isalnum @@ -48,12 +52,32 @@ function tests for any character for which .Xr isalpha 3 or .Xr isdigit 3 +is true, and +.Fn isalnum_l +tests for any character for which +.Xr isalpha_l 3 +or +.Xr isdigit_l 3 is true. +.Pp +In the C locale, the complete list of alphanumeric characters +is A\(enZ, a\(enz, 0, and 1\(en9. +.Ox +always uses the C locale for these functions, +ignoring the global locale, the thread-specific locale, and the +.Fa locale +argument. .Sh RETURN VALUES -The -.Fn isalnum -function returns zero if the character tests false or +These functions return zero if the character tests false or non-zero if the character tests true. +.Sh ENVIRONMENT +On systems supporting non-ASCII single-byte character encodings, +these functions may return non-zero for additional characters, +and the results of +.Fn isalnum +may depend on the +.Ev LC_CTYPE +.Xr locale 1 . .Sh SEE ALSO .Xr isalpha 3 , .Xr isascii 3 , @@ -66,6 +90,7 @@ non-zero if the character tests true. .Xr ispunct 3 , .Xr isspace 3 , .Xr isupper 3 , +.Xr iswalnum 3 , .Xr isxdigit 3 , .Xr stdio 3 , .Xr toascii 3 , @@ -76,15 +101,23 @@ non-zero if the character tests true. The .Fn isalnum function conforms to -.St -ansiC . +.St -ansiC , +and +.Fn isalnum_l +to +.St -p1003.1-2008 . .Sh HISTORY The .Fn isalnum function first appeared in -.At v7 . +.At v7 , +and +.Fn isalnum_l +has been available since +.Ox 6.2 . .Sh CAVEATS -The argument to -.Fn isalnum +The argument +.Fa c must be .Dv EOF or representable as an diff --git a/lib/libc/gen/isalpha.3 b/lib/libc/gen/isalpha.3 index 041c69dd532..db12e59ae8b 100644 --- a/lib/libc/gen/isalpha.3 +++ b/lib/libc/gen/isalpha.3 @@ -1,6 +1,7 @@ -.\" $OpenBSD: isalpha.3,v 1.12 2013/07/18 10:14:48 schwarze Exp $ +.\" $OpenBSD: isalpha.3,v 1.13 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -31,44 +32,53 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: July 18 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt ISALPHA 3 .Os .Sh NAME -.Nm isalpha -.Nd alphabetic character test +.Nm isalpha , +.Nm isalpha_l +.Nd alphabetic single-byte character test .Sh SYNOPSIS .In ctype.h .Ft int .Fn isalpha "int c" +.Ft int +.Fn isalpha_l "int c" "locale_t locale" .Sh DESCRIPTION The .Fn isalpha -function tests for any character for which -.Xr isupper 3 -or -.Xr islower 3 -is true and -.\" , or any of an implementation-defined set of characters -for which none of +and +.Fn isalpha_l +functions test whether +.Fa c +represents a letter. +.Pp +In the C locale, the complete list of alphabetic characters +is A\(enZ and a\(enz. +.Ox +always uses the C locale for these functions, +ignoring the global locale, the thread-specific locale, and the +.Fa locale +argument. +.Sh RETURN VALUES +These functions return zero if the character tests false or +non-zero if the character tests true. +.Sh ENVIRONMENT +On systems supporting non-ASCII single-byte character encodings, +these functions may return non-zero for additional characters, +and the results of +.Fn isalnum +may depend on the +.Ev LC_CTYPE +.Xr locale 1 , +but they never return non-zero for any character for which .Xr iscntrl 3 , .Xr isdigit 3 , .Xr ispunct 3 , or .Xr isspace 3 is true. -In the C locale, -.Fn isalpha -returns true only for the characters for which -.Xr isupper 3 -or -.Xr islower 3 -is true. -.Sh RETURN VALUES -The -.Fn isalpha -function returns zero if the character tests false or -non-zero if the character tests true. .Sh SEE ALSO .Xr isalnum 3 , .Xr isascii 3 , @@ -81,6 +91,7 @@ non-zero if the character tests true. .Xr ispunct 3 , .Xr isspace 3 , .Xr isupper 3 , +.Xr iswalpha 3 , .Xr isxdigit 3 , .Xr stdio 3 , .Xr toascii 3 , @@ -91,15 +102,23 @@ non-zero if the character tests true. The .Fn isalpha function conforms to -.St -ansiC . +.St -ansiC , +and +.Fn isalpha_l +to +.St -p1003.1-2008 . .Sh HISTORY The .Fn isalpha function first appeared in -.At v7 . +.At v7 , +and +.Fn isalpha_l +has been available since +.Ox 6.2 . .Sh CAVEATS -The argument to -.Fn isalpha +The argument +.Fa c must be .Dv EOF or representable as an diff --git a/lib/libc/gen/isblank.3 b/lib/libc/gen/isblank.3 index 553fbe79f90..1402b9a96e0 100644 --- a/lib/libc/gen/isblank.3 +++ b/lib/libc/gen/isblank.3 @@ -1,6 +1,7 @@ -.\" $OpenBSD: isblank.3,v 1.12 2015/06/23 15:31:02 bentley Exp $ +.\" $OpenBSD: isblank.3,v 1.13 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -31,21 +32,26 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: June 23 2015 $ +.Dd $Mdocdate: September 5 2017 $ .Dt ISBLANK 3 .Os .Sh NAME -.Nm isblank -.Nd blank-space character test +.Nm isblank , +.Nm isblank_l +.Nd blank-space single-byte character test .Sh SYNOPSIS .In ctype.h .Ft int .Fn isblank "int c" +.Ft int +.Fn isblank_l "int c" "locale_t locale" .Sh DESCRIPTION The .Fn isblank -function tests for the standard blank-space characters. -The standard blank-space characters are the following: +and +.Fn isblank_l +functions test for blank-space characters. +In the C locale, the complete list of blank-space characters is: .Pp .Bl -tag -width xxxxx -offset indent -compact .It Sq \0 @@ -54,14 +60,22 @@ Space character. Horizontal tab. .El .Pp -In the C locale, -.Fn isblank -returns true only for the standard blank-space characters. +.Ox +always uses the C locale for these functions, +ignoring the global locale, the thread-specific locale, and the +.Fa locale +argument. .Sh RETURN VALUES -The -.Fn isblank -function returns zero if the character tests false or +These functions return zero if the character tests false or non-zero if the character tests true. +.Sh ENVIRONMENT +On systems supporting non-ASCII single-byte character encodings, +these functions may return non-zero for additional characters, +and the results of +.Fn isblank +may depend on the +.Ev LC_CTYPE +.Xr locale 1 . .Sh SEE ALSO .Xr isalnum 3 , .Xr isalpha 3 , @@ -74,6 +88,7 @@ non-zero if the character tests true. .Xr ispunct 3 , .Xr isspace 3 , .Xr isupper 3 , +.Xr iswblank 3 , .Xr isxdigit 3 , .Xr stdio 3 , .Xr toascii 3 , @@ -84,10 +99,23 @@ non-zero if the character tests true. The .Fn isblank function conforms to -.St -isoC-99 . -.Sh CAVEATS -The argument to +.St -isoC-99 , +and +.Fn isblank_l +to +.St -p1003.1-2008 . +.Sh HISTORY +The .Fn isblank +function has been available since +.Bx 4.4 , +and +.Fn isblank_l +since +.Ox 6.2 . +.Sh CAVEATS +The argument +.Fa c must be .Dv EOF or representable as an diff --git a/lib/libc/gen/iscntrl.3 b/lib/libc/gen/iscntrl.3 index 53f261850f4..191c9cc24b6 100644 --- a/lib/libc/gen/iscntrl.3 +++ b/lib/libc/gen/iscntrl.3 @@ -1,6 +1,7 @@ -.\" $OpenBSD: iscntrl.3,v 1.11 2013/07/17 05:42:11 schwarze Exp $ +.\" $OpenBSD: iscntrl.3,v 1.12 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -31,25 +32,43 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: July 17 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt ISCNTRL 3 .Os .Sh NAME -.Nm iscntrl -.Nd control character test +.Nm iscntrl , +.Nm iscntrl_l +.Nd control single-byte character test .Sh SYNOPSIS .In ctype.h .Ft int .Fn iscntrl "int c" +.Ft int +.Fn iscntrl_l "int c" "locale_t locale" .Sh DESCRIPTION The .Fn iscntrl -function tests for any control character. +and +.Fn iscntrl_l +functions tests for any control character. +.Pp +In the C locale, the complete list of control characters +consists of the characters numbered 0x01\(en0x1f and 0x7f. +.Ox +always uses the C locale for these functions, +ignoring the global locale, the thread-specific locale, and the +.Fa locale +argument. .Sh RETURN VALUES -The -.Fn iscntrl -function returns zero if the character tests false or +These functions return zero if the character tests false or non-zero if the character tests true. +.Sh ENVIRONMENT +On systems supporting non-ASCII single-byte character encodings, +results of these functions may differ, and the results of +.Fn iscntrl +may depend on the +.Ev LC_CTYPE +.Xr locale 1 . .Sh SEE ALSO .Xr isalnum 3 , .Xr isalpha 3 , @@ -62,6 +81,7 @@ non-zero if the character tests true. .Xr ispunct 3 , .Xr isspace 3 , .Xr isupper 3 , +.Xr iswcntrl 3 , .Xr isxdigit 3 , .Xr stdio 3 , .Xr toascii 3 , @@ -72,15 +92,23 @@ non-zero if the character tests true. The .Fn iscntrl function conforms to -.St -ansiC . +.St -ansiC , +and +.Fn iscntrl_l +to +.St -p1003.1-2008 . .Sh HISTORY The .Fn iscntrl function first appeared in -.At v7 . +.At v7 , +and +.Fn iscntrl_l +has been available since +.Ox 6.2 . .Sh CAVEATS -The argument to -.Fn iscntrl +The argument +.Fa c must be .Dv EOF or representable as an diff --git a/lib/libc/gen/isdigit.3 b/lib/libc/gen/isdigit.3 index d7cfa1712df..0a3c278e1a6 100644 --- a/lib/libc/gen/isdigit.3 +++ b/lib/libc/gen/isdigit.3 @@ -1,6 +1,7 @@ -.\" $OpenBSD: isdigit.3,v 1.11 2013/07/17 05:42:11 schwarze Exp $ +.\" $OpenBSD: isdigit.3,v 1.12 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -31,25 +32,38 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: July 17 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt ISDIGIT 3 .Os .Sh NAME -.Nm isdigit -.Nd decimal-digit character test +.Nm isdigit , +.Nm isdigit_l +.Nd decimal-digit single-byte character test .Sh SYNOPSIS .In ctype.h .Ft int .Fn isdigit "int c" +.Ft int +.Fn isdigit_l "int c" "locale_t locale" .Sh DESCRIPTION The .Fn isdigit -function tests for any decimal-digit character. +and +.Fn isdigit_l +functions test for any decimal-digit character. +The complete list of decimal digits is 0 and 1\(en9, in any locale. .Sh RETURN VALUES -The -.Fn isdigit -function returns zero if the character tests false or +These functions return zero if the character tests false or non-zero if the character tests true. +.Sh ENVIRONMENT +On systems supporting non-ASCII single-byte character encodings, +different +.Fa c +arguments may correspond to the digits, and the results of +.Fn isdigit +may depend on the +.Ev LC_CTYPE +.Xr locale 1 . .Sh SEE ALSO .Xr isalnum 3 , .Xr isalpha 3 , @@ -62,6 +76,7 @@ non-zero if the character tests true. .Xr ispunct 3 , .Xr isspace 3 , .Xr isupper 3 , +.Xr iswdigit 3 , .Xr isxdigit 3 , .Xr stdio 3 , .Xr toascii 3 , @@ -72,15 +87,23 @@ non-zero if the character tests true. The .Fn isdigit function conforms to -.St -ansiC . +.St -ansiC , +and +.Fn isdigit_l +to +.St -p1003.1-2008 . .Sh HISTORY The .Fn isdigit function first appeared in -.At v7 . +.At v7 , +and +.Fn isdigit_l +has been available since +.Ox 6.2 . .Sh CAVEATS -The argument to -.Fn isdigit +The argument +.Fa c must be .Dv EOF or representable as an diff --git a/lib/libc/gen/isgraph.3 b/lib/libc/gen/isgraph.3 index fab5db54ccc..e27a6257d05 100644 --- a/lib/libc/gen/isgraph.3 +++ b/lib/libc/gen/isgraph.3 @@ -1,6 +1,7 @@ -.\" $OpenBSD: isgraph.3,v 1.11 2013/07/06 17:31:20 jmc Exp $ +.\" $OpenBSD: isgraph.3,v 1.12 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -31,26 +32,49 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: July 6 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt ISGRAPH 3 .Os .Sh NAME -.Nm isgraph -.Nd printing character test (space character exclusive) +.Nm isgraph , +.Nm isgraph_l +.Nd printing single-byte character test (space character exclusive) .Sh SYNOPSIS .In ctype.h .Ft int .Fn isgraph "int c" +.Ft int +.Fn isgraph_l "int c" "locale_t locale" .Sh DESCRIPTION The .Fn isgraph -function tests for any printing character except space +and +.Fn isgraph_l +functions tests for any printing character except space .Pq Sq \ \& . +.Pp +In the C locale, the complete list of printing characters +consists of the characters numbered 0x21\(en0x7e, which is +the union of the characters for which +.Xr isalnum 3 +or +.Xr ispunct 3 +is true. +.Ox +always uses the C locale for these functions, +ignoring the global locale, the thread-specific locale, and the +.Fa locale +argument. .Sh RETURN VALUES -The -.Fn isgraph -function returns zero if the character tests false or +These functions return zero if the character tests false or non-zero if the character tests true. +.Sh ENVIRONMENT +On systems supporting non-ASCII single-byte character encodings, +results of these functions may differ, and the results of +.Fn isgraph +may depend on the +.Ev LC_CTYPE +.Xr locale 1 . .Sh SEE ALSO .Xr isalnum 3 , .Xr isalpha 3 , @@ -63,6 +87,7 @@ non-zero if the character tests true. .Xr ispunct 3 , .Xr isspace 3 , .Xr isupper 3 , +.Xr iswgraph 3 , .Xr isxdigit 3 , .Xr stdio 3 , .Xr toascii 3 , @@ -73,10 +98,23 @@ non-zero if the character tests true. The .Fn isgraph function conforms to -.St -ansiC . -.Sh CAVEATS -The argument to +.St -ansiC , +and +.Fn isgraph_l +to +.St -p1003.1-2008 . +.Sh HISTORY +The .Fn isgraph +function first appeared in +.At III , +and +.Fn isgraph_l +has been available since +.Ox 6.2 . +.Sh CAVEATS +The argument +.Fa c must be .Dv EOF or representable as an diff --git a/lib/libc/gen/islower.3 b/lib/libc/gen/islower.3 index c5194f0d55c..59338613edc 100644 --- a/lib/libc/gen/islower.3 +++ b/lib/libc/gen/islower.3 @@ -1,6 +1,7 @@ -.\" $OpenBSD: islower.3,v 1.12 2013/07/17 05:42:11 schwarze Exp $ +.\" $OpenBSD: islower.3,v 1.13 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -31,37 +32,52 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: July 17 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt ISLOWER 3 .Os .Sh NAME -.Nm islower -.Nd lower-case character test +.Nm islower , +.Nm islower_l +.Nd lower-case single-byte character test .Sh SYNOPSIS .In ctype.h .Ft int .Fn islower "int c" +.Ft int +.Fn islower_l "int c" "locale_t locale" .Sh DESCRIPTION The .Fn islower -function tests for any lower-case letter -.\" or any of an -.\" implementation-defined set of characters -for which none of +and +.Fn islower_l +functions test whether +.Fa c +represents a lower-case letter. +.Pp +In the C locale, the complete list of lower-case letters is a\(enz. +.Ox +always uses the C locale for these functions, +ignoring the global locale, the thread-specific locale, and the +.Fa locale +argument. +.Sh RETURN VALUES +These functions return zero if the character tests false or +non-zero if the character tests true. +.Sh ENVIRONMENT +On systems supporting non-ASCII single-byte character encodings, +these functions may return non-zero for additional characters, +and the results of +.Fn islower +may depend on the +.Ev LC_CTYPE +.Xr locale 1 , +but they never return non-zero for any character for which .Xr iscntrl 3 , .Xr isdigit 3 , .Xr ispunct 3 , or .Xr isspace 3 is true. -In the C locale, -.Fn islower -returns true only for the characters defined as lower-case letters. -.Sh RETURN VALUES -The -.Fn islower -function returns zero if the character tests false or -non-zero if the character tests true. .Sh SEE ALSO .Xr isalnum 3 , .Xr isalpha 3 , @@ -74,6 +90,7 @@ non-zero if the character tests true. .Xr ispunct 3 , .Xr isspace 3 , .Xr isupper 3 , +.Xr iswlower 3 , .Xr isxdigit 3 , .Xr stdio 3 , .Xr toascii 3 , @@ -84,15 +101,23 @@ non-zero if the character tests true. The .Fn islower function conforms to -.St -ansiC . +.St -ansiC , +and +.Fn islower_l +to +.St -p1003.1-2008 . .Sh HISTORY The .Fn islower function first appeared in -.At v7 . +.At v7 , +AND +.Fn islower_l +has been available since +.Ox 6.2 . .Sh CAVEATS -The argument to -.Fn islower +The argument +.Fa c must be .Dv EOF or representable as an diff --git a/lib/libc/gen/isprint.3 b/lib/libc/gen/isprint.3 index 46f0b1fb4c1..78562fd99de 100644 --- a/lib/libc/gen/isprint.3 +++ b/lib/libc/gen/isprint.3 @@ -1,6 +1,7 @@ -.\" $OpenBSD: isprint.3,v 1.11 2013/07/17 05:42:11 schwarze Exp $ +.\" $OpenBSD: isprint.3,v 1.12 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -31,26 +32,49 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: July 17 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt ISPRINT 3 .Os .Sh NAME -.Nm isprint -.Nd printing character test (space character inclusive) +.Nm isprint , +.Nm isprint_l +.Nd printing single-byte character test (space character inclusive) .Sh SYNOPSIS .In ctype.h .Ft int .Fn isprint "int c" +.Ft int +.Fn isprint_l "int c" "locale_t locale" .Sh DESCRIPTION The .Fn isprint -function tests for any printing character including space +and +.Fn isprint_l +functions test for any printing character including space .Pq Sq \ \& . +.Pp +In the C locale, the complete list of printing characters +consists of the characters numbered 0x20\(en0x7e, which is +the union of the characters for which +.Xr isalnum 3 +or +.Xr ispunct 3 +is true, and the space character. +.Ox +always uses the C locale for these functions, +ignoring the global locale, the thread-specific locale, and the +.Fa locale +argument. .Sh RETURN VALUES -The -.Fn isprint -function returns zero if the character tests false or +These functions return zero if the character tests false or non-zero if the character tests true. +.Sh ENVIRONMENT +On systems supporting non-ASCII single-byte character encodings, +results of these functions may differ, and the results of +.Fn isprint +may depend on the +.Ev LC_CTYPE +.Xr locale 1 . .Sh SEE ALSO .Xr isalnum 3 , .Xr isalpha 3 , @@ -63,6 +87,7 @@ non-zero if the character tests true. .Xr ispunct 3 , .Xr isspace 3 , .Xr isupper 3 , +.Xr iswprint 3 , .Xr isxdigit 3 , .Xr stdio 3 , .Xr toascii 3 , @@ -73,15 +98,23 @@ non-zero if the character tests true. The .Fn isprint function conforms to -.St -ansiC . +.St -ansiC , +and +.Fn isprint_l +to +.St -p1003.1-2008 . .Sh HISTORY The .Fn isprint function first appeared in -.At v7 . +.At v7 , +and +.Fn isprint_l +has been available since +.Ox 6.2 . .Sh CAVEATS -The argument to -.Fn isprint +The argument +.Fa c must be .Dv EOF or representable as an diff --git a/lib/libc/gen/ispunct.3 b/lib/libc/gen/ispunct.3 index e41059c21c7..16c3af0a253 100644 --- a/lib/libc/gen/ispunct.3 +++ b/lib/libc/gen/ispunct.3 @@ -1,6 +1,7 @@ -.\" $OpenBSD: ispunct.3,v 1.11 2013/07/17 05:42:11 schwarze Exp $ +.\" $OpenBSD: ispunct.3,v 1.12 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -31,29 +32,50 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: July 17 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt ISPUNCT 3 .Os .Sh NAME -.Nm ispunct -.Nd punctuation character test +.Nm ispunct , +.Nm ispunct_l +.Nd punctuation single-byte character test .Sh SYNOPSIS .In ctype.h .Ft int .Fn ispunct "int c" +.Ft int +.Fn ispunct_l "int c" "locale_t locale" .Sh DESCRIPTION The .Fn ispunct -function tests for any printing character except space -.Pq Sq \ \& -or a character for which +and +.Fn ispunct_l +test for any punctuation characters. +.Pp +In the C locale, the complete list of punctuation characters is: +.Pp +.Dl !\(dq#$%&\(aq()*+,\-./:;<=>?@[\e]\(ha_\(ga{|}\(ti +.Pp +These are all characters for which +.Xr isgraph 3 +is true but .Xr isalnum 3 -is true. +is not. +.Ox +always uses the C locale for these functions, +ignoring the global locale, the thread-specific locale, and the +.Fa locale +argument. .Sh RETURN VALUES -The -.Fn ispunct -function returns zero if the character tests false or +These functions return zero if the character tests false or non-zero if the character tests true. +.Sh ENVIRONMENT +On systems supporting non-ASCII single-byte character encodings, +results of these functions may differ, and the results of +.Fn ispunct +may depend on the +.Ev LC_CTYPE +.Xr locale 1 . .Sh SEE ALSO .Xr isalnum 3 , .Xr isalpha 3 , @@ -66,6 +88,7 @@ non-zero if the character tests true. .Xr isprint 3 , .Xr isspace 3 , .Xr isupper 3 , +.Xr iswpunct 3 , .Xr isxdigit 3 , .Xr stdio 3 , .Xr toascii 3 , @@ -76,15 +99,23 @@ non-zero if the character tests true. The .Fn ispunct function conforms to -.St -ansiC . +.St -ansiC , +and +.Fn ispunct_l +to +.St -p1003.1-2008 . .Sh HISTORY The .Fn ispunct function first appeared in -.At v7 . +.At v7 , +and +.Fn ispunct_l +has been available since +.Ox 6.2 . .Sh CAVEATS -The argument to -.Fn ispunct +The argument +.Fa c must be .Dv EOF or representable as an diff --git a/lib/libc/gen/isspace.3 b/lib/libc/gen/isspace.3 index a2e2fa2dba1..1cd7b67eed8 100644 --- a/lib/libc/gen/isspace.3 +++ b/lib/libc/gen/isspace.3 @@ -1,6 +1,7 @@ -.\" $OpenBSD: isspace.3,v 1.13 2013/07/17 05:42:11 schwarze Exp $ +.\" $OpenBSD: isspace.3,v 1.14 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -31,26 +32,27 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: July 17 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt ISSPACE 3 .Os .Sh NAME -.Nm isspace -.Nd whitespace character test +.Nm isspace , +.Nm isspace_l +.Nd whitespace single-byte character test .Sh SYNOPSIS .In ctype.h .Ft int .Fn isspace "int c" +.Ft int +.Fn isspace_l "int c" "locale_t locale" .Sh DESCRIPTION The .Fn isspace -function tests for the standard whitespace characters -.\" or for any -.\" of an implementation-defined set of characters -for which -.Xr isalnum 3 -is false. -The standard whitespace characters are the following: +and +.Fn isspace_l +functions test for whitespace characters. +.Pp +In the C locale, the complete list of whitespace characters is: .Pp .Bl -tag -width xxxxx -offset indent -compact .It Sq \0 @@ -67,14 +69,22 @@ Horizontal tab. And vertical tab. .El .Pp -In the C locale, -.Fn isspace -returns true only for the standard whitespace characters. +.Ox +always uses the C locale for these functions, +ignoring the global locale, the thread-specific locale, and the +.Fa locale +argument. .Sh RETURN VALUES -The -.Fn isspace -function returns zero if the character tests false or +These functions return zero if the character tests false or non-zero if the character tests true. +.Sh ENVIRONMENT +On systems supporting non-ASCII single-byte character encodings, +these functions may return non-zero for additional characters, +and the results of +.Fn isspace +may depend on the +.Ev LC_CTYPE +.Xr locale 1 . .Sh SEE ALSO .Xr isalnum 3 , .Xr isalpha 3 , @@ -87,6 +97,7 @@ non-zero if the character tests true. .Xr isprint 3 , .Xr ispunct 3 , .Xr isupper 3 , +.Xr iswspace 3 , .Xr isxdigit 3 , .Xr stdio 3 , .Xr toascii 3 , @@ -97,15 +108,23 @@ non-zero if the character tests true. The .Fn isspace function conforms to -.St -ansiC . +.St -ansiC , +and +.Fn isspace_l +to +.St -p1003.1-2008 . .Sh HISTORY The .Fn isspace function first appeared in -.At v7 . +.At v7 , +and +.Fn isspace_l +has been available since +.Ox 6.2 . .Sh CAVEATS -The argument to -.Fn isspace +The argument +.Fa c must be .Dv EOF or representable as an diff --git a/lib/libc/gen/isupper.3 b/lib/libc/gen/isupper.3 index 364d62eb3fa..d519568ef1f 100644 --- a/lib/libc/gen/isupper.3 +++ b/lib/libc/gen/isupper.3 @@ -1,6 +1,7 @@ -.\" $OpenBSD: isupper.3,v 1.13 2013/07/17 05:42:11 schwarze Exp $ +.\" $OpenBSD: isupper.3,v 1.14 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -31,35 +32,52 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: July 17 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt ISUPPER 3 .Os .Sh NAME -.Nm isupper -.Nd upper-case character test +.Nm isupper , +.Nm isupper_l +.Nd upper-case singly-byte character test .Sh SYNOPSIS .In ctype.h .Ft int .Fn isupper "int c" +.Ft int +.Fn isupper_l "int c" "locale_t locale" .Sh DESCRIPTION The .Fn isupper -function tests for any upper-case letter or any of an -implementation-defined set of characters for which none of +and +.Fn isupper_l +functions test whether +.Fa c +represents an upper-case letter. +.Pp +In the C locale, the complete list of upper-case letters is A\(enZ. +.Ox +always uses the C locale for these functions, +ignoring the global locale, the thread-specific locale, and the +.Fa locale +argument. +.Sh RETURN VALUES +These functions return zero if the character tests false or +non-zero if the character tests true. +.Sh ENVIRONMENT +On systems supporting non-ASCII single-byte character encodings, +these functions may return non-zero for additional characters, +and the results of +.Fn isupper +may depend on the +.Ev LC_CTYPE +.Xr locale 1 , +but they never return non-zero for any character for which .Xr iscntrl 3 , .Xr isdigit 3 , .Xr ispunct 3 , or .Xr isspace 3 is true. -In the C locale, -.Fn isupper -returns true only for the characters defined as upper-case letters. -.Sh RETURN VALUES -The -.Fn isupper -function returns zero if the character tests false or -non-zero if the character tests true. .Sh SEE ALSO .Xr isalnum 3 , .Xr isalpha 3 , @@ -72,6 +90,7 @@ non-zero if the character tests true. .Xr isprint 3 , .Xr ispunct 3 , .Xr isspace 3 , +.Xr iswupper 3 , .Xr isxdigit 3 , .Xr stdio 3 , .Xr toascii 3 , @@ -82,15 +101,23 @@ non-zero if the character tests true. The .Fn isupper function conforms to -.St -ansiC . +.St -ansiC , +and +.Fn isupper_l +to +.St -p1003.1-2008 . .Sh HISTORY The .Fn isupper function first appeared in -.At v7 . +.At v7 , +and +.Fn isupper_l +has been available since +.Ox 6.2 . .Sh CAVEATS -The argument to -.Fn isupper +The argument +.Fa c must be .Dv EOF or representable as an diff --git a/lib/libc/gen/isxdigit.3 b/lib/libc/gen/isxdigit.3 index d40385efa5c..e4775dae606 100644 --- a/lib/libc/gen/isxdigit.3 +++ b/lib/libc/gen/isxdigit.3 @@ -1,6 +1,7 @@ -.\" $OpenBSD: isxdigit.3,v 1.10 2013/07/06 17:31:20 jmc Exp $ +.\" $OpenBSD: isxdigit.3,v 1.11 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -31,25 +32,44 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: July 6 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt ISXDIGIT 3 .Os .Sh NAME -.Nm isxdigit -.Nd hexadecimal-digit character test +.Nm isxdigit , +.Nm isxdigit_l +.Nd hexadecimal-digit single-byte character test .Sh SYNOPSIS .In ctype.h .Ft int .Fn isxdigit "int c" +.Ft int +.Fn isxdigit_l "int c" "locale_t locale" .Sh DESCRIPTION The .Fn isxdigit -function tests for any hexadecimal-digit character. +and +.Fn isxdigit_l +functions test for any hexadecimal-digit character. +.Pp +In the C locale, the complete list of hexadecimal digits +is 0, 1\(en9, A\(enF, and a\(enf. +.Ox +always uses the C locale for these functions, +ignoring the global locale, the thread-specific locale, and the +.Fa locale +argument. .Sh RETURN VALUES -The -.Fn isxdigit -function returns zero if the character tests false or +These functions return zero if the character tests false or non-zero if the character tests true. +.Sh ENVIRONMENT +On systems supporting non-ASCII single-byte character encodings, +these functions may return non-zero for additional characters, +and the results of +.Fn isxdigit +may depend on the +.Ev LC_CTYPE +.Xr locale 1 . .Sh SEE ALSO .Xr isalnum 3 , .Xr isalpha 3 , @@ -63,6 +83,7 @@ non-zero if the character tests true. .Xr ispunct 3 , .Xr isspace 3 , .Xr isupper 3 , +.Xr iswxdigit 3 , .Xr stdio 3 , .Xr toascii 3 , .Xr tolower 3 , @@ -72,10 +93,23 @@ non-zero if the character tests true. The .Fn isxdigit function conforms to -.St -ansiC . -.Sh CAVEATS -The argument to +.St -ansiC , +and +.Fn isxdigit_l +to +.St -p1003.1-2008 . +.Sh HISTORY +The .Fn isxdigit +function first appeared in +.At v7 , +and +.Fn isdigit_l +has been available since +.Ox 6.2 . +.Sh CAVEATS +The argument +.Fa c must be .Dv EOF or representable as an diff --git a/lib/libc/gen/tolower.3 b/lib/libc/gen/tolower.3 index a02d395dce5..2f6088b7177 100644 --- a/lib/libc/gen/tolower.3 +++ b/lib/libc/gen/tolower.3 @@ -1,6 +1,7 @@ -.\" $OpenBSD: tolower.3,v 1.13 2013/06/05 03:39:22 tedu Exp $ +.\" $OpenBSD: tolower.3,v 1.14 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1989, 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -31,11 +32,12 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: June 5 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt TOLOWER 3 .Os .Sh NAME .Nm tolower , +.Nm tolower_l , .Nm _tolower .Nd upper case to lower case letter conversion .Sh SYNOPSIS @@ -43,37 +45,49 @@ .Ft int .Fn tolower "int c" .Ft int +.Fn tolower_l "int c" "locale_t locale" +.Ft int .Fn _tolower "int c" .Sh DESCRIPTION The .Fn tolower -function converts an upper-case letter to the corresponding lower-case +and +.Fn tolower_l +functions convert an upper-case letter to the corresponding lower-case letter. The .Fn _tolower function is identical to .Fn tolower except that -.Ar c +.Fa c must be an upper-case letter. +.Pp +.Ox +always uses the C locale for these functions, +ignoring the global locale, the thread-specific locale, and the +.Fa locale +argument. .Sh RETURN VALUES If the argument to the .Fn tolower +or +.Fn tolower_l function is an upper-case letter, the corresponding lower-case letter is returned if there is one; otherwise the argument is returned unchanged. If the argument to the .Fn _tolower function is an upper-case letter, the corresponding lower-case letter is returned; otherwise the output is undefined. -.\" In the -.\" .Em ``C'' -.\" locale, -.\" .Fn tolower -.\" maps only the characters for which -.\" .Xr isupper -.\" is true to the corresponding characters for which -.\" .Xr islower -.\" is true. +.Sh ENVIRONMENT +On systems supporting non-ASCII single-byte character encodings, +the results of +.Fn tolower +and +.Fn _tolower +may depend on the +.Ev LC_CTYPE +.Xr locale 1 . .Sh SEE ALSO .Xr isalnum 3 , .Xr isalpha 3 , @@ -91,6 +105,7 @@ is returned; otherwise the output is undefined. .Xr stdio 3 , .Xr toascii 3 , .Xr toupper 3 , +.Xr towlower 3 , .Xr ascii 7 .Sh STANDARDS The @@ -98,10 +113,29 @@ The and .Fn _tolower functions conform to -.St -ansiC . +.St -ansiC , +and +.Fn tolower_l +to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn tolower +function first appeared in +.At v7 +and acquired the current semantics in +.At III , +where +.Fn _tolower +first appeared. +.Pp +The +.Fn tolower_l +function has been available since +.Ox 6.2 . .Sh CAVEATS -The argument to -.Nm +The argument +.Fa c must be .Dv EOF or representable as an diff --git a/lib/libc/gen/toupper.3 b/lib/libc/gen/toupper.3 index a2aee335926..6d5c16f39d6 100644 --- a/lib/libc/gen/toupper.3 +++ b/lib/libc/gen/toupper.3 @@ -1,6 +1,7 @@ -.\" $OpenBSD: toupper.3,v 1.15 2013/06/05 03:39:22 tedu Exp $ +.\" $OpenBSD: toupper.3,v 1.16 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1989, 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -31,11 +32,12 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: June 5 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt TOUPPER 3 .Os .Sh NAME .Nm toupper , +.Nm toupper_l , .Nm _toupper .Nd lower case to upper case letter conversion .Sh SYNOPSIS @@ -43,37 +45,49 @@ .Ft int .Fn toupper "int c" .Ft int +.Fn toupper_l "int c" "locale_t locale" +.Ft int .Fn _toupper "int c" .Sh DESCRIPTION The .Fn toupper -function converts a lower-case letter to the corresponding +and +.Fn toupper_l +functions convert a lower-case letter to the corresponding upper-case letter. The .Fn _toupper function is identical to .Fn toupper except that -.Ar c +.Fa c must be a lower-case letter. +.Pp +.Ox +always uses the C locale for these functions, +ignoring the global locale, the thread-specific locale, and the +.Fa locale +argument. .Sh RETURN VALUES If the argument to the .Fn toupper +or +.Fn toupper_l function is a lower-case letter, the corresponding upper-case letter is returned if there is one; otherwise the argument is returned unchanged. If the argument to the .Fn _toupper function is a lower-case letter, the corresponding upper-case letter is returned; otherwise the output is undefined. -.\" In the -.\" .Em ``C'' -.\" locale, -.\" .Fn toupper -.\" maps only the characters for which -.\" .Xr islower -.\" is true to the corresponding characters for which -.\" .Xr isupper -.\" is true. +.Sh ENVIRONMENT +On systems supporting non-ASCII single-byte character encodings, +the results of +.Fn toupper +and +.Fn _toupper +may depend on the +.Ev LC_CTYPE +.Xr locale 1 . .Sh SEE ALSO .Xr isalnum 3 , .Xr isalpha 3 , @@ -91,15 +105,35 @@ is returned; otherwise the output is undefined. .Xr stdio 3 , .Xr toascii 3 , .Xr tolower 3 , +.Xr towupper 3 , .Xr ascii 7 .Sh STANDARDS The .Fn toupper function conforms to -.St -ansiC . +.St -ansiC , +and +.Fn toupper_l +to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn toupper +function first appeared in +.At v7 +and acquired the current semantics in +.At III , +where +.Fn _toupper +first appeared. +.Pp +The +.Fn toupper_l +function has been available since +.Ox 6.2 . .Sh CAVEATS -The argument to -.Nm +The argument +.Fa c must be .Dv EOF or representable as an diff --git a/lib/libc/hidden/ctype.h b/lib/libc/hidden/ctype.h index 36953d86355..7f42789a612 100644 --- a/lib/libc/hidden/ctype.h +++ b/lib/libc/hidden/ctype.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ctype.h,v 1.3 2016/09/06 19:56:36 guenther Exp $ */ +/* $OpenBSD: ctype.h,v 1.4 2017/09/05 03:16:13 schwarze Exp $ */ /* * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> * @@ -37,22 +37,57 @@ __only_inline int isascii(int _c); __only_inline int toascii(int _c); __only_inline int _tolower(int _c); __only_inline int _toupper(int _c); + +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif + +__only_inline int isalnum_l(int _c, locale_t _l); +__only_inline int isalpha_l(int _c, locale_t _l); +__only_inline int iscntrl_l(int _c, locale_t _l); +__only_inline int isdigit_l(int _c, locale_t _l); +__only_inline int isgraph_l(int _c, locale_t _l); +__only_inline int islower_l(int _c, locale_t _l); +__only_inline int isprint_l(int _c, locale_t _l); +__only_inline int ispunct_l(int _c, locale_t _l); +__only_inline int isspace_l(int _c, locale_t _l); +__only_inline int isupper_l(int _c, locale_t _l); +__only_inline int isxdigit_l(int _c, locale_t _l); +__only_inline int tolower_l(int _c, locale_t _l); +__only_inline int toupper_l(int _c, locale_t _l); +__only_inline int isblank_l(int _c, locale_t _l); + PROTO_NORMAL(isalnum); +PROTO_DEPRECATED(isalnum_l); PROTO_NORMAL(isalpha); +PROTO_DEPRECATED(isalpha_l); +PROTO_NORMAL(isascii); +PROTO_NORMAL(isblank); +PROTO_DEPRECATED(isblank_l); PROTO_NORMAL(iscntrl); +PROTO_DEPRECATED(iscntrl_l); PROTO_NORMAL(isdigit); +PROTO_DEPRECATED(isdigit_l); PROTO_NORMAL(isgraph); +PROTO_DEPRECATED(isgraph_l); PROTO_NORMAL(islower); +PROTO_DEPRECATED(islower_l); PROTO_NORMAL(isprint); +PROTO_DEPRECATED(isprint_l); PROTO_NORMAL(ispunct); +PROTO_DEPRECATED(ispunct_l); PROTO_NORMAL(isspace); +PROTO_DEPRECATED(isspace_l); PROTO_NORMAL(isupper); +PROTO_DEPRECATED(isupper_l); PROTO_NORMAL(isxdigit); +PROTO_DEPRECATED(isxdigit_l); +PROTO_DEPRECATED(toascii); PROTO_NORMAL(tolower); +PROTO_DEPRECATED(tolower_l); PROTO_NORMAL(toupper); -PROTO_NORMAL(isblank); -PROTO_NORMAL(isascii); -PROTO_DEPRECATED(toascii); +PROTO_DEPRECATED(toupper_l); PROTO_STD_DEPRECATED(_tolower); PROTO_STD_DEPRECATED(_toupper); diff --git a/lib/libc/hidden/langinfo.h b/lib/libc/hidden/langinfo.h index d60afe22cc6..12fb7502129 100644 --- a/lib/libc/hidden/langinfo.h +++ b/lib/libc/hidden/langinfo.h @@ -1,4 +1,4 @@ -/* $OpenBSD: langinfo.h,v 1.1 2015/09/14 12:22:49 guenther Exp $ */ +/* $OpenBSD: langinfo.h,v 1.2 2017/09/05 03:16:13 schwarze Exp $ */ /* * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> * @@ -21,5 +21,6 @@ #include_next <langinfo.h> PROTO_NORMAL(nl_langinfo); +PROTO_DEPRECATED(nl_langinfo_l); #endif /* _LIBC_LANGINFO_H_ */ diff --git a/lib/libc/hidden/locale.h b/lib/libc/hidden/locale.h index 242e35325a3..9e9d6dfdc39 100644 --- a/lib/libc/hidden/locale.h +++ b/lib/libc/hidden/locale.h @@ -1,4 +1,4 @@ -/* $OpenBSD: locale.h,v 1.1 2015/09/14 12:21:03 guenther Exp $ */ +/* $OpenBSD: locale.h,v 1.2 2017/09/05 03:16:13 schwarze Exp $ */ /* * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> * @@ -20,7 +20,11 @@ #include_next <locale.h> +PROTO_DEPRECATED(duplocale); +PROTO_DEPRECATED(freelocale); PROTO_NORMAL(localeconv); +PROTO_DEPRECATED(newlocale); PROTO_NORMAL(setlocale); +PROTO_DEPRECATED(uselocale); #endif /* _LIBC_LOCALE_H_ */ diff --git a/lib/libc/hidden/stdlib.h b/lib/libc/hidden/stdlib.h index 9dece0555b6..cbfe4837457 100644 --- a/lib/libc/hidden/stdlib.h +++ b/lib/libc/hidden/stdlib.h @@ -1,4 +1,4 @@ -/* $OpenBSD: stdlib.h,v 1.11 2017/05/20 12:48:56 millert Exp $ */ +/* $OpenBSD: stdlib.h,v 1.12 2017/09/05 03:16:13 schwarze Exp $ */ /* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */ /*- @@ -46,10 +46,10 @@ extern char **environ; extern char *__progname; #if 0 -extern PROTO_NORMAL(__mb_cur_max); /*extern PROTO_NORMAL(suboptarg);*/ #endif +PROTO_NORMAL(__mb_cur_max); PROTO_STD_DEPRECATED(_Exit); PROTO_DEPRECATED(a64l); PROTO_NORMAL(abort); diff --git a/lib/libc/hidden/string.h b/lib/libc/hidden/string.h index f8a92b96145..0b9554a9f4a 100644 --- a/lib/libc/hidden/string.h +++ b/lib/libc/hidden/string.h @@ -1,4 +1,4 @@ -/* $OpenBSD: string.h,v 1.3 2015/09/10 18:13:46 guenther Exp $ */ +/* $OpenBSD: string.h,v 1.4 2017/09/05 03:16:13 schwarze Exp $ */ /* * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> * @@ -42,21 +42,25 @@ PROTO_DEPRECATED(rindex); PROTO_DEPRECATED(stpcpy); PROTO_NORMAL(stpncpy); PROTO_NORMAL(strcasecmp); +PROTO_DEPRECATED(strcasecmp_l); PROTO_NORMAL(strcasestr); PROTO_STD_DEPRECATED(strcat); PROTO_NORMAL(strchr); PROTO_NORMAL(strcmp); PROTO_NORMAL(strcoll); +PROTO_DEPRECATED(strcoll_l); PROTO_STD_DEPRECATED(strcpy); PROTO_NORMAL(strcspn); PROTO_NORMAL(strdup); PROTO_NORMAL(strerror); +PROTO_DEPRECATED(strerror_l); PROTO_NORMAL(strerror_r); PROTO_NORMAL(strlcat); PROTO_NORMAL(strlcpy); PROTO_NORMAL(strlen); PROTO_NORMAL(strmode); PROTO_NORMAL(strncasecmp); +PROTO_DEPRECATED(strncasecmp_l); PROTO_NORMAL(strncat); PROTO_NORMAL(strncmp); PROTO_NORMAL(strncpy); @@ -71,6 +75,7 @@ PROTO_NORMAL(strstr); PROTO_NORMAL(strtok); PROTO_NORMAL(strtok_r); PROTO_NORMAL(strxfrm); +PROTO_DEPRECATED(strxfrm_l); PROTO_NORMAL(timingsafe_bcmp); PROTO_NORMAL(timingsafe_memcmp); diff --git a/lib/libc/hidden/time.h b/lib/libc/hidden/time.h index 47dbd30beea..e777020335b 100644 --- a/lib/libc/hidden/time.h +++ b/lib/libc/hidden/time.h @@ -1,4 +1,4 @@ -/* $OpenBSD: time.h,v 1.4 2016/05/07 19:05:22 guenther Exp $ */ +/* $OpenBSD: time.h,v 1.5 2017/09/05 03:16:13 schwarze Exp $ */ /* * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> * @@ -41,6 +41,7 @@ PROTO_NORMAL(localtime_r); PROTO_NORMAL(mktime); PROTO_CANCEL(nanosleep); PROTO_NORMAL(strftime); +PROTO_DEPRECATED(strftime_l); PROTO_NORMAL(strptime); PROTO_NORMAL(time); PROTO_DEPRECATED(timegm); diff --git a/lib/libc/hidden/wchar.h b/lib/libc/hidden/wchar.h index 36b02094790..7fb255110c0 100644 --- a/lib/libc/hidden/wchar.h +++ b/lib/libc/hidden/wchar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wchar.h,v 1.3 2015/09/12 16:23:14 guenther Exp $ */ +/* $OpenBSD: wchar.h,v 1.4 2017/09/05 03:16:13 schwarze Exp $ */ /* * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> * @@ -53,6 +53,7 @@ PROTO_NORMAL(wcscat); PROTO_NORMAL(wcschr); PROTO_NORMAL(wcscmp); PROTO_STD_DEPRECATED(wcscoll); +PROTO_DEPRECATED(wcscoll_l); PROTO_STD_DEPRECATED(wcscpy); PROTO_NORMAL(wcscspn); PROTO_NORMAL(wcsdup); @@ -80,7 +81,8 @@ PROTO_NORMAL(wcstoul); PROTO_NORMAL(wcstoull); PROTO_DEPRECATED(wcswcs); PROTO_NORMAL(wcswidth); -PROTO_STD_DEPRECATED(wcsxfrm); +PROTO_NORMAL(wcsxfrm); +PROTO_DEPRECATED(wcsxfrm_l); PROTO_NORMAL(wctob); PROTO_NORMAL(wcwidth); PROTO_NORMAL(wmemchr); diff --git a/lib/libc/hidden/wctype.h b/lib/libc/hidden/wctype.h index 006432f4ec2..87ce1611e02 100644 --- a/lib/libc/hidden/wctype.h +++ b/lib/libc/hidden/wctype.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wctype.h,v 1.1 2015/09/13 11:38:08 guenther Exp $ */ +/* $OpenBSD: wctype.h,v 1.2 2017/09/05 03:16:13 schwarze Exp $ */ /* * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> * @@ -21,22 +21,40 @@ #include_next <wctype.h> PROTO_STD_DEPRECATED(iswalnum); +PROTO_DEPRECATED(iswalnum_l); PROTO_STD_DEPRECATED(iswalpha); +PROTO_DEPRECATED(iswalpha_l); PROTO_STD_DEPRECATED(iswblank); +PROTO_DEPRECATED(iswblank_l); PROTO_STD_DEPRECATED(iswcntrl); +PROTO_DEPRECATED(iswcntrl_l); PROTO_STD_DEPRECATED(iswctype); +PROTO_DEPRECATED(iswctype_l); PROTO_STD_DEPRECATED(iswdigit); +PROTO_DEPRECATED(iswdigit_l); PROTO_STD_DEPRECATED(iswgraph); +PROTO_DEPRECATED(iswgraph_l); PROTO_STD_DEPRECATED(iswlower); +PROTO_DEPRECATED(iswlower_l); PROTO_STD_DEPRECATED(iswprint); +PROTO_DEPRECATED(iswprint_l); PROTO_STD_DEPRECATED(iswpunct); +PROTO_DEPRECATED(iswpunct_l); PROTO_NORMAL(iswspace); +PROTO_DEPRECATED(iswspace_l); PROTO_NORMAL(iswupper); +PROTO_DEPRECATED(iswupper_l); PROTO_STD_DEPRECATED(iswxdigit); -PROTO_STD_DEPRECATED(towctrans); +PROTO_DEPRECATED(iswxdigit_l); +PROTO_NORMAL(towctrans); +PROTO_DEPRECATED(towctrans_l); PROTO_NORMAL(towlower); +PROTO_NORMAL(towlower_l); PROTO_STD_DEPRECATED(towupper); +PROTO_DEPRECATED(towupper_l); PROTO_STD_DEPRECATED(wctrans); +PROTO_DEPRECATED(wctrans_l); PROTO_STD_DEPRECATED(wctype); +PROTO_DEPRECATED(wctype_l); #endif /* !_LIBC_WCTYPE_H_ */ diff --git a/lib/libc/locale/Makefile.inc b/lib/libc/locale/Makefile.inc index 75902fcc605..253d7827e8b 100644 --- a/lib/libc/locale/Makefile.inc +++ b/lib/libc/locale/Makefile.inc @@ -1,20 +1,25 @@ -# $OpenBSD: Makefile.inc,v 1.22 2016/03/30 06:38:41 jmc Exp $ +# $OpenBSD: Makefile.inc,v 1.23 2017/09/05 03:16:13 schwarze Exp $ # locale sources .PATH: ${LIBCSRCDIR}/locale SRCS+= btowc.c _def_messages.c _def_monetary.c _def_numeric.c _def_time.c \ - localeconv.c nl_langinfo.c setlocale.c iswctype.c __mb_cur_max.c \ + localeconv.c nl_langinfo.c nl_langinfo_l.c setlocale.c \ + duplocale.c freelocale.c newlocale.c uselocale.c \ + __mb_cur_max.c _CurrentRuneLocale.c _get_locname.c \ + isctype_l.c iswctype.c iswctype_l.c \ mblen.c mbrlen.c mbstowcs.c mbtowc.c multibyte_citrus.c wcscoll.c \ + wcscoll_l.c \ wcstombs.c wctob.c wctomb.c wcstof.c wcstod.c wcstold.c wcstol.c \ wcstoul.c wcstoll.c wcstoull.c wcstoimax.c wcstoumax.c \ - setrunelocale.c runeglue.c rune.c runetable.c ___runetype_mb.c \ - _wctrans.c wcsxfrm.c + runeglue.c rune.c runetable.c ___runetype_mb.c \ + _wctrans.c wcsxfrm.c wcsxfrm_l.c -MAN+= nl_langinfo.3 setlocale.3 iswalnum.3 towlower.3 \ +MAN+= nl_langinfo.3 setlocale.3 newlocale.3 uselocale.3 \ + iswalnum.3 towlower.3 \ btowc.3 mblen.3 mbrlen.3 mbrtowc.3 mbsinit.3 mbsrtowcs.3 \ - mbstowcs.3 mbtowc.3 wcrtomb.3 wcsrtombs.3 wcstod.3 wcstol.3 \ - wcstombs.3 wctob.3 wctomb.3 \ + mbstowcs.3 mbtowc.3 wcrtomb.3 wcscoll.3 wcsrtombs.3 wcstod.3 \ + wcstol.3 wcstombs.3 wcsxfrm.3 wctob.3 wctomb.3 \ wctype.3 iswctype.3 wctrans.3 towctrans.3 wcwidth.3 CFLAGS+=-I${.CURDIR} -I${LIBCSRCDIR}/citrus diff --git a/lib/libc/locale/_CurrentRuneLocale.c b/lib/libc/locale/_CurrentRuneLocale.c new file mode 100644 index 00000000000..a6b06c831c7 --- /dev/null +++ b/lib/libc/locale/_CurrentRuneLocale.c @@ -0,0 +1,33 @@ +/* $OpenBSD: _CurrentRuneLocale.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* + * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <tib.h> + +#include "rune.h" + +_RuneLocale *_Utf8RuneLocale = NULL; +_RuneLocale *_GlobalRuneLocale = &_DefaultRuneLocale; + +_RuneLocale * +_CurrentRuneLocale(void) +{ + struct tib *tib; + + tib = TIB_GET(); + return tib->tib_locale == NULL ? _GlobalRuneLocale : + tib->tib_locale; +} diff --git a/lib/libc/locale/___runetype_mb.c b/lib/libc/locale/___runetype_mb.c index 502a04de7fb..68a2577027c 100644 --- a/lib/libc/locale/___runetype_mb.c +++ b/lib/libc/locale/___runetype_mb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ___runetype_mb.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */ +/* $OpenBSD: ___runetype_mb.c,v 1.3 2017/09/05 03:16:13 schwarze Exp $ */ /* $NetBSD: ___runetype_mb.c,v 1.10 2005/02/10 19:19:57 tnozaki Exp $ */ /*- @@ -38,7 +38,7 @@ #include "rune_local.h" _RuneType -___runetype_mb(wint_t c) +___runetype_mb(wint_t c, _RuneLocale *rl) { rune_t c0; uint32_t x; @@ -49,7 +49,7 @@ ___runetype_mb(wint_t c) return (0U); c0 = (rune_t)c; /* XXX assumes wint_t = int */ - rr = &_CurrentRuneLocale->rl_runetype_ext; + rr = &rl->rl_runetype_ext; base = rr->rr_rune_ranges; for (x = rr->rr_nranges; x; x >>= 1) { re = base + (x >> 1); diff --git a/lib/libc/locale/__mb_cur_max.c b/lib/libc/locale/__mb_cur_max.c index d1d30af1f6d..bb3601ef0f2 100644 --- a/lib/libc/locale/__mb_cur_max.c +++ b/lib/libc/locale/__mb_cur_max.c @@ -1,32 +1,31 @@ -/* $OpenBSD: __mb_cur_max.c,v 1.5 2016/05/23 00:05:15 guenther Exp $ */ -/* $NetBSD: __mb_cur_max.c,v 1.2 2001/01/25 01:25:06 itojun Exp $ */ - -/*- - * Copyright (c)1999 Citrus Project, - * All rights reserved. +/* $OpenBSD: __mb_cur_max.c,v 1.6 2017/09/05 03:16:13 schwarze Exp $ */ +/* + * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <sys/types.h> #include <stdlib.h> +#include <wchar.h> + +#include "citrus_ctype.h" +#include "rune.h" -size_t __mb_cur_max = 1; +size_t +__mb_cur_max(void) +{ + return _CurrentRuneLocale() == _Utf8RuneLocale ? + _CITRUS_UTF8_MB_CUR_MAX : 1; +} +DEF_STRONG(__mb_cur_max); diff --git a/lib/libc/locale/_get_locname.c b/lib/libc/locale/_get_locname.c new file mode 100644 index 00000000000..b100aa87daa --- /dev/null +++ b/lib/libc/locale/_get_locname.c @@ -0,0 +1,82 @@ +/* $OpenBSD: _get_locname.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* + * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <errno.h> +#include <locale.h> +#include <paths.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "rune.h" +#include "rune_local.h" + +/* + * Supplement the input with locale(1) variables from the + * environment, validate it, and initialize UTF-8 when needed. + * Return NULL on error, "" if unset (for LC_ALL only), + * or the name of the locale that takes effect. + */ +const char * +_get_locname(int category, const char *locname) +{ + static const char *const catname[_LC_LAST - 1] = { + "LC_COLLATE", "LC_CTYPE", "LC_MONETARY", + "LC_NUMERIC", "LC_TIME", "LC_MESSAGES" + }; + + FILE *fp; + const char *cp; + int save_errno; + + /* For empty input, inspect the environment. */ + if (*locname == '\0') + locname = getenv("LC_ALL"); + + if (category != LC_ALL) { + if (locname == NULL || *locname == '\0') + locname = getenv(catname[category - 1]); + if (locname == NULL || *locname == '\0') + locname = getenv("LANG"); + } + + /* + * If still empty, treat LC_ALL as unset, but + * fall back to the default locale for other categories. + */ + if (locname == NULL || *locname == '\0') + locname = category == LC_ALL ? "" : "C"; + + /* Accept and ignore all language and territory prefixes. */ + if ((cp = strrchr(locname, '.')) == NULL) + return locname; + + /* Reject all encodings except ASCII and UTF-8. */ + if (strcmp(cp + 1, "UTF-8") != 0) + return NULL; + + /* Initialize the UTF-8 character encoding locale, if needed. */ + if (_Utf8RuneLocale != NULL) + return locname; + save_errno = errno; + if ((fp = fopen(_PATH_LOCALE "/UTF-8/LC_CTYPE", "re")) != NULL) { + _Utf8RuneLocale = _Read_RuneMagi(fp); + fclose(fp); + } + errno = save_errno; + return _Utf8RuneLocale == NULL ? NULL : locname; +} diff --git a/lib/libc/locale/duplocale.c b/lib/libc/locale/duplocale.c new file mode 100644 index 00000000000..9dd864421ad --- /dev/null +++ b/lib/libc/locale/duplocale.c @@ -0,0 +1,37 @@ +/* $OpenBSD: duplocale.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* + * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <errno.h> +#include <locale.h> + +#include "rune.h" + +locale_t +duplocale(locale_t oldloc) +{ + if (oldloc == _LOCALE_UTF8 && _Utf8RuneLocale != NULL) + return _LOCALE_UTF8; + if (oldloc == _LOCALE_C) + return _LOCALE_C; + if (oldloc == LC_GLOBAL_LOCALE) + return _GlobalRuneLocale == _Utf8RuneLocale ? + _LOCALE_UTF8 : _LOCALE_C; + + /* POSIX says: invalid input -> undefined behaviour. */ + errno = EINVAL; + return _LOCALE_NONE; +} diff --git a/lib/libc/locale/freelocale.c b/lib/libc/locale/freelocale.c new file mode 100644 index 00000000000..78dd1a4d808 --- /dev/null +++ b/lib/libc/locale/freelocale.c @@ -0,0 +1,13 @@ +/* $OpenBSD: freelocale.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* + * Written in 2017 by Ingo Schwarze <schwarze@openbsd.org>. + * Released into the public domain. + */ + +#include <locale.h> + +void +freelocale(locale_t oldloc __attribute((__unused__))) +{ + /* Nothing to do here. */ +} diff --git a/lib/libc/locale/isctype_l.c b/lib/libc/locale/isctype_l.c new file mode 100644 index 00000000000..32fe327998b --- /dev/null +++ b/lib/libc/locale/isctype_l.c @@ -0,0 +1,122 @@ +/* $OpenBSD: isctype_l.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* + * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Only ASCII and UTF-8 are supported, and all single-byte UTF-8 + * characters agree with ASCII, so always use the ASCII tables. + */ + +#define _ANSI_LIBRARY +#include <ctype.h> + +#undef isalnum_l +int +isalnum_l(int c, locale_t locale __attribute__((__unused__))) +{ + return isalnum(c); +} + +#undef isalpha_l +int +isalpha_l(int c, locale_t locale __attribute__((__unused__))) +{ + return isalpha(c); +} + +#undef isblank_l +int +isblank_l(int c, locale_t locale __attribute__((__unused__))) +{ + return isblank(c); +} + +#undef iscntrl_l +int +iscntrl_l(int c, locale_t locale __attribute__((__unused__))) +{ + return iscntrl(c); +} + +#undef isdigit_l +int +isdigit_l(int c, locale_t locale __attribute__((__unused__))) +{ + return isdigit(c); +} + +#undef isgraph_l +int +isgraph_l(int c, locale_t locale __attribute__((__unused__))) +{ + return isgraph(c); +} + +#undef islower_l +int +islower_l(int c, locale_t locale __attribute__((__unused__))) +{ + return islower(c); +} + +#undef isprint_l +int +isprint_l(int c, locale_t locale __attribute__((__unused__))) +{ + return isprint(c); +} + +#undef ispunct_l +int +ispunct_l(int c, locale_t locale __attribute__((__unused__))) +{ + return ispunct(c); +} + +#undef isspace_l +int +isspace_l(int c, locale_t locale __attribute__((__unused__))) +{ + return isspace(c); +} + +#undef isupper_l +int +isupper_l(int c, locale_t locale __attribute__((__unused__))) +{ + return isupper(c); +} + +#undef isxdigit_l +int +isxdigit_l(int c, locale_t locale __attribute__((__unused__))) +{ + return isxdigit(c); +} + +#undef tolower_l +int +tolower_l(int c, locale_t locale __attribute__((__unused__))) +{ + return tolower(c); +} + +#undef toupper_l +int +toupper_l(int c, locale_t locale __attribute__((__unused__))) +{ + return toupper(c); +} diff --git a/lib/libc/locale/iswalnum.3 b/lib/libc/locale/iswalnum.3 index 36339728c9d..2297f0f401c 100644 --- a/lib/libc/locale/iswalnum.3 +++ b/lib/libc/locale/iswalnum.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: iswalnum.3,v 1.5 2013/06/05 03:39:22 tedu Exp $ +.\" $OpenBSD: iswalnum.3,v 1.6 2017/09/05 03:16:13 schwarze Exp $ .\" $NetBSD: iswalnum.3,v 1.8 2003/09/08 17:54:31 wiz Exp $ .\" .\" Copyright (c) 1991 The Regents of the University of California. @@ -34,49 +34,85 @@ .\" .\" @(#)isalnum.3 5.2 (Berkeley) 6/29/91 .\" -.Dd $Mdocdate: June 5 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt ISWALNUM 3 .Os .Sh NAME .Nm iswalnum , +.Nm iswalnum_l , .Nm iswalpha , +.Nm iswalpha_l , .Nm iswblank , +.Nm iswblank_l , .Nm iswcntrl , +.Nm iswcntrl_l , .Nm iswdigit , +.Nm iswdigit_l , .Nm iswgraph , +.Nm iswgraph_l , .Nm iswlower , +.Nm iswlower_l , .Nm iswprint , +.Nm iswprint_l , .Nm iswpunct , +.Nm iswpunct_l , .Nm iswspace , +.Nm iswspace_l , .Nm iswupper , -.Nm iswxdigit +.Nm iswupper_l , +.Nm iswxdigit , +.Nm iswxdigit_l .Nd wide-character classification utilities .Sh SYNOPSIS .In wctype.h .Ft int .Fn iswalnum "wint_t wc" .Ft int +.Fn iswalnum_l "wint_t wc" "locale_t locale" +.Ft int .Fn iswalpha "wint_t wc" .Ft int +.Fn iswalpha_l "wint_t wc" "locale_t locale" +.Ft int .Fn iswblank "wint_t wc" .Ft int +.Fn iswblank_l "wint_t wc" "locale_t locale" +.Ft int .Fn iswcntrl "wint_t wc" .Ft int +.Fn iswcntrl_l "wint_t wc" "locale_t locale" +.Ft int .Fn iswdigit "wint_t wc" .Ft int +.Fn iswdigit_l "wint_t wc" "locale_t locale" +.Ft int .Fn iswgraph "wint_t wc" .Ft int +.Fn iswgraph_l "wint_t wc" "locale_t locale" +.Ft int .Fn iswlower "wint_t wc" .Ft int +.Fn iswlower_l "wint_t wc" "locale_t locale" +.Ft int .Fn iswprint "wint_t wc" .Ft int +.Fn iswprint_l "wint_t wc" "locale_t locale" +.Ft int .Fn iswpunct "wint_t wc" .Ft int +.Fn iswpunct_l "wint_t wc" "locale_t locale" +.Ft int .Fn iswspace "wint_t wc" .Ft int +.Fn iswspace_l "wint_t wc" "locale_t locale" +.Ft int .Fn iswupper "wint_t wc" .Ft int +.Fn iswupper_l "wint_t wc" "locale_t locale" +.Ft int .Fn iswxdigit "wint_t wc" +.Ft int +.Fn iswxdigit_l "wint_t wc" "locale_t locale" .Sh DESCRIPTION The functions are character classification utility functions, for use with wide characters @@ -88,6 +124,13 @@ or See the description of singlebyte classification functions, like .Xr isalnum 3 , for details. +.Pp +The two-argument variants use the specified +.Fa locale , +while the others use the thread-specific locale set with +.Xr uselocale 3 , +falling back to the global locale set with +.Xr setlocale 3 . .Sh RETURN VALUES The functions return zero if the character tests false and return non-zero if the character tests true. @@ -103,18 +146,21 @@ return non-zero if the character tests true. .Xr ispunct 3 , .Xr isspace 3 , .Xr isupper 3 , -.Xr isxdigit 3 +.Xr iswctype 3 , +.Xr isxdigit 3 , +.Xr newlocale 3 , +.Xr setlocale 3 , +.Xr towlower 3 .Sh STANDARDS -The functions conform to -.\" .St -isoC99 . -ISO/IEC 9899:1999 -.Pq Dq ISO C99 . +The one-argument functions conform to +.St -isoC-99 , +the two-argument functions to +.St -p1003.1-2008 . .Sh CAVEATS -The argument to these functions must be +The argument +.Fa wc +must be .Dv WEOF or a valid .Fa wchar_t value with the current locale; otherwise, the result is undefined. -.Sh BUGS -In a UTF-8 locale these functions return wrong answers for some characters -because they do not cover the entire Unicode character set. diff --git a/lib/libc/locale/iswctype.3 b/lib/libc/locale/iswctype.3 index c430adee8a1..0405f0ebb4a 100644 --- a/lib/libc/locale/iswctype.3 +++ b/lib/libc/locale/iswctype.3 @@ -1,7 +1,8 @@ -.\" $OpenBSD: iswctype.3,v 1.4 2014/11/30 15:54:18 schwarze Exp $ +.\" $OpenBSD: iswctype.3,v 1.5 2017/09/05 03:16:13 schwarze Exp $ .\" $NetBSD: iswctype.3,v 1.5 2003/04/16 13:34:40 wiz Exp $ .\" -.\" Copyright (c)2003 Citrus Project, +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> +.\" Copyright (c) 2003 Citrus Project .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -25,74 +26,70 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: November 30 2014 $ +.Dd $Mdocdate: September 5 2017 $ .Dt ISWCTYPE 3 .Os -.\" ---------------------------------------------------------------------- .Sh NAME -.Nm iswctype -.Nd test a character for character class identifier -.\" ---------------------------------------------------------------------- +.Nm iswctype , +.Nm iswctype_l +.Nd test whether a wide character belongs to a character class .Sh SYNOPSIS .In wctype.h .Ft int .Fn iswctype "wint_t wc" "wctype_t charclass" -.\" ---------------------------------------------------------------------- +.Ft int +.Fn iswctype_l "wint_t wc" "wctype_t charclass" "locale_t locale" .Sh DESCRIPTION -The -.Fn iswctype -function returns a boolean value that indicates whether a wide character +These functions test whether the wide character .Fa wc -is in +belongs to .Fa charclass . .Pp -The behaviour of the -.Fn iswctype -is undefined if the -.Fn iswctype -function is called with an invalid +The behaviour is undefined if .Fa charclass -(changes of -.Dv LC_CTYPE -category invalidate -.Fa charclass ) -or invalid wide character -.Fa wc . -.Pp -The behaviour of the -.Fn iswctype -is affected by the -.Dv LC_CTYPE -category of the current locale. -.\" ---------------------------------------------------------------------- -.Sh RETURN VALUES -The -.Fn iswcttype -returns: -.Bl -tag -width 012345678901 -.It 0 +or .Fa wc -is not in -.Fa charclass . -.It non-zero -.Fa wc -is in -.Fa charclass . -.El -.\" ---------------------------------------------------------------------- -.Sh ERRORS -No errors are defined. -.\" ---------------------------------------------------------------------- +is invalid. +When +.Fa charclass +is retrieved with +.Xr wctype 3 , +it becomes invalid when the thread-specific character encoding locale +is changed with +.Xr uselocale 3 +or when the global character encoding locale is changed with +.Xr setlocale 3 . +When +.Fa charclass +is retrieved with +.Xr wctype_l 3 , +it is only valid for use with the same +.Fa locale +argument. +.Sh RETURN VALUES +These functions return zero if the character tests false +or non-zero if the character tests true. .Sh SEE ALSO +.Xr iswalnum 3 , +.Xr newlocale 3 , .Xr setlocale 3 , .Xr towctrans 3 , -.Xr wctrans 3 , .Xr wctype 3 -.\" ---------------------------------------------------------------------- .Sh STANDARDS The .Fn iswctype function conforms to -.\" .St -isoC-amd1 . -ISO/IEC 9899/AMD1:1995 -.Pq Dq ISO C90, Amendment 1 . +.St -isoC-amd1 , +and +.Fn iswctype_l +to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn iswctype +function has been available since +.Ox 3.8 , +and +.Fn iswctype_l +since +.Ox 6.2 . diff --git a/lib/libc/locale/iswctype.c b/lib/libc/locale/iswctype.c index 8c14cda37a3..b7b4e7da3ea 100644 --- a/lib/libc/locale/iswctype.c +++ b/lib/libc/locale/iswctype.c @@ -1,4 +1,4 @@ -/* $OpenBSD: iswctype.c,v 1.6 2015/09/13 11:38:08 guenther Exp $ */ +/* $OpenBSD: iswctype.c,v 1.7 2017/09/05 03:16:13 schwarze Exp $ */ /* $NetBSD: iswctype.c,v 1.15 2005/02/09 21:35:46 kleink Exp $ */ /* @@ -53,10 +53,10 @@ static inline wint_t __tolower_w(wint_t); static inline _RuneType __runetype_w(wint_t c) { - _RuneLocale *rl = _CurrentRuneLocale; + _RuneLocale *rl = _CurrentRuneLocale(); return (_RUNE_ISCACHED(c) ? - rl->rl_runetype[c] : ___runetype_mb(c)); + rl->rl_runetype[c] : ___runetype_mb(c, rl)); } static inline int @@ -68,13 +68,13 @@ __isctype_w(wint_t c, _RuneType f) static inline wint_t __toupper_w(wint_t c) { - return (_towctrans(c, _wctrans_upper(_CurrentRuneLocale))); + return (_towctrans(c, _wctrans_upper(_CurrentRuneLocale()))); } static inline wint_t __tolower_w(wint_t c) { - return (_towctrans(c, _wctrans_lower(_CurrentRuneLocale))); + return (_towctrans(c, _wctrans_lower(_CurrentRuneLocale()))); } int @@ -177,7 +177,7 @@ wctrans_t wctrans(const char *charclass) { int i; - _RuneLocale *rl = _CurrentRuneLocale; + _RuneLocale *rl = _CurrentRuneLocale(); if (rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name==NULL) _wctrans_init(rl); @@ -198,12 +198,13 @@ towctrans(wint_t c, wctrans_t desc) } return (_towctrans(c, (_WCTransEntry *)desc)); } +DEF_STRONG(towctrans); wctype_t wctype(const char *property) { int i; - _RuneLocale *rl = _CurrentRuneLocale; + _RuneLocale *rl = _CurrentRuneLocale(); for (i=0; i<_WCTYPE_NINDEXES; i++) if (!strcmp(rl->rl_wctype[i].te_name, property)) diff --git a/lib/libc/locale/iswctype_l.c b/lib/libc/locale/iswctype_l.c new file mode 100644 index 00000000000..8da0e792835 --- /dev/null +++ b/lib/libc/locale/iswctype_l.c @@ -0,0 +1,217 @@ +/* $OpenBSD: iswctype_l.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* $NetBSD: iswctype.c,v 1.15 2005/02/09 21:35:46 kleink Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <ctype.h> +#include <errno.h> +#include <locale.h> +#include <string.h> +#include <wchar.h> +#include <wctype.h> + +#include "rune.h" +#include "runetype.h" +#include "rune_local.h" +#include "_wctrans_local.h" + +static _RuneLocale *__runelocale(locale_t); +static int __isctype_wl(wint_t, _RuneType, locale_t); + +/* + * For all these functions, POSIX says that behaviour is undefined + * for LC_GLOBAL_LOCALE and for invalid locale arguments. + * The choice made here is to use the C locale in that case. + */ +static _RuneLocale * +__runelocale(locale_t locale) +{ + _RuneLocale *rl; + + rl = NULL; + if (locale == _LOCALE_UTF8) + rl = _Utf8RuneLocale; + if (rl == NULL) + rl = &_DefaultRuneLocale; + return rl; +} + +static int +__isctype_wl(wint_t c, _RuneType f, locale_t locale) +{ + _RuneLocale *rl; + _RuneType rt; + + rl = __runelocale(locale); + rt = _RUNE_ISCACHED(c) ? rl->rl_runetype[c] : ___runetype_mb(c, rl); + return (rt & f) != 0; +} + +int +iswalnum_l(wint_t c, locale_t locale) +{ + return __isctype_wl(c, _CTYPE_A|_CTYPE_D, locale); +} + +int +iswalpha_l(wint_t c, locale_t locale) +{ + return __isctype_wl(c, _CTYPE_A, locale); +} + +int +iswblank_l(wint_t c, locale_t locale) +{ + return __isctype_wl(c, _CTYPE_B, locale); +} + +int +iswcntrl_l(wint_t c, locale_t locale) +{ + return __isctype_wl(c, _CTYPE_C, locale); +} + +int +iswdigit_l(wint_t c, locale_t locale) +{ + return __isctype_wl(c, _CTYPE_D, locale); +} + +int +iswgraph_l(wint_t c, locale_t locale) +{ + return __isctype_wl(c, _CTYPE_G, locale); +} + +int +iswlower_l(wint_t c, locale_t locale) +{ + return __isctype_wl(c, _CTYPE_L, locale); +} + +int +iswprint_l(wint_t c, locale_t locale) +{ + return __isctype_wl(c, _CTYPE_R, locale); +} + +int +iswpunct_l(wint_t c, locale_t locale) +{ + return __isctype_wl(c, _CTYPE_P, locale); +} + +int +iswspace_l(wint_t c, locale_t locale) +{ + return __isctype_wl(c, _CTYPE_S, locale); +} + +int +iswupper_l(wint_t c, locale_t locale) +{ + return __isctype_wl(c, _CTYPE_U, locale); +} + +int +iswxdigit_l(wint_t c, locale_t locale) +{ + return __isctype_wl(c, _CTYPE_X, locale); +} + +wint_t +towupper_l(wint_t c, locale_t locale) +{ + return _towctrans(c, _wctrans_upper(__runelocale(locale))); +} + +wint_t +towlower_l(wint_t c, locale_t locale) +{ + return _towctrans(c, _wctrans_lower(__runelocale(locale))); +} +DEF_WEAK(towlower_l); + +wctrans_t +wctrans_l(const char *charclass, locale_t locale) +{ + _RuneLocale *rl; + int i; + + rl = __runelocale(locale); + if (rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name == NULL) + _wctrans_init(rl); + + for (i = 0; i < _WCTRANS_NINDEXES; i++) + if (strcmp(rl->rl_wctrans[i].te_name, charclass) == 0) + return &rl->rl_wctrans[i]; + + return NULL; +} + +/* + * POSIX says that the behaviour is unspecified if the LC_CTYPE in + * the locale argument does not match what was used to get desc. + * The choice made here is to simply ignore the locale argument + * and rely on the desc argument only. + */ +wint_t +towctrans_l(wint_t c, wctrans_t desc, + locale_t locale __attribute__((__unused__))) +{ + return towctrans(c, desc); +} + +wctype_t +wctype_l(const char *property, locale_t locale) +{ + _RuneLocale *rl; + int i; + + rl = __runelocale(locale); + for (i = 0; i < _WCTYPE_NINDEXES; i++) + if (strcmp(rl->rl_wctype[i].te_name, property) == 0) + return &rl->rl_wctype[i]; + return NULL; +} + +int +iswctype_l(wint_t c, wctype_t charclass, locale_t locale) +{ + if (charclass == (wctype_t)0) + return 0; /* Required by SUSv3. */ + + return __isctype_wl(c, ((_WCTypeEntry *)charclass)->te_mask, locale); +} diff --git a/lib/libc/locale/multibyte_citrus.c b/lib/libc/locale/multibyte_citrus.c index c4566579621..650f2139d25 100644 --- a/lib/libc/locale/multibyte_citrus.c +++ b/lib/libc/locale/multibyte_citrus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: multibyte_citrus.c,v 1.7 2016/09/05 09:47:03 schwarze Exp $ */ +/* $OpenBSD: multibyte_citrus.c,v 1.8 2017/09/05 03:16:13 schwarze Exp $ */ /* $NetBSD: multibyte_amd1.c,v 1.7 2009/01/11 02:46:28 christos Exp $ */ /*- @@ -37,7 +37,7 @@ int mbsinit(const mbstate_t *ps) { - if (ps == NULL || __mb_cur_max == 1) + if (ps == NULL || __mb_cur_max() == 1) return 1; return _citrus_utf8_ctype_mbsinit(ps); } @@ -50,7 +50,7 @@ mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) if (ps == NULL) ps = &mbs; - if (__mb_cur_max == 1) + if (__mb_cur_max() == 1) return _citrus_none_ctype_mbrtowc(pwc, s, n); return _citrus_utf8_ctype_mbrtowc(pwc, s, n, ps); } @@ -75,7 +75,7 @@ mbsnrtowcs(wchar_t *dst, const char **src, size_t nmc, size_t len, if (ps == NULL) ps = &mbs; - if (__mb_cur_max == 1) + if (__mb_cur_max() == 1) return _citrus_none_ctype_mbsnrtowcs(dst, src, nmc, len); return _citrus_utf8_ctype_mbsnrtowcs(dst, src, nmc, len, ps); } @@ -88,7 +88,7 @@ wcrtomb(char *s, wchar_t wc, mbstate_t *ps) if (ps == NULL) ps = &mbs; - if (__mb_cur_max == 1) + if (__mb_cur_max() == 1) return _citrus_none_ctype_wcrtomb(s, wc); return _citrus_utf8_ctype_wcrtomb(s, wc, ps); } @@ -113,7 +113,7 @@ wcsnrtombs(char *dst, const wchar_t **src, size_t nwc, size_t len, if (ps == NULL) ps = &mbs; - if (__mb_cur_max == 1) + if (__mb_cur_max() == 1) return _citrus_none_ctype_wcsnrtombs(dst, src, nwc, len); return _citrus_utf8_ctype_wcsnrtombs(dst, src, nwc, len, ps); } diff --git a/lib/libc/locale/newlocale.3 b/lib/libc/locale/newlocale.3 new file mode 100644 index 00000000000..7e23b527e25 --- /dev/null +++ b/lib/libc/locale/newlocale.3 @@ -0,0 +1,161 @@ +.\" $OpenBSD: newlocale.3,v 1.1 2017/09/05 03:16:13 schwarze Exp $ +.\" +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: September 5 2017 $ +.Dt NEWLOCALE 3 +.Os +.Sh NAME +.Nm newlocale , +.Nm duplocale , +.Nm freelocale +.Nd create and destroy locale objects +.Sh SYNOPSIS +.In locale.h +.Ft locale_t +.Fo newlocale +.Fa "int mask" +.Fa "const char *locname" +.Fa "locale_t oldloc" +.Fc +.Ft locale_t +.Fo duplocale +.Fa "locale_t oldloc" +.Fc +.Ft void +.Fo freelocale +.Fa "locale_t oldloc" +.Fc +.Sh DESCRIPTION +The function +.Fn newlocale +creates a new locale object for use with +.Xr uselocale 3 +and with many functions that accept +.Vt locale_t +arguments. +.Pp +On +.Ox , +.Fa mask +is only meaningful if it includes +.Dv LC_CTYPE_MASK , +and +.Fa locname +is only meaningful if it is +.Qq C +or +.Qq POSIX , +if it ends with +.Qq .UTF-8 , +or if it is an empty string; otherwise, +.Fn newlocale +always returns the C locale. +.Pp +On +.Ox , +.Fn newlocale +ignores +.Fa oldloc , +and passing +.Po Vt locale_t Pc Ns 0 +is recommended. +.Pp +The function +.Fn duplocale +copies +.Fa oldloc , +or the global locale if given the special argument +.Dv LC_GLOBAL_LOCALE . +.Pp +For portability, when an object returned from +.Fn newlocale +or +.Fn duplocale +is no longer needed, pass it to +.Fn freelocale , +even though the latter has no effect on +.Ox . +The +.Fa oldloc +objects passed to +.Fn newlocale +or +.Fn freelocale +become invalid, and using them or passing them once again to +.Fn freelocale +results in undefined behaviour, whereas objects passed to +.Fn duplocale +remain valid and can be passed to +.Fn freelocale +later on. +.Sh RETURN VALUES +The functions +.Fn newlocale +and +.Fn duplocale +return the new locale object on success or +.Po Vt locale_t Pc Ns 0 +on failure. +.Sh ENVIRONMENT +If +.Fa locname +is an empty string, +.Fa newlocale +inspects +.Ev LC_ALL , +.Ev LC_CTYPE , +and +.Ev LANG +as described in +.Xr locale 1 . +.Sh ERRORS +The function +.Fn newlocale +fails if: +.Bl -tag -width Er +.It Bq Er EINVAL +An invalid bit is set in +.Fa mask , +or +.Fa locname +is +.Dv NULL . +.It Bq Er ENOENT +Locale data is not available for +.Fa locname . +.El +.Pp +On other operating systems, +.Fn newlocale +and +.Fn duplocale +may also fail with +.Er ENOMEM . +.Sh SEE ALSO +.Xr iswalnum 3 , +.Xr iswctype 3 , +.Xr towctrans 3 , +.Xr towlower 3 , +.Xr uselocale 3 , +.Xr wcscasecmp 3 , +.Xr wctrans 3 , +.Xr wctype 3 +.Sh STANDARDS +These functions conform to +.St -p1003.1-2008 . +.Sh HISTORY +These functions have been available since +.Ox 6.2 . diff --git a/lib/libc/locale/newlocale.c b/lib/libc/locale/newlocale.c new file mode 100644 index 00000000000..e8655a05dde --- /dev/null +++ b/lib/libc/locale/newlocale.c @@ -0,0 +1,56 @@ +/* $OpenBSD: newlocale.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* + * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <errno.h> +#include <locale.h> +#include <string.h> + +#include "rune.h" + +locale_t +newlocale(int mask, const char *locname, + locale_t oldloc __attribute__((__unused__))) +{ + int ic, flag; + + /* Invalid input. */ + if (locname == NULL || mask & ~LC_ALL_MASK) { + errno = EINVAL; + return _LOCALE_NONE; + } + + /* Check the syntax for all selected categories. */ + for (ic = flag = 1; ic < _LC_LAST; ic++) { + flag <<= 1; + if (ic != LC_CTYPE && mask & flag && + _get_locname(ic, locname) == NULL) { + errno = ENOENT; + return _LOCALE_NONE; + } + } + + /* Only character encoding has thread-specific effects. */ + if ((mask & LC_CTYPE_MASK) == 0) + return _LOCALE_C; + + /* The following may initialize UTF-8 for later use. */ + if ((locname = _get_locname(LC_CTYPE, locname)) == NULL) { + errno = ENOENT; + return _LOCALE_NONE; + } + return strchr(locname, '.') == NULL ? _LOCALE_C : _LOCALE_UTF8; +} diff --git a/lib/libc/locale/nl_langinfo.3 b/lib/libc/locale/nl_langinfo.3 index 340b4d225e4..e16e7d0a187 100644 --- a/lib/libc/locale/nl_langinfo.3 +++ b/lib/libc/locale/nl_langinfo.3 @@ -1,37 +1,78 @@ -.\" $OpenBSD: nl_langinfo.3,v 1.11 2015/10/24 13:32:18 bentley Exp $ +.\" $OpenBSD: nl_langinfo.3,v 1.12 2017/09/05 03:16:13 schwarze Exp $ .\" -.\" Written by J.T. Conklin <jtc@netbsd.org>. -.\" Public domain. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" -.Dd $Mdocdate: October 24 2015 $ +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: September 5 2017 $ .Dt NL_LANGINFO 3 .Os .Sh NAME -.Nm nl_langinfo +.Nm nl_langinfo , +.Nm nl_langinfo_l .Nd get locale information .Sh SYNOPSIS .In langinfo.h .Ft char * .Fn nl_langinfo "nl_item item" +.Ft char * +.Fn nl_langinfo "nl_item item" "locale_t locale" .Sh DESCRIPTION The .Fn nl_langinfo -function returns a pointer to a string containing information -set by the program's locale. -.Pp -The names and values of -.Fa item -are defined in -.In langinfo.h . +function returns information about the global +.Xr locale 1 , +and +.Fn nl_langinfo_l +about the +.Fa locale +passed as an argument. .Sh RETURN VALUES -.Fn nl_langinfo -returns a pointer to an empty string if +On +.Ox , +if .Fa item -is invalid. +is +.Dv CODESET , +the return value is either +.Qq US-ASCII +or +.Qq UTF-8 . +For other values of +.Fa item , +the strings that +.St -p1003.1-2008 +specifies for the C locale are returned. +.Pp +If +.Fa item +is invalid, a pointer to an empty string is returned. .Sh SEE ALSO -.Xr setlocale 3 +.Xr setlocale 3 , +.Xr uselocale 3 .Sh STANDARDS -The -.Fn nl_langinfo -function conforms to +These functions conform to .St -p1003.1-2008 . +.Sh HISTORY +The function +.Fn nl_langinfo +has been available since +.Nx 1.0 , +and +.Fn nl_langinfo_l +since +.Ox 6.2 . +.Sh BUGS +The return values for +.Dv CODESET +are not standardized and vary among implementations. diff --git a/lib/libc/locale/nl_langinfo.c b/lib/libc/locale/nl_langinfo.c index ea54dc668a0..79d91ce3754 100644 --- a/lib/libc/locale/nl_langinfo.c +++ b/lib/libc/locale/nl_langinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nl_langinfo.c,v 1.8 2016/05/23 00:05:15 guenther Exp $ */ +/* $OpenBSD: nl_langinfo.c,v 1.9 2017/09/05 03:16:13 schwarze Exp $ */ /* * Written by J.T. Conklin <jtc@netbsd.org>. * Public domain. @@ -102,7 +102,7 @@ nl_langinfo(nl_item item) s = ""; break; case CODESET: - s = _CurrentRuneLocale->rl_codeset; + s = _CurrentRuneLocale()->rl_codeset; if (!s) s = ""; break; diff --git a/lib/libc/locale/nl_langinfo_l.c b/lib/libc/locale/nl_langinfo_l.c new file mode 100644 index 00000000000..704135e15c2 --- /dev/null +++ b/lib/libc/locale/nl_langinfo_l.c @@ -0,0 +1,43 @@ +/* $OpenBSD: nl_langinfo_l.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* + * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <langinfo.h> +#include <locale.h> + +#include "rune.h" + +char * +nl_langinfo_l(nl_item item, locale_t locale) +{ + _RuneLocale *rl; + const char *s; + + if (item != CODESET) + return nl_langinfo(item); + + rl = NULL; + if (locale == _LOCALE_UTF8) + rl = _Utf8RuneLocale; + if (rl == NULL) + rl = &_DefaultRuneLocale; + + s = rl->rl_codeset; + if (s == NULL) + s = ""; + + return (char *)s; +} diff --git a/lib/libc/locale/rune.h b/lib/libc/locale/rune.h index 98852f93fb7..f10db484a94 100644 --- a/lib/libc/locale/rune.h +++ b/lib/libc/locale/rune.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rune.h,v 1.3 2016/05/23 00:05:15 guenther Exp $ */ +/* $OpenBSD: rune.h,v 1.4 2017/09/05 03:16:13 schwarze Exp $ */ /* $NetBSD: rune.h,v 1.9 2003/08/07 16:43:04 agc Exp $ */ /*- @@ -38,10 +38,15 @@ #ifndef _RUNE_H_ #define _RUNE_H_ +#include <locale.h> #include <stdio.h> #include <wchar.h> #include "runetype.h" +#define _LOCALE_NONE (locale_t)0 +#define _LOCALE_C (locale_t)1 +#define _LOCALE_UTF8 (locale_t)2 + /* * map _RTYPE_x to _CTYPE_x * @@ -70,12 +75,13 @@ #define _CTYPE_SW2 _RUNETYPE_SW2 #define _CTYPE_SW3 _RUNETYPE_SW3 -/* - * global variables - */ __BEGIN_HIDDEN_DECLS -extern _RuneLocale _DefaultRuneLocale; -extern _RuneLocale *_CurrentRuneLocale; +extern _RuneLocale _DefaultRuneLocale; +extern _RuneLocale *_Utf8RuneLocale; +extern _RuneLocale *_GlobalRuneLocale; + +_RuneLocale *_CurrentRuneLocale(void); +const char *_get_locname(int, const char *); __END_HIDDEN_DECLS #endif /*! _RUNE_H_ */ diff --git a/lib/libc/locale/rune_local.h b/lib/libc/locale/rune_local.h index 43428a0b888..d2967475e0a 100644 --- a/lib/libc/locale/rune_local.h +++ b/lib/libc/locale/rune_local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rune_local.h,v 1.6 2017/08/05 15:16:32 schwarze Exp $ */ +/* $OpenBSD: rune_local.h,v 1.7 2017/09/05 03:16:13 schwarze Exp $ */ /* $NetBSD: rune_local.h,v 1.7 2003/03/02 22:18:15 tshiozak Exp $ */ /*- @@ -35,16 +35,11 @@ __BEGIN_HIDDEN_DECLS /* rune.c */ extern _RuneLocale *_Read_RuneMagi(FILE *fp); -/* setrunelocale.c */ -extern int _xpg4_setrunelocale(const char *); -extern _RuneLocale *_findrunelocale(const char *); -extern int _newrunelocale(const char *); - /* runeglue.c */ extern int __make_ctype_tabs(_RuneLocale *); /* ___runetype_mb.c */ -extern _RuneType ___runetype_mb(wint_t); +extern _RuneType ___runetype_mb(wint_t, _RuneLocale *); __END_HIDDEN_DECLS diff --git a/lib/libc/locale/runetable.c b/lib/libc/locale/runetable.c index ad4e22c9631..89cd04d47b2 100644 --- a/lib/libc/locale/runetable.c +++ b/lib/libc/locale/runetable.c @@ -268,5 +268,3 @@ _RuneLocale _DefaultRuneLocale = { }, NULL }; - -_RuneLocale *_CurrentRuneLocale = &_DefaultRuneLocale; diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c index 33578a9815c..7afc46ed497 100644 --- a/lib/libc/locale/setlocale.c +++ b/lib/libc/locale/setlocale.c @@ -1,289 +1,196 @@ -/* $OpenBSD: setlocale.c,v 1.26 2017/08/05 15:16:32 schwarze Exp $ */ +/* $OpenBSD: setlocale.c,v 1.27 2017/09/05 03:16:13 schwarze Exp $ */ /* - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <locale.h> -#include <limits.h> -#include <paths.h> -#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> -#include "localedef.h" #include "rune.h" -#include "rune_local.h" -/* - * Category names for getenv() - */ -static char *categories[_LC_LAST] = { - "LC_ALL", - "LC_COLLATE", - "LC_CTYPE", - "LC_MONETARY", - "LC_NUMERIC", - "LC_TIME", - "LC_MESSAGES" -}; - -/* - * Current locales for each category - */ -static char current_categories[_LC_LAST][32] = { - "C", - "C", - "C", - "C", - "C", - "C", - "C" -}; -static char current_locale_string[_LC_LAST * 33]; - -static char *currentlocale(void); -static void revert_to_default(int); -static int load_locale_sub(int, const char *); -static char *loadlocale(int, const char *); -static const char *__get_locale_env(int); - -char * -setlocale(int category, const char *locale) +static void +freegl(char **oldgl) { - int i, loadlocale_success; - size_t len; - const char *env, *r; - char new_categories[_LC_LAST][32]; - - if (category < 0 || category >= _LC_LAST) - return (NULL); - - if (!locale) - return (category ? - current_categories[category] : currentlocale()); - - /* - * Default to the current locale for everything. - */ - for (i = 1; i < _LC_LAST; ++i) - (void)strlcpy(new_categories[i], current_categories[i], - sizeof(new_categories[i])); - - /* - * Now go fill up new_categories from the locale argument - */ - if (!*locale) { - if (category == LC_ALL) { - for (i = 1; i < _LC_LAST; ++i) { - env = __get_locale_env(i); - (void)strlcpy(new_categories[i], env, - sizeof(new_categories[i])); - } - } - else { - env = __get_locale_env(category); - (void)strlcpy(new_categories[category], env, - sizeof(new_categories[category])); - } - } else if (category) { - (void)strlcpy(new_categories[category], locale, - sizeof(new_categories[category])); - } else { - if ((r = strchr(locale, '/')) == 0) { - for (i = 1; i < _LC_LAST; ++i) { - (void)strlcpy(new_categories[i], locale, - sizeof(new_categories[i])); - } - } else { - for (i = 1;;) { - if (*locale == '/') - return (NULL); /* invalid format. */ - len = r - locale; - if (len + 1 > sizeof(new_categories[i])) - return (NULL); /* too long */ - (void)memcpy(new_categories[i], locale, len); - new_categories[i][len] = '\0'; - if (*r == 0) - break; - if (*(locale = ++r) == 0) - /* slash followed by NUL */ - return (NULL); - /* skip until NUL or '/' */ - while (*r && *r != '/') - r++; - if (++i == _LC_LAST) - return (NULL); /* too many slashes. */ - } - if (i + 1 != _LC_LAST) - return (NULL); /* too few slashes. */ - } - } - - if (category) - return (loadlocale(category, new_categories[category])); + int ic; - loadlocale_success = 0; - for (i = 1; i < _LC_LAST; ++i) { - if (loadlocale(i, new_categories[i]) != NULL) - loadlocale_success = 1; - } - - /* - * If all categories failed, return NULL; we don't need to back - * changes off, since none happened. - */ - if (!loadlocale_success) - return NULL; - - return (currentlocale()); + if (oldgl == NULL) + return; + for (ic = LC_ALL; ic < _LC_LAST; ic++) + free(oldgl[ic]); + free(oldgl); } -DEF_STRONG(setlocale); -static char * -currentlocale(void) +static char ** +dupgl(char **oldgl) { - int i; - - (void)strlcpy(current_locale_string, current_categories[1], - sizeof(current_locale_string)); + char **newgl; + int ic; - for (i = 2; i < _LC_LAST; ++i) - if (strcmp(current_categories[1], current_categories[i])) { - (void)snprintf(current_locale_string, - sizeof(current_locale_string), "%s/%s/%s/%s/%s/%s", - current_categories[1], current_categories[2], - current_categories[3], current_categories[4], - current_categories[5], current_categories[6]); - break; + if ((newgl = calloc(_LC_LAST, sizeof(*newgl))) == NULL) + return NULL; + for (ic = LC_ALL; ic < _LC_LAST; ic++) { + if ((newgl[ic] = strdup(oldgl != NULL ? + oldgl[ic] : ic == LC_ALL ? "" : "C")) == NULL) { + freegl(newgl); + return NULL; } - return (current_locale_string); -} - -static void -revert_to_default(int category) -{ - switch (category) { - case LC_CTYPE: - (void)_xpg4_setrunelocale("C"); - break; - case LC_MESSAGES: - case LC_COLLATE: - case LC_MONETARY: - case LC_NUMERIC: - case LC_TIME: - break; } + return newgl; } static int -set_lc_messages_locale(const char *locname) +changegl(int category, const char *locname, char **gl) { - const char *dot, *loc_encoding; + char *cp; - /* Assumes "language[_territory][.codeset]" locale name. */ - dot = strrchr(locname, '.'); - if (dot == NULL) + if ((locname = _get_locname(category, locname)) == NULL || + (cp = strdup(locname)) == NULL) return -1; - loc_encoding = dot + 1; - return strcmp(loc_encoding, "UTF-8") == 0 ? 0 : -1; + free(gl[category]); + gl[category] = cp; + return 0; } -static int -load_locale_sub(int category, const char *locname) +char * +setlocale(int category, const char *locname) { - /* check for the default locales */ - if (!strcmp(locname, "C") || !strcmp(locname, "POSIX")) { - revert_to_default(category); - return 0; - } + /* + * Even though only LC_CTYPE has any effect in the OpenBSD + * base system, store complete information about the global + * locale, such that third-party software can access it, + * both via setlocale(3) and via locale(1). + */ + static char global_locname[256]; + static char **global_locale; - /* sanity check */ - if (strchr(locname, '/') != NULL) - return -1; + char **newgl, *firstname, *nextname; + int ic; - switch (category) { - case LC_CTYPE: - if (_xpg4_setrunelocale(locname)) - return -1; - break; + if (category < LC_ALL || category >= _LC_LAST) + return NULL; - case LC_MESSAGES: - return set_lc_messages_locale(locname); + /* + * Change the global locale. + */ + if (locname != NULL) { + if ((newgl = dupgl(global_locale)) == NULL) + return NULL; + if (category == LC_ALL && strchr(locname, '/') != NULL) { + + /* One value for each category. */ + if ((firstname = strdup(locname)) == NULL) + return NULL; + nextname = firstname; + for (ic = 1; ic < _LC_LAST; ic++) + if (nextname == NULL || changegl(ic, + strsep(&nextname, "/"), newgl) == -1) + break; + free(firstname); + if (ic < _LC_LAST || nextname != NULL) { + freegl(newgl); + return NULL; + } + } else { - case LC_COLLATE: - case LC_MONETARY: - case LC_NUMERIC: - case LC_TIME: - return -1; - } + /* One value only. */ + if (changegl(category, locname, newgl) == -1) { + freegl(newgl); + return NULL; + } - return 0; -} + /* One common value for all categories. */ + if (category == LC_ALL) { + for (ic = 1; ic < _LC_LAST; ic++) { + if (changegl(ic, locname, + newgl) == -1) { + freegl(newgl); + return NULL; + } + } + } + } + } else + newgl = global_locale; -static char * -loadlocale(int category, const char *locname) -{ - if (strcmp(locname, current_categories[category]) == 0) - return (current_categories[category]); + /* + * Assemble a string representation of the globale locale. + */ - if (!load_locale_sub(category, locname)) { - (void)strlcpy(current_categories[category], - locname, sizeof(current_categories[category])); - return current_categories[category]; - } else { - return NULL; + /* setlocale(3) was never called with a non-NULL argument. */ + if (newgl == NULL) { + (void)strlcpy(global_locname, "C", sizeof(global_locname)); + goto done; } -} - -static const char * -__get_locale_env(int category) -{ - const char *env; - /* 1. check LC_ALL. */ - env = getenv(categories[0]); - - /* 2. check LC_* */ - if (!env || !*env) - env = getenv(categories[category]); + /* Individual category. */ + if (category > LC_ALL) { + if (strlcpy(global_locname, newgl[category], + sizeof(global_locname)) >= sizeof(global_locname)) + global_locname[0] = '\0'; + goto done; + } - /* 3. check LANG */ - if (!env || !*env) - env = getenv("LANG"); + /* LC_ALL overrides everything else. */ + if (newgl[LC_ALL][0] != '\0') { + if (strlcpy(global_locname, newgl[LC_ALL], + sizeof(global_locname)) >= sizeof(global_locname)) + global_locname[0] = '\0'; + goto done; + } - /* 4. if none is set, fall to "C" */ - if (!env || !*env || strchr(env, '/')) - env = "C"; + /* + * Check whether all categories agree and return either + * the single common name for all categories or a string + * listing the names for all categories. + */ + for (ic = 2; ic < _LC_LAST; ic++) + if (strcmp(newgl[ic], newgl[1]) != 0) + break; + if (ic == _LC_LAST) { + if (strlcpy(global_locname, newgl[1], + sizeof(global_locname)) >= sizeof(global_locname)) + global_locname[0] = '\0'; + } else { + ic = snprintf(global_locname, sizeof(global_locname), + "%s/%s/%s/%s/%s/%s", newgl[1], newgl[2], newgl[3], + newgl[4], newgl[5], newgl[6]); + if (ic == -1 || ic >= sizeof(global_locname)) + global_locname[0] = '\0'; + } - return env; +done: + if (locname != NULL) { + /* + * We can't replace the global locale earlier + * because we first have to make sure that we + * also have the memory required to report success. + */ + if (global_locname[0] != '\0') { + freegl(global_locale); + global_locale = newgl; + if (category == LC_ALL || category == LC_CTYPE) + _GlobalRuneLocale = + strchr(global_locname, '.') == NULL ? + &_DefaultRuneLocale : _Utf8RuneLocale; + } else { + freegl(newgl); + return NULL; + } + } + return global_locname; } +DEF_STRONG(setlocale); diff --git a/lib/libc/locale/setrunelocale.c b/lib/libc/locale/setrunelocale.c deleted file mode 100644 index 754a1b30dfe..00000000000 --- a/lib/libc/locale/setrunelocale.c +++ /dev/null @@ -1,164 +0,0 @@ -/* $OpenBSD: setrunelocale.c,v 1.15 2016/09/05 09:47:03 schwarze Exp $ */ -/* $NetBSD: setrunelocale.c,v 1.14 2003/08/07 16:43:07 agc Exp $ */ - -/*- - * Copyright (c)1999 Citrus Project, - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*- - * Copyright (c) 1998 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Paul Kranenburg. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <errno.h> -#include <limits.h> -#include <paths.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <wchar.h> - -#include "citrus_ctype.h" -#include "rune.h" -#include "rune_local.h" - -static _RuneLocale *_Utf8RuneLocale; - - -int -_newrunelocale(const char *path) -{ - FILE *fp; - - if (_Utf8RuneLocale != NULL) - return 0; - - if ((fp = fopen(path, "re")) == NULL) - return ENOENT; - - if ((_Utf8RuneLocale = _Read_RuneMagi(fp)) == NULL) { - fclose(fp); - return EFTYPE; - } - fclose(fp); - return 0; -} - -int -_xpg4_setrunelocale(const char *locname) -{ - char path[PATH_MAX]; - int error, len; - const char *dot, *encoding; - - if (!strcmp(locname, "C") || !strcmp(locname, "POSIX")) { - _CurrentRuneLocale = &_DefaultRuneLocale; - __mb_cur_max = 1; - return 0; - } - - /* Assumes "language[_territory][.codeset]" locale name. */ - dot = strrchr(locname, '.'); - if (dot == NULL) { - /* No encoding specified. Fall back to ASCII. */ - _CurrentRuneLocale = &_DefaultRuneLocale; - __mb_cur_max = 1; - return 0; - } - - encoding = dot + 1; - if (strcmp(encoding, "UTF-8") != 0) - return ENOTSUP; - - len = snprintf(path, sizeof(path), - "%s/UTF-8/LC_CTYPE", _PATH_LOCALE); - if (len < 0 || len >= sizeof(path)) - return ENAMETOOLONG; - - error = _newrunelocale(path); - if (error) - return error; - if (_Utf8RuneLocale == NULL) - return ENOENT; - _CurrentRuneLocale = _Utf8RuneLocale; - __mb_cur_max = _CITRUS_UTF8_MB_CUR_MAX; - return 0; -} diff --git a/lib/libc/locale/towctrans.3 b/lib/libc/locale/towctrans.3 index 816990c34ac..399dff7ce2b 100644 --- a/lib/libc/locale/towctrans.3 +++ b/lib/libc/locale/towctrans.3 @@ -1,8 +1,8 @@ -.\" $OpenBSD: towctrans.3,v 1.2 2007/05/31 19:19:29 jmc Exp $ -.\" +.\" $OpenBSD: towctrans.3,v 1.3 2017/09/05 03:16:13 schwarze Exp $ .\" $NetBSD: towctrans.3,v 1.5 2004/01/24 16:58:54 wiz Exp $ .\" -.\" Copyright (c)2003 Citrus Project, +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> +.\" Copyright (c) 2003 Citrus Project .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -26,61 +26,72 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: May 31 2007 $ +.Dd $Mdocdate: September 5 2017 $ .Dt TOWCTRANS 3 .Os -.\" ---------------------------------------------------------------------- .Sh NAME -.Nm towctrans +.Nm towctrans , +.Nm towctrans_l .Nd convert a wide character with a specified map -.\" ---------------------------------------------------------------------- .Sh SYNOPSIS .In wctype.h .Ft wint_t .Fn towctrans "wint_t wc" "wctrans_t charmap" -.\" ---------------------------------------------------------------------- +.Ft wint_t +.Fn towctrans_l "wint_t wc" "wctrans_t charmap" "locale_t locale" .Sh DESCRIPTION -The -.Fn towctrans -function converts a wide character +These functions convert the wide character .Fa wc with a character mapping .Fa charmap . .Pp -The behaviour of -.Fn towctrans -is undefined if the -.Fn towctrans -function is called with an invalid +The behaviour is undefined if .Fa charmap -(changes of -.Dv LC_CTYPE -category invalidate -.Fa charmap ) -or invalid wide character -.Fa wc . -.Pp -The behaviour of -.Fn towctrans -is affected by the -.Dv LC_CTYPE -category of the current locale. -.\" ---------------------------------------------------------------------- +or +.Fa wc +is invalid. +When +.Fa charmap +is retrieved with +.Xr wctrans 3 , +it becomes invalid when the thread-specific character encoding locale +is changed with +.Xr uselocale 3 +or when the global character encoding locale is changed with +.Xr setlocale 3 . +When +.Fa charmap +is retrieved with +.Xr wctrans_l 3 , +it is only valid for use with the same +.Fa locale +argument. .Sh RETURN VALUES -.Fn towctrans -returns the resulting character of the conversion. -.\" ---------------------------------------------------------------------- -.Sh ERRORS -No errors are defined. -.\" ---------------------------------------------------------------------- +These functions return the resulting wide character, or +.Fa wc +if there is no corresponding character in +.Fa charmap . .Sh SEE ALSO .Xr iswctype 3 , +.Xr newlocale 3 , .Xr setlocale 3 , -.Xr wctrans 3 , -.Xr wctype 3 -.\" ---------------------------------------------------------------------- +.Xr towlower 3 , +.Xr wctrans 3 .Sh STANDARDS The .Fn towctrans function conforms to -.St -isoC-amd1 . +.St -isoC-amd1 , +and +.Fn towctrans_l +to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn towctrans +function has been available since +.Ox 3.8 , +and +.Fn towctrans_l +since +.Ox 6.2 . diff --git a/lib/libc/locale/towlower.3 b/lib/libc/locale/towlower.3 index afb6f29b0f2..d4f9422eb00 100644 --- a/lib/libc/locale/towlower.3 +++ b/lib/libc/locale/towlower.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: towlower.3,v 1.5 2014/04/07 17:57:56 schwarze Exp $ +.\" $OpenBSD: towlower.3,v 1.6 2017/09/05 03:16:13 schwarze Exp $ .\" $NetBSD: towlower.3,v 1.7 2003/09/08 17:54:31 wiz Exp $ .\" .\" Copyright (c) 1989, 1991 The Regents of the University of California. @@ -34,38 +34,88 @@ .\" .\" @(#)tolower.3 5.2 (Berkeley) 6/29/91 .\" -.Dd $Mdocdate: April 7 2014 $ +.Dd $Mdocdate: September 5 2017 $ .Dt TOWLOWER 3 .Os .Sh NAME .Nm towlower , -.Nm towupper +.Nm towlower_l , +.Nm towupper , +.Nm towupper_l .Nd wide-character case letter conversion utilities .Sh SYNOPSIS .In wctype.h .Ft wint_t .Fn towlower "wint_t wc" .Ft wint_t +.Fn towlower_l "wint_t wc" "locale_t locale" +.Ft wint_t .Fn towupper "wint_t wc" +.Ft wint_t +.Fn towupper_l "wint_t wc" "locale_t locale" .Sh DESCRIPTION The .Fn towlower -function converts an upper-case wide character to the corresponding lower-case -letter. +and +.Fn towlower_l +functions convert an upper-case wide character +to the corresponding lower-case letter. The .Fn towupper -function converts an lower-case wide character to the corresponding upper-case -letter. +and +.Fn towupper_l +functions convert a lower-case wide character +to the corresponding upper-case letter. +.Pp +The functions +.Fn towlower_l +and +.Fn towupper_l +use the specified +.Fa locale , +whereas +.Fn towlower +and +.Fn towupper +use the thread-specific locale set with +.Xr uselocale 3 , +falling back to the global locale set with +.Xr setlocale 3 . .Sh RETURN VALUES -If the argument is an upper/lower-case letter, the -.Fn tolower -function returns the corresponding counterpart if there is -one; otherwise the argument is returned unchanged. +These functions return the corresponding character, if any. +Otherwise, +.Fa wc +is returned unchanged. .Sh SEE ALSO +.Xr iswlower 3 , .Xr tolower 3 , -.Xr toupper 3 +.Xr toupper 3 , +.Xr towctrans 3 .Sh STANDARDS -The functions conform to +The functions +.Fn towlower +and +.Fn towupper +conform to .St -isoC-amd1 and -.St -isoC-99 . +.St -isoC-99 , +and +.Fn towlower_l +and +.Fn towupper_l +to +.St -p1003.1-2008 . +.Sh HISTORY +The functions +.Fn towlower +and +.Fn towupper +have been available since +.Ox 3.8 , +and +.Fn towlower_l +and +.Fn towupper_l +since +.Ox 6.2 . diff --git a/lib/libc/locale/uselocale.3 b/lib/libc/locale/uselocale.3 new file mode 100644 index 00000000000..9597af87e10 --- /dev/null +++ b/lib/libc/locale/uselocale.3 @@ -0,0 +1,101 @@ +.\" $OpenBSD: uselocale.3,v 1.1 2017/09/05 03:16:13 schwarze Exp $ +.\" +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: September 5 2017 $ +.Dt USELOCALE 3 +.Os +.Sh NAME +.Nm uselocale +.Nd select the locale for the current thread +.Sh SYNOPSIS +.In locale.h +.Ft locale_t +.Fo uselocale +.Fa "locale_t newloc" +.Fc +.Sh DESCRIPTION +The function +.Fn uselocale +selects +.Fa newloc +for use by functions in the current thread that do not take a +.Vt locale_t +argument. +Neither the global locale set by +.Xr setlocale 3 +nor locales used by other threads change. +.Pp +The current thread uses +.Fa newloc +until +.Fn uselocale +is called again successfully with a non-null argument +in the same thread, and passing +.Fa newloc +to +.Xr freelocale 3 +or +.Xr newlocale 3 +before that results in undefined behaviour. +.Pp +To revoke the use of +.Fa newloc +in the current thread without installing another thread-specific locale, +instead reverting to the global locale, call +.Fn uselocale +with the special argument +.Dv LC_GLOBAL_LOCALE . +.Pp +When called with the argument +.Po Vt locale_t Pc Ns 0 , +the thread-specific locale remains unchanged. +.Sh RETURN VALUES +The function +.Fn uselocale +returns the thread-specific locale which is in use right before the call, +or the special return value +.Dv LC_GLOBAL_LOCALE +if the thread used the global locale before the call. +.Sh ERRORS +The function +.Fn uselocale +fails if: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa newloc +argument is neither a valid locale object nor +.Po Vt locale_t Pc Ns 0 . +.El +.Sh SEE ALSO +.Xr iswalnum 3 , +.Xr iswctype 3 , +.Xr newlocale 3 , +.Xr towctrans 3 , +.Xr towlower 3 , +.Xr wcscasecmp 3 , +.Xr wctrans 3 , +.Xr wctype 3 +.Sh STANDARDS +The function +.Fn uselocale +conforms to +.St -p1003.1-2008 . +.Sh HISTORY +The function +.Fn uselocale +has been available since +.Ox 6.2 . diff --git a/lib/libc/locale/uselocale.c b/lib/libc/locale/uselocale.c new file mode 100644 index 00000000000..b67c2041947 --- /dev/null +++ b/lib/libc/locale/uselocale.c @@ -0,0 +1,45 @@ +/* $OpenBSD: uselocale.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* + * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <errno.h> +#include <locale.h> +#include <tib.h> + +#include "rune.h" + +locale_t +uselocale(locale_t newloc) +{ + struct tib *tib; + _RuneLocale *oldrunes; + + tib = TIB_GET(); + oldrunes = tib->tib_locale; + + if (newloc == _LOCALE_UTF8 && _Utf8RuneLocale != NULL) + tib->tib_locale = _Utf8RuneLocale; + else if (newloc == _LOCALE_C) + tib->tib_locale = &_DefaultRuneLocale; + else if (newloc == LC_GLOBAL_LOCALE) + tib->tib_locale = NULL; + else if (newloc != _LOCALE_NONE) { + errno = EINVAL; + return _LOCALE_NONE; + } + return oldrunes == NULL ? LC_GLOBAL_LOCALE : + oldrunes == _Utf8RuneLocale ? _LOCALE_UTF8 : _LOCALE_C; +} diff --git a/lib/libc/locale/wcscoll.3 b/lib/libc/locale/wcscoll.3 new file mode 100644 index 00000000000..4ce87355462 --- /dev/null +++ b/lib/libc/locale/wcscoll.3 @@ -0,0 +1,99 @@ +.\" $OpenBSD: wcscoll.3,v 1.1 2017/09/05 03:16:13 schwarze Exp $ +.\" +.\" Copyright (c) 1990, 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Chris Torek and the American National Standards Committee X3, +.\" on Information Processing Systems. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd $Mdocdate: September 5 2017 $ +.Dt WCSCOLL 3 +.Os +.Sh NAME +.Nm wcscoll , +.Nm wcscoll_l +.Nd compare wide strings according to the current collation +.Sh SYNOPSIS +.In wchar.h +.Ft int +.Fn wcscoll "const wchar_t *s1" "const wchar_t *s2" +.Ft int +.Fn wcscoll_l "const wchar_t *s1" "const wchar_t *s2" "locale_t locale" +.Sh DESCRIPTION +The +.Fn wcscoll +and +.Fn wcscoll_l +functions lexicographically compare the NUL-terminated wide strings +.Fa s1 +and +.Fa s2 +according to the current locale collation +and return an integer greater than, equal to, or less than 0, +according to whether +.Fa s1 +is greater than, equal to, or less than +.Fa s2 . +.Pp +On +.Ox , +they have the same effect as +.Xr wcscmp 3 , +and the global locale, the thread-specific locale, and the +.Fa locale +argument are ignored. +.Sh ENVIRONMENT +On other operating systems, the behaviour of +.Fn wcscoll +may depend on the +.Dv LC_CTYPE +.Xr locale 1 . +.Sh SEE ALSO +.Xr newlocale 3 , +.Xr setlocale 3 , +.Xr wcscmp 3 , +.Xr wcsxfrm 3 +.Sh STANDARDS +The +.Fn wcscoll +function conforms to +.St -isoC-99 , +and +.Fn wcscoll_l +to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn wcscoll +function has been available since +.Ox 4.8 , +and +.Fn wcscoll_l +since +.Ox 6.2 . diff --git a/lib/libc/locale/wcscoll_l.c b/lib/libc/locale/wcscoll_l.c new file mode 100644 index 00000000000..7bfd1563109 --- /dev/null +++ b/lib/libc/locale/wcscoll_l.c @@ -0,0 +1,17 @@ +/* $OpenBSD: wcscoll_l.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* + * Written in 2017 by Ingo Schwarze <schwarze@openbsd.org>. + * Released into the public domain. + */ + +#include <wchar.h> + +/* + * Locale-dependent collation is intentionally unsupported. + */ +int +wcscoll_l(const wchar_t *s1, const wchar_t *s2, + locale_t locale __attribute__((__unused__))) +{ + return wcscmp(s1, s2); +} diff --git a/lib/libc/locale/wcsxfrm.3 b/lib/libc/locale/wcsxfrm.3 new file mode 100644 index 00000000000..b1337e0507c --- /dev/null +++ b/lib/libc/locale/wcsxfrm.3 @@ -0,0 +1,101 @@ +.\" $OpenBSD: wcsxfrm.3,v 1.1 2017/09/05 03:16:13 schwarze Exp $ +.\" +.\" Copyright (c) 1990, 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Chris Torek and the American National Standards Committee X3, +.\" on Information Processing Systems. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd $Mdocdate: September 5 2017 $ +.Dt WCSXFRM 3 +.Os +.Sh NAME +.Nm wcsxfrm , +.Nm wcsxfrm_l +.Nd transform a wide string under locale +.Sh SYNOPSIS +.In wchar.h +.Ft size_t +.Fn wcsxfrm "wchar_t *dst" "const wchar_t *src" "size_t n" +.Ft size_t +.Fn wcsxfrm_l "wchar_t *dst" "const wchar_t *src" "size_t n" "locale_t locale" +.Sh DESCRIPTION +The idea of +.Fn wcsxfrm +and +.Fn wcsxfrm_l +is to +.Dq un-localize +a wide string: the functions transform +.Ar src , +storing the result in +.Ar dst , +such that +.Xr wcscmp 3 +on transformed wide strings returns what +.Xr wcscoll 3 +on the original untransformed wide strings would return. +.Pp +On +.Ox , +both have the same effect as +.Xr wcslcpy 3 , +and the global locale, the thread-specific locale, and the +.Fa locale +argument are ignored. +.Sh ENVIRONMENT +On other operating systems, the behaviour of +.Fn wcsxfrm +may depend on the +.Dv LC_CTYPE +.Xr locale 1 . +.Sh SEE ALSO +.Xr newlocale 3 , +.Xr setlocale 3 , +.Xr wcscmp 3 , +.Xr wcscoll 3 , +.Xr wcslcpy 3 +.Sh STANDARDS +The +.Fn wcsxfrm +function conforms to +.St -isoC-99 , +and +.Fn wcsxfrm_l +to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn wcsxfrm +function has been available since +.Ox 4.8 , +and +.Fn wcsxfrm_l +since +.Ox 6.2 . diff --git a/lib/libc/locale/wcsxfrm.c b/lib/libc/locale/wcsxfrm.c index 98db4a98fab..3d1e5803f7b 100644 --- a/lib/libc/locale/wcsxfrm.c +++ b/lib/libc/locale/wcsxfrm.c @@ -1,6 +1,5 @@ -/* $OpenBSD: wcsxfrm.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */ -/* $OpenBSD: wcsxfrm.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */ -/* $NetBSD: multibyte_sb.c,v 1.4 2003/08/07 16:43:04 agc Exp $ */ +/* $OpenBSD: wcsxfrm.c,v 1.3 2017/09/05 03:16:13 schwarze Exp $ */ +/* $NetBSD: multibyte_sb.c,v 1.4 2003/08/07 16:43:04 agc Exp $ */ /* * Copyright (c) 1991 The Regents of the University of California. @@ -40,3 +39,4 @@ wcsxfrm(wchar_t *dest, const wchar_t *src, size_t n) return wcslen(src); return wcslcpy(dest, src, n); } +DEF_STRONG(wcsxfrm); diff --git a/lib/libc/locale/wcsxfrm_l.c b/lib/libc/locale/wcsxfrm_l.c new file mode 100644 index 00000000000..1b7925dc8d9 --- /dev/null +++ b/lib/libc/locale/wcsxfrm_l.c @@ -0,0 +1,14 @@ +/* $OpenBSD: wcsxfrm_l.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* + * Written in 2017 by Ingo Schwarze <schwarze@openbsd.org>. + * Released into the public domain. + */ + +#include <wchar.h> + +size_t +wcsxfrm_l(wchar_t *dest, const wchar_t *src, size_t n, + locale_t locale __attribute__((__unused__))) +{ + return wcsxfrm(dest, src, n); +} diff --git a/lib/libc/locale/wctrans.3 b/lib/libc/locale/wctrans.3 index 6fe8ca5ae4a..1ef1813b389 100644 --- a/lib/libc/locale/wctrans.3 +++ b/lib/libc/locale/wctrans.3 @@ -1,8 +1,8 @@ -.\" $OpenBSD: wctrans.3,v 1.2 2007/05/31 19:19:29 jmc Exp $ -.\" +.\" $OpenBSD: wctrans.3,v 1.3 2017/09/05 03:16:13 schwarze Exp $ .\" $NetBSD: wctrans.3,v 1.4 2004/01/24 16:58:54 wiz Exp $ .\" -.\" Copyright (c)2003 Citrus Project, +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> +.\" Copyright (c) 2003 Citrus Project .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -26,63 +26,71 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: May 31 2007 $ +.Dd $Mdocdate: September 5 2017 $ .Dt WCTRANS 3 .Os -.\" ---------------------------------------------------------------------- .Sh NAME -.Nm wctrans -.Nd get character mapping identifier by name -.\" ---------------------------------------------------------------------- +.Nm wctrans , +.Nm wctrans_l +.Nd get a character mapping identifier by name .Sh SYNOPSIS .In wctype.h .Ft wctrans_t .Fn wctrans "const char *charmap" -.\" ---------------------------------------------------------------------- +.Ft wctrans_t +.Fn wctrans_l "const char *charmap" "locale_t locale" .Sh DESCRIPTION -The -.Fn wctrans -function returns a character mapping identifier corresponding to the -locale-specific character mapping name +These functions return a character mapping identifier +corresponding to the locale-specific character mapping name .Fa charmap . -This identifier can be used on the subsequent calls of -.Fn towctrans . +This identifier can be used in the subsequent calls of +.Fn towctrans +or +.Fn towctrans_l , +respectively. +.Pp The following names are defined in all locales: .Bd -literal -offset indent tolower toupper .Ed .Pp -The behaviour of +The function +.Fn wctrans_l +uses the specified +.Fa locale , +whereas .Fn wctrans -is affected by the -.Dv LC_CTYPE -category of the current locale. -.\" ---------------------------------------------------------------------- +uses the thread-specific locale set with +.Xr uselocale 3 , +falling back to the global locale set with +.Xr setlocale 3 . .Sh RETURN VALUES -.Fn wctrans -returns: -.Bl -tag -width 012345678901 -.It 0 -If the string +These functions return the character mapping identifier, or +.Po Vt wctrans_t Pc Ns 0 +if .Fa charmap does not corresponding to a valid character mapping name. -.It non-zero -A character mapping identifier corresponding to -.Fa charmap . -.El -.Pp -Note: wctype_t is a scalar type, e.g., a pointer. -.\" ---------------------------------------------------------------------- -.Sh ERRORS -No errors are defined. -.\" ---------------------------------------------------------------------- .Sh SEE ALSO -.Xr iswctype 3 , +.Xr newlocale 3 , .Xr setlocale 3 , +.Xr towctrans 3 , +.Xr towlower 3 , .Xr wctype 3 -.\" ---------------------------------------------------------------------- .Sh STANDARDS The -.Fn towctrans +.Fn wctrans function conforms to -.St -isoC-amd1 . +.St -isoC-amd1 , +and +.Fn wctrans_l +to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn wctrans +function has been available since +.Ox 3.8 , +and +.Fn wctrans_l +since +.Ox 6.2 . diff --git a/lib/libc/locale/wctype.3 b/lib/libc/locale/wctype.3 index 61c83d297c8..9613bb9d1e0 100644 --- a/lib/libc/locale/wctype.3 +++ b/lib/libc/locale/wctype.3 @@ -1,7 +1,8 @@ -.\" $OpenBSD: wctype.3,v 1.3 2013/06/05 03:39:22 tedu Exp $ +.\" $OpenBSD: wctype.3,v 1.4 2017/09/05 03:16:13 schwarze Exp $ .\" $NetBSD: wctype.3,v 1.4 2003/04/16 13:34:41 wiz Exp $ .\" -.\" Copyright (c)2003 Citrus Project, +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> +.\" Copyright (c) 2003 Citrus Project .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -25,67 +26,71 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: June 5 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt WCTYPE 3 .Os -.\" ---------------------------------------------------------------------- .Sh NAME -.Nm wctype -.Nd get character class identifier by name -.\" ---------------------------------------------------------------------- +.Nm wctype , +.Nm wctype_l +.Nd get a character class identifier by name .Sh SYNOPSIS .In wctype.h .Ft wctype_t .Fn wctype "const char *charclass" -.\" ---------------------------------------------------------------------- +.Ft wctype_t +.Fn wctype_l "const char *charclass" "locale_t locale" .Sh DESCRIPTION -The -.Fn wctype -function returns a character class identifier corresponding to the -locale-specific character class name +These functions return a character class identifier +corresponding to the locale-specific character class name .Fa charclass . This identifier can be used in subsequent calls of -.Fn iswctype . +.Fn iswctype +or +.Fn iswctype_l , +respectively. +.Pp The following names are defined in all locales: .Bd -literal -offset indent alnum alpha blank cntrl digit graph lower print punct space upper xdigit .Ed .Pp -The behaviour of +The function +.Fn wctype_l +uses the specified +.Fa locale , +whereas .Fn wctype -is affected by the -.Dv LC_CTYPE -category of the current locale. -.\" ---------------------------------------------------------------------- +uses the thread-specific locale set with +.Xr uselocale 3 , +falling back to the global locale set with +.Xr setlocale 3 . .Sh RETURN VALUES -.Fn wcttype -returns: -.Bl -tag -width 012345678901 -.It 0 -If +These functions return the character class identifier, or +.Po Vt wctype_t Pc Ns 0 +if .Fa charclass does not correspond to a valid character class name. -.It non-zero -A character class identifier corresponding to -.Fa charclass . -.El -.Pp -Note: wctype_t is a scalar type, e.g., a pointer. -.\" ---------------------------------------------------------------------- -.Sh ERRORS -No errors are defined. -.\" ---------------------------------------------------------------------- .Sh SEE ALSO .Xr iswctype 3 , +.Xr newlocale 3 , .Xr setlocale 3 , -.Xr towctrans 3 , .Xr wctrans 3 -.\" ---------------------------------------------------------------------- .Sh STANDARDS The .Fn wctype function conforms to -.\" .St -isoC-amd1 . -ISO/IEC 9899/AMD1:1995 -.Pq Sq ISO C90, Amendment 1 . +.St -isoC-amd1 , +and +.Fn wctype_l +to +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn wctype +function has been available since +.Ox 3.8 , +and +.Fn wctype_l +since +.Ox 6.2 . diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index 95eb93006b8..a1b1934aad0 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -1,17 +1,17 @@ -# $OpenBSD: Makefile.inc,v 1.38 2016/03/30 06:38:41 jmc Exp $ +# $OpenBSD: Makefile.inc,v 1.39 2017/09/05 03:16:13 schwarze Exp $ # string sources .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/string ${LIBCSRCDIR}/string SRCS+= explicit_bzero.c memccpy.c memmem.c memrchr.c stpcpy.c stpncpy.c \ - strcasecmp.c strcasestr.c strcoll.c strdup.c \ - strerror.c strerror_r.c strmode.c strndup.c strnlen.c \ - strsignal.c strtok.c strxfrm.c \ + strcasecmp.c strcasecmp_l.c strcasestr.c strcoll.c strcoll_l.c \ + strdup.c strerror.c strerror_l.c strerror_r.c strmode.c \ + strndup.c strnlen.c strsignal.c strtok.c strxfrm.c strxfrm_l.c \ timingsafe_bcmp.c timingsafe_memcmp.c \ wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \ wcslen.c wcsncat.c wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c \ wcsstr.c wcstok.c wcswcs.c wcswidth.c wmemchr.c wmemcmp.c wmemcpy.c \ - wmemmove.c wmemset.c wcsdup.c wcscasecmp.c + wmemmove.c wmemset.c wcsdup.c wcscasecmp.c wcscasecmp_l.c # machine-dependent net sources # ../arch/ARCH/Makefile.inc must include sources for: diff --git a/lib/libc/string/strcasecmp.3 b/lib/libc/string/strcasecmp.3 index 38703622160..bb39df895a0 100644 --- a/lib/libc/string/strcasecmp.3 +++ b/lib/libc/string/strcasecmp.3 @@ -1,7 +1,8 @@ -.\" $OpenBSD: strcasecmp.3,v 1.13 2015/11/24 09:14:35 daniel Exp $ +.\" $OpenBSD: strcasecmp.3,v 1.14 2017/09/05 03:16:13 schwarze Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" .\" This code is derived from software contributed to Berkeley by .\" Chris Torek. @@ -31,25 +32,43 @@ .\" .\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93 .\" -.Dd $Mdocdate: November 24 2015 $ +.Dd $Mdocdate: September 5 2017 $ .Dt STRCASECMP 3 .Os .Sh NAME .Nm strcasecmp , -.Nm strncasecmp +.Nm strcasecmp_l , +.Nm strncasecmp , +.Nm strncasecmp_l .Nd compare strings, ignoring case .Sh SYNOPSIS .In strings.h .Ft int -.Fn strcasecmp "const char *s1" "const char *s2" +.Fo strcasecmp +.Fa "const char *s1" +.Fa "const char *s2" +.Fc .Ft int -.Fn strncasecmp "const char *s1" "const char *s2" "size_t len" +.Fo strcasecmp_l +.Fa "const char *s1" +.Fa "const char *s2" +.Fa "locale_t locale" +.Fc +.Ft int +.Fo strncasecmp +.Fa "const char *s1" +.Fa "const char *s2" +.Fa "size_t len" +.Fc +.Ft int +.Fo strncasecmp_l +.Fa "const char *s1" +.Fa "const char *s2" +.Fa "size_t len" +.Fa "locale_t locale" +.Fc .Sh DESCRIPTION -The -.Fn strcasecmp -and -.Fn strncasecmp -functions compare the NUL-terminated strings +These functions compare the NUL-terminated strings .Fa s1 and .Fa s2 @@ -66,27 +85,44 @@ is greater than .Ql \e0 . .Pp .Fn strncasecmp -compares at most +and +.Fn strncasecmp_l +compare at most .Fa len characters. +.Pp +On +.Ox , +these functions always use the C locale and ignore +the global locale, the thread-specific locale, and the +.Fa locale +argument. +.Sh ENVIRONMENT +On other operating systems, the behaviour of +.Fn strcasecmp +and +.Fn strncasecmp +may depend on the +.Dv LC_CTYPE +.Xr locale 1 . .Sh SEE ALSO -.Xr bcmp 3 , -.Xr memcmp 3 , .Xr strcmp 3 , .Xr strcoll 3 , .Xr strxfrm 3 , .Xr wcscasecmp 3 .Sh STANDARDS -The -.Fn strcasecmp -and -.Fn strncasecmp -functions conform to +These functions conform to .St -p1003.1-2008 . .Sh HISTORY The .Fn strcasecmp and .Fn strncasecmp -functions first appeared in -.Bx 4.3 Tahoe . +functions have been available since +.Bx 4.3 Tahoe , +and +.Fn strcasecmp_l +and +.Fn strncasecmp_l +since +.Ox 6.2 . diff --git a/lib/libc/string/strcasecmp_l.c b/lib/libc/string/strcasecmp_l.c new file mode 100644 index 00000000000..a9543dda118 --- /dev/null +++ b/lib/libc/string/strcasecmp_l.c @@ -0,0 +1,21 @@ +/* $OpenBSD: strcasecmp_l.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* + * Written in 2017 by Ingo Schwarze <schwarze@openbsd.org>. + * Released into the public domain. + */ + +#include <string.h> + +int +strcasecmp_l(const char *s1, const char *s2, + locale_t locale __attribute__((__unused__))) +{ + return strcasecmp(s1, s2); +} + +int +strncasecmp_l(const char *s1, const char *s2, size_t n, + locale_t locale __attribute__((__unused__))) +{ + return strncasecmp(s1, s2, n); +} diff --git a/lib/libc/string/strcoll.3 b/lib/libc/string/strcoll.3 index d421200b628..4ba1f226776 100644 --- a/lib/libc/string/strcoll.3 +++ b/lib/libc/string/strcoll.3 @@ -1,4 +1,7 @@ +.\" $OpenBSD: strcoll.3,v 1.10 2017/09/05 03:16:13 schwarze Exp $ +.\" .\" Copyright (c) 1990, 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -29,45 +32,69 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: strcoll.3,v 1.9 2013/06/05 03:39:23 tedu Exp $ -.\" -.Dd $Mdocdate: June 5 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt STRCOLL 3 .Os .Sh NAME -.Nm strcoll +.Nm strcoll , +.Nm strcoll_l .Nd compare strings according to current collation .Sh SYNOPSIS .In string.h .Ft int .Fn strcoll "const char *s1" "const char *s2" +.Ft int +.Fn strcoll_l "const char *s1" "const char *s2" "locale_t locale" .Sh DESCRIPTION The .Fn strcoll -function lexicographically compares the NUL-terminated strings +and +.Fn strcoll_l +functions lexicographically compare the NUL-terminated strings .Fa s1 and .Fa s2 according to the current locale collation -and returns an integer greater than, equal to, or less than 0, +and return an integer greater than, equal to, or less than 0, according to whether .Fa s1 is greater than, equal to, or less than .Fa s2 . +.Pp +On +.Ox , +they have the same effect as +.Xr strcmp 3 , +and the global locale, the thread-specific locale, and the +.Fa locale +argument are ignored. +.Sh ENVIRONMENT +On other operating systems, the behaviour of +.Fn strcoll +may depend on the +.Dv LC_CTYPE +.Xr locale 1 . .Sh SEE ALSO -.Xr bcmp 3 , -.Xr memcmp 3 , +.Xr newlocale 3 , .Xr setlocale 3 , -.Xr strcasecmp 3 , .Xr strcmp 3 , -.Xr strxfrm 3 +.Xr strxfrm 3 , +.Xr wcscoll 3 .Sh STANDARDS The .Fn strcoll function conforms to -.St -ansiC . +.St -ansiC , +and +.Fn strcoll_l +to +.St -p1003.1-2008 . .Sh HISTORY The .Fn strcoll -function first appeared in -.Bx 4.3 Reno . +function has been available since +.Bx 4.3 Reno , +and +.Fn strcoll_l +since +.Ox 6.2 . diff --git a/lib/libc/string/strcoll_l.c b/lib/libc/string/strcoll_l.c new file mode 100644 index 00000000000..bcd5b0f4177 --- /dev/null +++ b/lib/libc/string/strcoll_l.c @@ -0,0 +1,14 @@ +/* $OpenBSD: strcoll_l.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* + * Written in 2017 by Ingo Schwarze <schwarze@openbsd.org>. + * Released into the public domain. + */ + +#include <string.h> + +int +strcoll_l(const char *s1, const char *s2, + locale_t locale __attribute__((__unused__))) +{ + return strcmp(s1, s2); +} diff --git a/lib/libc/string/strerror.3 b/lib/libc/string/strerror.3 index 8b2d32ea75a..0d4f084e5e0 100644 --- a/lib/libc/string/strerror.3 +++ b/lib/libc/string/strerror.3 @@ -1,4 +1,7 @@ +.\" $OpenBSD: strerror.3,v 1.15 2017/09/05 03:16:13 schwarze Exp $ +.\" .\" Copyright (c) 1980, 1991 Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -29,46 +32,61 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: strerror.3,v 1.14 2014/11/30 21:21:59 schwarze Exp $ -.\" -.Dd $Mdocdate: November 30 2014 $ +.Dd $Mdocdate: September 5 2017 $ .Dt STRERROR 3 .Os .Sh NAME .Nm strerror , +.Nm strerror_l , .Nm strerror_r .Nd get error message string .Sh SYNOPSIS .In string.h .Ft char * .Fn strerror "int errnum" +.Ft char * +.Fn strerror_l "int errnum" "locale_t locale" .Ft int .Fn strerror_r "int errnum" "char *strerrbuf" "size_t buflen" .Sh DESCRIPTION -The -.Fn strerror -and -.Fn strerror_r -functions map the error number +These functions map the error number .Fa errnum -to a language-dependent error message string. +to an error message string. .Pp .Fn strerror -returns a string containing a maximum of +and +.Fn strerror_l +return a string containing a maximum of .Dv NL_TEXTMAX characters, including the trailing NUL. -This string is not to be modified by the calling program, -but may be overwritten by subsequent calls to -.Fn strerror . +This string is not to be modified by the calling program. +The string returned by +.Fn strerror +may be overwritten by subsequent calls to +.Fn strerror +in any thread. +The string returned by +.Fn strerror_l +may be overwritten by subsequent calls to +.Fn strerror_l +in the same thread. .Pp .Fn strerror_r is a thread safe version of .Fn strerror that places the error message in the specified buffer .Fa strerrbuf . +.Pp +On +.Ox , +the global locale, the thread-specific locale, and the +.Fa locale +argument are ignored. .Sh RETURN VALUES .Fn strerror -returns a pointer to the error message string. +and +.Fn strerror_l +return a pointer to the error message string. If an error occurs, the error code is stored in .Va errno . .Pp @@ -77,11 +95,16 @@ returns zero upon successful completion. If an error occurs, the error code is stored in .Va errno and the error code is returned. -.Sh ERRORS +.Sh ENVIRONMENT +On other operating systems, the behaviour of .Fn strerror and .Fn strerror_r -may fail if: +may depend on the +.Dv LC_MESSAGES +.Xr locale 1 . +.Sh ERRORS +All these functions may fail if: .Bl -tag -width Er .It Bq Er EINVAL .Fa errnum @@ -91,7 +114,7 @@ The returned error string will consist of an error message that includes .El .Pp .Fn strerror_r -may fail if: +may also fail if: .Bl -tag -width Er .It Bq Er ERANGE The error message is larger than @@ -101,6 +124,7 @@ The message will be truncated to fit. .El .Sh SEE ALSO .Xr intro 2 , +.Xr newlocale 3 , .Xr perror 3 , .Xr setlocale 3 .Sh STANDARDS @@ -109,15 +133,20 @@ The function conforms to .St -isoC-99 . The +.Fn strerror_l +and .Fn strerror_r -function conforms to +functions conform to .St -p1003.1-2008 . .Sh HISTORY The .Fn strerror -function first appeared in -.Bx 4.3 Reno . -The +function has been available since +.Bx 4.3 Reno , .Fn strerror_r -function first appeared in -.Ox 3.3 . +since +.Ox 3.3 , +and +.Fn strerror_l +since +.Ox 6.2 . diff --git a/lib/libc/string/strerror_l.c b/lib/libc/string/strerror_l.c new file mode 100644 index 00000000000..c16be7a0cc2 --- /dev/null +++ b/lib/libc/string/strerror_l.c @@ -0,0 +1,33 @@ +/* $OpenBSD: strerror_l.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* + * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <limits.h> +#include <string.h> + +#include "thread_private.h" + +char * +strerror_l(int errnum, locale_t locale) +{ + static char sel_buf[NL_TEXTMAX]; + _THREAD_PRIVATE_KEY(strerror_l); + char *p = _THREAD_PRIVATE(strerror_l, sel_buf, NULL); + + return p == NULL ? "no buffer available in strerror_l" : + strerror_r(errnum, p, sizeof(sel_buf)) ? + "strerror_r failure" : p; +} diff --git a/lib/libc/string/strxfrm.3 b/lib/libc/string/strxfrm.3 index 481f741cb79..1a96c8512e7 100644 --- a/lib/libc/string/strxfrm.3 +++ b/lib/libc/string/strxfrm.3 @@ -1,4 +1,7 @@ +.\" $OpenBSD: strxfrm.3,v 1.11 2017/09/05 03:16:13 schwarze Exp $ +.\" .\" Copyright (c) 1990, 1991 The Regents of the University of California. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -29,24 +32,27 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: strxfrm.3,v 1.10 2013/06/05 03:39:23 tedu Exp $ -.\" -.Dd $Mdocdate: June 5 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt STRXFRM 3 .Os .Sh NAME -.Nm strxfrm +.Nm strxfrm , +.Nm strxfrm_l .Nd transform a string under locale .Sh SYNOPSIS .In string.h .Ft size_t .Fn strxfrm "char *dst" "const char *src" "size_t n" +.Ft size_t +.Fn strxfrm_l "char *dst" "const char *src" "size_t n" "locale_t locale" .Sh DESCRIPTION The idea of .Fn strxfrm +and +.Fn strxfrm_l is to .Dq un-localize -a string: the function transforms +a string: the functions transform .Ar src , storing the result in .Ar dst , @@ -55,25 +61,42 @@ such that on transformed strings returns what .Xr strcoll 3 on the original untransformed strings would return. +.Pp +On +.Ox , +both have the same effect as +.Xr strlcpy 3 , +and the global locale, the thread-specific locale, and the +.Fa locale +argument are ignored. +.Sh ENVIRONMENT +On other operating systems, the behaviour of +.Fn strxfrm +may depend on the +.Dv LC_CTYPE +.Xr locale 1 . .Sh SEE ALSO -.Xr bcmp 3 , -.Xr memcmp 3 , +.Xr newlocale 3 , .Xr setlocale 3 , -.Xr strcasecmp 3 , .Xr strcmp 3 , -.Xr strcoll 3 +.Xr strcoll 3 , +.Xr strlcpy 3 , +.Xr wcsxfrm 3 .Sh STANDARDS The .Fn strxfrm function conforms to -.St -ansiC . +.St -ansiC , +and +.Fn strxfrm_l +to +.St -p1003.1-2008 . .Sh HISTORY The .Fn strxfrm -function first appeared in -.Bx 4.3 Reno . -.Sh BUGS -Since locales are not fully implemented on -.Ox , -.Fn strxfrm -just returns a copy of the original string. +function has been available since +.Bx 4.3 Reno , +and +.Fn strxfrm_l +since +.Ox 6.2 . diff --git a/lib/libc/string/strxfrm_l.c b/lib/libc/string/strxfrm_l.c new file mode 100644 index 00000000000..ff77947953b --- /dev/null +++ b/lib/libc/string/strxfrm_l.c @@ -0,0 +1,14 @@ +/* $OpenBSD: strxfrm_l.c,v 1.1 2017/09/05 03:16:14 schwarze Exp $ */ +/* + * Written in 2017 by Ingo Schwarze <schwarze@openbsd.org>. + * Released into the public domain. + */ + +#include <string.h> + +size_t +strxfrm_l(char *dst, const char *src, size_t n, + locale_t locale __attribute__((__unused__))) +{ + return strxfrm(dst, src, n); +} diff --git a/lib/libc/string/wcscasecmp.3 b/lib/libc/string/wcscasecmp.3 index daf397aecea..9db4a829b90 100644 --- a/lib/libc/string/wcscasecmp.3 +++ b/lib/libc/string/wcscasecmp.3 @@ -1,7 +1,8 @@ -.\" $OpenBSD: wcscasecmp.3,v 1.4 2013/07/16 15:21:11 schwarze Exp $ +.\" $OpenBSD: wcscasecmp.3,v 1.5 2017/09/05 03:16:14 schwarze Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. +.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> .\" .\" This code is derived from software contributed to Berkeley by .\" Chris Torek. @@ -31,25 +32,43 @@ .\" .\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93 .\" -.Dd $Mdocdate: July 16 2013 $ +.Dd $Mdocdate: September 5 2017 $ .Dt WCSCASECMP 3 .Os .Sh NAME .Nm wcscasecmp , -.Nm wcsncasecmp +.Nm wcscasecmp_l , +.Nm wcsncasecmp , +.Nm wcsncasecmp_l .Nd compare wide strings, ignoring case .Sh SYNOPSIS .In wchar.h .Ft int -.Fn wcscasecmp "const wchar_t *s1" "const wchar_t *s2" +.Fo wcscasecmp +.Fa "const wchar_t *s1" +.Fa "const wchar_t *s2" +.Fc .Ft int -.Fn wcsncasecmp "const wchar_t *s1" "const wchar_t *s2" "size_t len" +.Fo wcscasecmp_l +.Fa "const wchar_t *s1" +.Fa "const wchar_t *s2" +.Fa "locale_t locale" +.Fc +.Ft int +.Fo wcsncasecmp +.Fa "const wchar_t *s1" +.Fa "const wchar_t *s2" +.Fa "size_t len" +.Fc +.Ft int +.Fo wcsncasecmp_l +.Fa "const wchar_t *s1" +.Fa "const wchar_t *s2" +.Fa "size_t len" +.Fa "locale_t locale" +.Fc .Sh DESCRIPTION -The -.Fn wcscasecmp -and -.Fn wcsncasecmp -functions compare the wide strings +These functions compare the wide strings .Fa s1 and .Fa s2 @@ -61,28 +80,49 @@ is lexicographically greater than, equal to, or less than after translation of each corresponding wide character to lower case. The wide strings themselves are not modified. .Pp +For the translation to lower case, +.Fn wcscasecmp +and +.Fn wcsncasecmp +use the thread-specific locale as defined with +.Xr uselocale 3 , +falling back to the global locale defined with +.Xr setlocale 3 . +.Fn wcscasecmp_l +and +.Fn wcsncasecmp_l +use the +.Fa locale +argument instead. +.Pp .Fn wcsncasecmp -compares at most +and +.Fn wcsncasecmp_l +compare at most .Fa len wide characters. .Sh SEE ALSO +.Xr newlocale 3 , +.Xr setlocale 3 , .Xr strcasecmp 3 , .Xr wcscmp 3 , .Xr wmemcmp 3 .Sh STANDARDS -The -.Fn wcscasecmp -and -.Fn wcsncasecmp -functions conform to +These functions conform to .St -p1003.1-2008 . .Sh HISTORY The .Fn wcscasecmp and .Fn wcsncasecmp -functions first appeared in -.Ox 5.0 . +functions have been available since +.Ox 5.0 , +and +.Fn wcscasecmp_l +and +.Fn wcsncasecmp_l +since +.Ox 6.2 . .Sh AUTHORS The .Ox diff --git a/lib/libc/string/wcscasecmp_l.c b/lib/libc/string/wcscasecmp_l.c new file mode 100644 index 00000000000..35b99225c11 --- /dev/null +++ b/lib/libc/string/wcscasecmp_l.c @@ -0,0 +1,63 @@ +/* $OpenBSD: wcscasecmp_l.c,v 1.1 2017/09/05 03:16:14 schwarze Exp $ */ + +/* + * Copyright (c) 2011 Marc Espie + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD + * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <wchar.h> +#include <wctype.h> +#include "locale/runetype.h" + +int +wcscasecmp_l(const wchar_t *s1, const wchar_t *s2, locale_t locale) +{ + wchar_t l1, l2; + + while ((l1 = towlower_l(*s1++, locale)) == + (l2 = towlower_l(*s2++, locale))) { + if (l1 == 0) + return (0); + } + /* XXX assumes wchar_t = int */ + return ((rune_t)l1 - (rune_t)l2); +} + +int +wcsncasecmp_l(const wchar_t *s1, const wchar_t *s2, size_t n, locale_t locale) +{ + wchar_t l1, l2; + + if (n == 0) + return (0); + do { + if (((l1 = towlower_l(*s1++, locale))) != + (l2 = towlower_l(*s2++, locale))) { + /* XXX assumes wchar_t = int */ + return ((rune_t)l1 - (rune_t)l2); + } + if (l1 == 0) + break; + } while (--n != 0); + return (0); +} diff --git a/lib/libc/time/Makefile.inc b/lib/libc/time/Makefile.inc index f73cfbc9b56..28aada456e9 100644 --- a/lib/libc/time/Makefile.inc +++ b/lib/libc/time/Makefile.inc @@ -1,6 +1,7 @@ -# $OpenBSD: Makefile.inc,v 1.10 2016/03/30 06:38:42 jmc Exp $ +# $OpenBSD: Makefile.inc,v 1.11 2017/09/05 03:16:14 schwarze Exp $ .PATH: ${LIBCSRCDIR}/time -SRCS+= asctime.c difftime.c localtime.c strftime.c strptime.c wcsftime.c +SRCS+= asctime.c difftime.c localtime.c strftime.c strftime_l.c \ + strptime.c wcsftime.c MAN+= ctime.3 strftime.3 time2posix.3 tzfile.5 tzset.3 strptime.3 wcsftime.3 diff --git a/lib/libc/time/strftime.3 b/lib/libc/time/strftime.3 index 00ca41604ca..a02af262b15 100644 --- a/lib/libc/time/strftime.3 +++ b/lib/libc/time/strftime.3 @@ -1,3 +1,5 @@ +.\" $OpenBSD: strftime.3,v 1.37 2017/09/05 03:16:14 schwarze Exp $ +.\" .\" Copyright (c) 1989, 1991 The Regents of the University of California. .\" All rights reserved. .\" @@ -30,22 +32,33 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)strftime.3 5.12 (Berkeley) 6/29/91 -.\" $OpenBSD: strftime.3,v 1.36 2016/02/08 20:29:11 jmc Exp $ .\" -.Dd $Mdocdate: February 8 2016 $ +.Dd $Mdocdate: September 5 2017 $ .Dt STRFTIME 3 .Os .Sh NAME -.Nm strftime +.Nm strftime , +.Nm strftime_l .Nd format date and time .Sh SYNOPSIS .In time.h .Ft size_t -.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr" +.Fo strftime +.Fa "char *buf" +.Fa "size_t maxsize" +.Fa "const char *format" +.Fa "const struct tm *timeptr" +.Fc +.Ft size_t +.Fo strftime_l +.Fa "char *buf" +.Fa "size_t maxsize" +.Fa "const char *format" +.Fa "const struct tm *timeptr" +.Fa "locale_t locale" +.Fc .Sh DESCRIPTION -The -.Fn strftime -function formats the information from +These functions format the information from .Fa timeptr (as described in .Xr mktime 3 ) @@ -191,6 +204,13 @@ is replaced by the date and time in .Xr date 1 format. .El +.Pp +The +.Ox +implementation always uses the C locale and ignores +the global locale, the thread-specific locale, and the +.Fa locale +argument. .Sh RETURN VALUES If the total number of resulting characters, including the terminating NUL character, is not more than @@ -199,6 +219,12 @@ NUL character, is not more than returns the number of characters placed in the array, not counting the terminating NUL. Otherwise, zero is returned. +.Sh ENVIRONMENT +On other operating systems, the behaviour of +.Fn strftime +may depend on the +.Dv LC_TIME +.Xr locale 1 . .Sh SEE ALSO .Xr date 1 , .Xr printf 1 , @@ -215,6 +241,10 @@ The function conforms to .St -isoC-99 , +and +.Fn strftime_l +to +.St -p1003.1-2008 , except that the .Ql E and @@ -253,7 +283,11 @@ first appeared in The .Fn strftime function has been available since -.Bx 4.3 Reno . +.Bx 4.3 Reno , +and +.Fn strftime_l +since +.Ox 6.2 . .Sh AUTHORS .An Keith Bostic implemented the diff --git a/lib/libc/time/strftime_l.c b/lib/libc/time/strftime_l.c new file mode 100644 index 00000000000..4d3face1c95 --- /dev/null +++ b/lib/libc/time/strftime_l.c @@ -0,0 +1,14 @@ +/* $OpenBSD: strftime_l.c,v 1.1 2017/09/05 03:16:14 schwarze Exp $ */ +/* + * Written in 2017 by Ingo Schwarze <schwarze@openbsd.org>. + * Released into the public domain. + */ + +#include <time.h> + +size_t +strftime_l(char *s, size_t maxsize, const char *format, const struct tm *t, + locale_t locale __attribute__((__unused__))) +{ + return strftime(s, maxsize, format, t); +} diff --git a/lib/libcxx/include/support/newlib/xlocale.h b/lib/libcxx/include/support/newlib/xlocale.h index 323aa65bd70..04e41d40971 100644 --- a/lib/libcxx/include/support/newlib/xlocale.h +++ b/lib/libcxx/include/support/newlib/xlocale.h @@ -16,8 +16,10 @@ #include <clocale> #include <cwctype> #include <ctype.h> +#ifndef __OpenBSD__ #include <support/xlocale/__nop_locale_mgmt.h> #include <support/xlocale/__posix_l_fallback.h> +#endif #include <support/xlocale/__strtonum_fallback.h> #endif // _NEWLIB_VERSION diff --git a/lib/libcxx/shlib_version b/lib/libcxx/shlib_version index 97c9f92d6b8..1edea46de91 100644 --- a/lib/libcxx/shlib_version +++ b/lib/libcxx/shlib_version @@ -1,2 +1,2 @@ -major=0 +major=1 minor=0 |