sync code with last improvements from OpenBSD

This commit is contained in:
purplerain 2023-08-21 03:05:03 +00:00
parent cb9f36df51
commit 6b5b190599
Signed by: purplerain
GPG Key ID: F42C07F07E2E35B7
48 changed files with 1492 additions and 422 deletions

View File

@ -89,7 +89,7 @@ wr_start(void)
if (!wrblksz)
wrblksz = frmt->bsz;
if (wrblksz > MAXBLK) {
paxwarn(1, "Write block size of %d too large, maximium is: %d",
paxwarn(1, "Write block size of %d too large, maximum is: %d",
wrblksz, MAXBLK);
return(-1);
}
@ -134,7 +134,7 @@ rd_start(void)
buf = &(bufmem[BLKMULT]);
if ((act == APPND) && wrblksz) {
if (wrblksz > MAXBLK) {
paxwarn(1,"Write block size %d too large, maximium is: %d",
paxwarn(1,"Write block size %d too large, maximum is: %d",
wrblksz, MAXBLK);
return(-1);
}

View File

@ -734,7 +734,7 @@
./usr/lib/crtendS.o
./usr/lib/gcrt0.o
./usr/lib/libagentx.so.1.1
./usr/lib/libc.so.97.0
./usr/lib/libc.so.97.1
./usr/lib/libcbor.so.2.0
./usr/lib/libcrypto.so.52.0
./usr/lib/libcurses.so.14.0
@ -759,7 +759,7 @@
./usr/lib/libpanelw.so.6.0
./usr/lib/libpcap.so.9.0
./usr/lib/libperl.so.23.0
./usr/lib/libpthread.so.27.0
./usr/lib/libpthread.so.27.1
./usr/lib/libradius.so.1.0
./usr/lib/libreadline.so.4.0
./usr/lib/librpcsvc.so.3.0
@ -2999,7 +2999,7 @@
./usr/share/relink/kernel.tgz
./usr/share/relink/usr
./usr/share/relink/usr/lib
./usr/share/relink/usr/lib/libc.so.97.0.a
./usr/share/relink/usr/lib/libc.so.97.1.a
./usr/share/relink/usr/lib/libcrypto.so.52.0.a
./usr/share/relink/usr/libexec
./usr/share/relink/usr/libexec/ld.so.a

View File

@ -1435,6 +1435,7 @@
./usr/include/time.h
./usr/include/tls.h
./usr/include/ttyent.h
./usr/include/uchar.h
./usr/include/ufs
./usr/include/ufs/ext2fs
./usr/include/ufs/ext2fs/ext2fs.h
@ -2295,6 +2296,7 @@
./usr/share/man/man3/btowc.3
./usr/share/man/man3/btree.3
./usr/share/man/man3/bzero.3
./usr/share/man/man3/c16rtomb.3
./usr/share/man/man3/cacos.3
./usr/share/man/man3/cacosh.3
./usr/share/man/man3/carg.3
@ -2715,6 +2717,7 @@
./usr/share/man/man3/malloc.3
./usr/share/man/man3/mblen.3
./usr/share/man/man3/mbrlen.3
./usr/share/man/man3/mbrtoc16.3
./usr/share/man/man3/mbrtowc.3
./usr/share/man/man3/mbsinit.3
./usr/share/man/man3/mbsrtowcs.3

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.230 2022/08/30 18:50:06 krw Exp $
# $OpenBSD: Makefile,v 1.231 2023/08/20 15:02:50 schwarze Exp $
# $NetBSD: Makefile,v 1.59 1996/05/15 21:36:43 jtc Exp $
# @(#)Makefile 5.45.1.1 (Berkeley) 5/6/91
@ -27,7 +27,7 @@ FILES= a.out.h ar.h asr.h assert.h \
signal.h siphash.h sndio.h spawn.h stdbool.h stddef.h \
stdio.h stdlib.h string.h strings.h sysexits.h \
tar.h tgmath.h tib.h time.h ttyent.h \
unistd.h utime.h utmp.h uuid.h \
uchar.h unistd.h utime.h utmp.h uuid.h \
vis.h \
wchar.h wctype.h

38
include/uchar.h Normal file
View File

@ -0,0 +1,38 @@
/* $OpenBSD: uchar.h,v 1.1 2023/08/20 15:02:50 schwarze Exp $ */
/*
* Written by Ingo Schwarze <schwarze@openbsd.org>
* and placed in the public domain on March 19, 2022.
*/
#ifndef _UCHAR_H_
#define _UCHAR_H_
#include <sys/cdefs.h>
#include <sys/_types.h>
#ifndef _MBSTATE_T_DEFINED_
#define _MBSTATE_T_DEFINED_
typedef __mbstate_t mbstate_t;
#endif
#ifndef _SIZE_T_DEFINED_
#define _SIZE_T_DEFINED_
typedef __size_t size_t;
#endif
#define __STDC_UTF_16__ 1
#define __STDC_UTF_32__ 1
typedef __uint16_t char16_t;
typedef __uint32_t char32_t;
__BEGIN_DECLS
size_t mbrtoc16(char16_t * __restrict, const char * __restrict, size_t,
mbstate_t * __restrict);
size_t c16rtomb(char * __restrict, char16_t, mbstate_t * __restrict);
size_t mbrtoc32(char32_t * __restrict, const char * __restrict, size_t,
mbstate_t * __restrict);
size_t c32rtomb(char * __restrict, char32_t, mbstate_t * __restrict);
__END_DECLS
#endif /* !_UCHAR_H_ */

View File

@ -121,6 +121,7 @@ _thread_sys_issetugid
_thread_sys_kevent
_thread_sys_kill
_thread_sys_kqueue
_thread_sys_kqueue1
_thread_sys_ktrace
_thread_sys_lchown
_thread_sys_link
@ -322,6 +323,7 @@ issetugid
kevent
kill
kqueue
kqueue1
ktrace
lchown
link
@ -958,6 +960,8 @@ SipHash_Update
/* locale */
__mb_cur_max
btowc
c16rtomb
c32rtomb
duplocale
freelocale
isalnum_l
@ -1007,6 +1011,8 @@ mbsnrtowcs
mbsrtowcs
mbstowcs
newlocale
mbrtoc16
mbrtoc32
mbtowc
nl_langinfo
nl_langinfo_l

View File

@ -1,4 +1,4 @@
/* $OpenBSD: event.h,v 1.1 2023/05/18 16:11:09 guenther Exp $ */
/* $OpenBSD: event.h,v 1.2 2023/08/20 15:17:53 visa Exp $ */
/*
* Copyright (c) 2023 Philip Guenther <guenther@openbsd.org>
*
@ -22,5 +22,6 @@
PROTO_NORMAL(kevent);
PROTO_NORMAL(kqueue);
PROTO_NORMAL(kqueue1);
#endif /* !_LIBC_SYS_EVENT_H_ */

17
lib/libc/hidden/uchar.h Normal file
View File

@ -0,0 +1,17 @@
/* $OpenBSD: uchar.h,v 1.1 2023/08/20 15:02:51 schwarze Exp $ */
/*
* Written by Ingo Schwarze <schwarze@openbsd.org>
* and placed in the public domain on March 19, 2022.
*/
#ifndef _LIBC_UCHAR_H_
#define _LIBC_UCHAR_H_
#include_next <uchar.h>
PROTO_STD_DEPRECATED(c16rtomb);
PROTO_STD_DEPRECATED(c32rtomb);
PROTO_STD_DEPRECATED(mbrtoc16);
PROTO_STD_DEPRECATED(mbrtoc32);
#endif /* !_LIBC_UCHAR_H_ */

View File

@ -1,14 +1,15 @@
# $OpenBSD: Makefile.inc,v 1.26 2022/07/27 20:00:11 guenther Exp $
# $OpenBSD: Makefile.inc,v 1.27 2023/08/20 15:02:51 schwarze Exp $
# locale sources
.PATH: ${LIBCSRCDIR}/locale
SRCS+= btowc.c _def_messages.c _def_monetary.c _def_numeric.c _def_time.c \
SRCS+= _def_messages.c _def_monetary.c _def_numeric.c _def_time.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 wctype.c \
mblen.c mbrlen.c mbstowcs.c mbtowc.c multibyte_citrus.c wcscoll.c \
mblen.c mbrlen.c mbrtoc16.c mbrtoc32.c mbstowcs.c mbtowc.c \
btowc.c c16rtomb.c c32rtomb.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 \
@ -17,7 +18,8 @@ SRCS+= btowc.c _def_messages.c _def_monetary.c _def_numeric.c _def_time.c \
MAN+= nl_langinfo.3 setlocale.3 newlocale.3 uselocale.3 localeconv.3 \
iswalnum.3 towlower.3 \
btowc.3 mblen.3 mbrlen.3 mbrtowc.3 mbsinit.3 mbsrtowcs.3 \
btowc.3 c16rtomb.3 mblen.3 mbrlen.3 mbrtoc16.3 mbrtowc.3 \
mbsinit.3 mbsrtowcs.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

207
lib/libc/locale/c16rtomb.3 Normal file
View File

@ -0,0 +1,207 @@
.\" $OpenBSD: c16rtomb.3,v 1.1 2023/08/20 15:02:51 schwarze Exp $
.\"
.\" Copyright (c) 2023 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: August 20 2023 $
.Dt C16RTOMB 3
.Os
.Sh NAME
.Nm c16rtomb
.Nd convert one UTF-16 encoded character to UTF-8
.Sh SYNOPSIS
.In uchar.h
.Ft size_t
.Fo c16rtomb
.Fa "char * restrict s"
.Fa "char16_t c16"
.Fa "mbstate_t * restrict mbs"
.Fc
.Sh DESCRIPTION
This function converts one UTF-16 encoded character to UTF-8.
In some cases, it is necessary to call the function twice
to convert a single character.
.Pp
First, call
.Fn c16rtomb
passing the first 16-bit code unit of the UTF-16 encoded character in
.Fa c16 .
If the return value is greater than 0, the character is part of the UCS-2
range, the complete UTF-8 encoding consisting of at most
.Dv MB_CUR_MAX
bytes has been written to the storage starting at
.Fa s ,
and the function does not need to be called again.
.Pp
If the return value is 0, the first 16-bit code unit is a UTF-16
high surrogate and the function needs to be called a second time,
this time passing the second 16-bit code unit of the UTF-16 encoded
character in
.Fa c16
and passing the same
.Fa mbs
again that was also passed to the first call.
If the second 16-bit code unit is a UTF-16 low surrogate,
the second call returns a value greater than 0,
the surrogate pair represents a Unicode code point
beyond the basic multilingual plane,
and the complete UTF-8 encoding consisting of at most
.Dv MB_CUR_MAX
bytes is written to the storage starting at
.Fa s .
.Pp
The output encoding that
.Fn c16rtomb
uses in
.Fa s
is determined by the
.Dv LC_CTYPE
category of the current locale.
.Ox
only supports UTF-8 and ASCII output,
and this function is only useful for UTF-8.
.Pp
The following arguments cause special processing:
.Bl -tag -width 012345678901
.It Fa c16 No == 0
A NUL byte is stored to
.Pf * Fa s
and the state object pointed to by
.Fa mbs
is reset to the initial state.
On operating systems other than
.Ox
that support state-dependent multibyte encodings,
a special byte sequence
.Pq Dq shift sequence
is written before the NUL byte to return to the initial state
if that is required by the output encoding
and by the current output encoding state.
.It Fa mbs No == Dv NULL
An internal
.Vt mbstate_t
object specific to the
.Fn c16rtomb
function is used instead of the
.Fa mbs
argument.
This internal object is automatically initialized at program startup
and never changed by any
.Em libc
function except
.Fn c16rtomb .
.It Fa s No == Dv NULL
The object pointed to by
.Fa mbs ,
or the internal object if
.Fa mbs
is a
.Dv NULL
pointer, is reset to its initial state,
.Fa c16
is ignored, and 1 is returned.
.El
.Sh RETURN VALUES
.Fn c16rtomb
returns the number of bytes written to
.Fa s
on success or
.Po Vt size_t Pc Ns \-1
on failure, specifically:
.Bl -tag -width 10n
.It 0
The first 16-bit code unit was successfully decoded
as a UTF-16 high surrogate.
Nothing was written to
.Fa s
yet.
.It 1
The first 16-bit code unit was successfully decoded
as a character in the range U+0000 to U+007F, or
.Fa s
is
.Dv NULL .
.It 2
The first 16-bit code unit was successfully decoded
as a character in the range U+0080 to U+07FF.
.It 3
The first 16-bit code unit was successfully decoded
as a character in the range U+0800 to U+D7FF or U+E000 to U+FFFF.
.It 4
The second 16-bit code unit was successfully decoded as a UTF-16 low
surrogate, resulting in a character in the range U+10000 to U+10FFFF.
.It greater
Return values greater than 4 may occur on operating systems other than
.Ox
for output encodings other than UTF-8, in particular when a shift
sequence was written.
.It Po Vt size_t Pc Ns \-1
UTF-16 input decoding or
.Dv LC_CTYPE
output encoding failed, or
.Fa mbs
is invalid.
Nothing was written to
.Fa s ,
and
.Va errno
has been set.
.El
.Sh ERRORS
.Fn c16rtomb
causes an error in the following cases:
.Bl -tag -width Er
.It Bq Er EILSEQ
UTF-16 input decoding failed because the first 16-bit code unit
is neither a UCS-2 character nor a UTF-16 high surrogate,
or because the second 16-bit code unit is not a UTF-16 low surrogate;
or output encoding failed because the resulting character
cannot be represented in the output encoding selected with
.Dv LC_CTYPE .
.It Bq Er EINVAL
.Fa mbs
points to an invalid or uninitialized
.Vt mbstate_t
object.
.El
.Sh SEE ALSO
.Xr mbrtoc16 3 ,
.Xr setlocale 3 ,
.Xr wcrtomb 3
.Sh STANDARDS
.Fn c16rtomb
conforms to
.St -isoC-2011 .
.Sh HISTORY
.Fn c16rtomb
has been available since
.Ox 7.4 .
.Sh CAVEATS
The C11 standard only requires the
.Fa c16
argument to be interpreted according to UTF-16
if the predefined environment macro
.Dv __STDC_UTF_16__
is defined with a value of 1.
On
.Ox ,
.In uchar.h
provides this definition.
Other operating systems which do not define
.Dv __STDC_UTF_16__
could theoretically use a different,
implementation-defined input encoding for
.Fa c16
instead of UTF-16.
Using UTF-16 becomes mandatory in C23.

100
lib/libc/locale/c16rtomb.c Normal file
View File

@ -0,0 +1,100 @@
/* $OpenBSD: c16rtomb.c,v 1.1 2023/08/20 15:02:51 schwarze Exp $ */
/*
* Copyright (c) 2022 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 <uchar.h>
#include <wchar.h>
/*
* Keep this structure compatible with
* struct _utf8_state in the file citrus/citrus_utf8.c.
*/
struct _utf16_state {
wchar_t ch;
int want;
};
size_t
c16rtomb(char *s, char16_t c16, mbstate_t *ps)
{
static mbstate_t mbs;
struct _utf16_state *us;
wchar_t wc;
if (ps == NULL)
ps = &mbs;
/*
* Handle the special case of NULL output first
* to avoid inspecting c16 and ps and possibly drawing
* bogus conclusions from whatever those may contain.
* Instead, just restore the initial conversion state.
* The return value represents the length of the NUL byte
* corresponding to the NUL wide character, even though
* there is no place to write that NUL byte to.
*/
if (s == NULL) {
memset(ps, 0, sizeof(*ps));
return 1;
}
us = (struct _utf16_state *)ps;
if (us->want == (size_t)-3) {
/*
* The previous call read a high surrogate,
* so expect a low surrogate now.
*/
if ((c16 & 0xfc00) != 0xdc00) {
errno = EILSEQ;
return -1;
}
/*
* Assemble the full code point for processing
* by wcrtomb(3). Since we do not support
* state-dependent encodings, our wcrtomb(3)
* always expects the initial conversion state,
* so clearing the state here is just fine.
*/
wc = us->ch + (c16 & 0x3ff);
us->ch = 0;
us->want = 0;
} else if ((c16 & 0xfc00) == 0xd800) {
/*
* Got a high surrogate while being in the initial
* conversion state. Remeber its contribution to
* the codepoint and defer encoding to the next call.
*/
us->ch = 0x10000 + ((c16 & 0x3ff) << 10);
us->want = -3;
/* Nothing was written to *s just yet. */
return 0;
} else
wc = c16;
/*
* The following correctly returns an error when a low
* surrogate is encountered without a preceding high one.
*/
return wcrtomb(s, wc, ps);
}

View File

@ -0,0 +1,18 @@
/* $OpenBSD: c32rtomb.c,v 1.1 2023/08/20 15:02:51 schwarze Exp $ */
/*
* Written by Ingo Schwarze <schwarze@openbsd.org>
* and placed in the public domain on March 19, 2022.
*/
#include <uchar.h>
#include <wchar.h>
size_t
c32rtomb(char *s, char32_t c32, mbstate_t *ps)
{
static mbstate_t mbs;
if (ps == NULL)
ps = &mbs;
return wcrtomb(s, c32, ps);
}

265
lib/libc/locale/mbrtoc16.3 Normal file
View File

@ -0,0 +1,265 @@
.\" $OpenBSD: mbrtoc16.3,v 1.1 2023/08/20 15:02:51 schwarze Exp $
.\"
.\" Copyright 2023 Ingo Schwarze <schwarze@openbsd.org>
.\" Copyright 2010 Stefan Sperling <stsp@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: August 20 2023 $
.Dt MBRTOC16 3
.Os
.Sh NAME
.Nm mbrtoc16
.Nd convert one UTF-8 encoded character to UTF-16
.Sh SYNOPSIS
.In uchar.h
.Ft size_t
.Fo mbrtoc16
.Fa "char16_t * restrict pc16"
.Fa "const char * restrict s"
.Fa "size_t n"
.Fa "mbstate_t * restrict mbs"
.Fc
.Sh DESCRIPTION
The
.Fn mbrtoc16
function examines at most
.Fa n
bytes of the multibyte character byte string pointed to by
.Fa s ,
converts those bytes to a wide character,
and encodes the wide character using UTF-16.
In some cases, it is necessary to call this function
twice to convert a single character.
.Pp
Conversion happens in accordance with the conversion state
.Pf * Fa mbs ,
which must be initialized to zero before the application's first call to
.Fn mbrtoc16 .
For this function,
.Pf * Fa mbs
stores information about both the state of the UTF-8 input encoding
and the state of the UTF-16 output encoding.
If the previous call did not return
.Po Vt size_t Pc Ns \-1 ,
.Fa mbs
can safely be reused without reinitialization.
.Pp
The input encoding that
.Fn mbrtoc16
uses for
.Fa s
is determined by the
.Dv LC_CTYPE
category of the current locale.
If the locale is changed without reinitialization of
.Pf * Fa mbs ,
the behaviour is undefined.
.Pp
Unlike
.Xr mbtowc 3 ,
.Fn mbrtoc16
accepts an incomplete byte sequence pointed to by
.Fa s
which does not form a complete character but is potentially part of
a valid character.
In this case, the function consumes all such bytes.
The conversion state saved in
.Pf * Fa mbs
will be used to restart the suspended conversion during the next call.
.Pp
On systems other than
.Ox
that support state-dependent encodings,
.Fa s
may point to a special sequence of bytes called a
.Dq shift sequence ;
see
.Xr mbrtowc 3
for details.
.Pp
The following arguments cause special processing:
.Bl -tag -width 012345678901
.It Fa pc16 No == Dv NULL
The conversion from a multibyte character to a wide character is performed
and the conversion state may be affected, but the resulting wide character
is discarded.
.It Fa s No == Dv NULL
The arguments
.Fa pc16
and
.Fa n
are ignored and starting or continuing the conversion with an empty string
is attempted, discarding the conversion result.
.It Fa mbs No == Dv NULL
An internal
.Vt mbstate_t
object specific to the
.Fn mbrtoc16
function is used instead of the
.Fa mbs
argument.
This internal object is automatically initialized at program startup
and never changed by any
.Em libc
function except
.Fn mbrtoc16 .
.Pp
If
.Fn mbrtoc16
is called with a
.Dv NULL
.Fa mbs
argument and that call returns
.Po Vt size_t Pc Ns \-1 ,
the internal conversion state of
.Fn mbrtoc16
becomes permanently undefined and there is no way
to reset it to any defined state.
Consequently, after such a mishap, it is not safe to call
.Fn mbrtoc16
with a
.Dv NULL
.Fa mbs
argument ever again until the program is terminated.
.El
.Sh RETURN VALUES
.Bl -tag -width 012345678901
.It 0
The bytes pointed to by
.Fa s
form a terminating NUL character.
If
.Fa pc16
is not
.Dv NULL ,
a NUL wide character has been stored in
.Pf * Fa pc16 .
.It positive
.Fa s
points to a valid character, and the value returned is the number of
bytes completing the character.
If
.Fa pc16
is not
.Dv NULL ,
the first UTF-16 code unit of the corresponding wide character
has been stored in
.Pf * Fa pc16 .
If it is an UTF-16 high surrogate, the function needs to be called
again to retrieve a second UTF-16 code unit, the low surrogate.
On
.Ox ,
this happens if and only if the return value is 4,
but this equivalence does not hold on other operating systems
that support input encodings other than UTF-8.
.It Po Vt size_t Pc Ns \-1
.Fa s
points to an illegal byte sequence which does not form a valid multibyte
character in the current locale, or
.Fa mbs
points to an invalid or uninitialized object.
.Va errno
is set to
.Er EILSEQ
or
.Er EINVAL ,
respectively.
The conversion state object pointed to by
.Fa mbs
is left in an undefined state and must be reinitialized before being
used again.
.It Po Vt size_t Pc Ns \-2
.Fa s
points to an incomplete byte sequence of length
.Fa n
which has been consumed and contains part of a valid multibyte character.
The character may be completed by calling the same function again with
.Fa s
pointing to one or more subsequent bytes of the multibyte character and
.Fa mbs
pointing to the conversion state object used during conversion of the
incomplete byte sequence.
.It Po Vt size_t Pc Ns \-3
The second 16-bit code unit resulting from a previous call
has been stored into
.Pf * Fa pc16 ,
without consuming any additional bytes from
.Fa s .
.El
.Sh ERRORS
.Fn mbrtoc16
causes an error in the following cases:
.Bl -tag -width Er
.It Bq Er EILSEQ
.Fa s
points to an invalid multibyte character.
.It Bq Er EINVAL
.Fa mbs
points to an invalid or uninitialized
.Vt mbstate_t
object.
.El
.Sh SEE ALSO
.Xr c16rtomb 3 ,
.Xr mbrtowc 3 ,
.Xr setlocale 3
.Sh STANDARDS
.Fn mbrtoc16
conforms to
.St -isoC-2011 .
.Sh HISTORY
.Fn mbrtoc16
has been available since
.Ox 7.4 .
.Sh CAVEATS
On operating systems other than
.Ox
that support input encodings other than UTF-8, inspecting the return value
is insufficient to tell whether the function needs to be called again.
If the return value is positive, inspecting
.Pf * Fa pc16
is also required to make that decision.
Consequently, passing a
.Dv NULL
pointer for the
.Fa pc16
argument is discouraged because it can result
in a well-defined but unknown output encoding state.
The simplest way to recover from such an unknown state is to
reinitialize the object pointed to by
.Fa mbs .
.Pp
The C11 standard only requires the
.Fa pc16
argument to be encoded according to UTF-16
if the predefined environment macro
.Dv __STDC_UTF_16__
is defined with a value of 1.
On
.Ox ,
.In uchar.h
provides this definition.
Other operating systems which do not define
.Dv __STDC_UTF_16__
could theoretically use a different,
implementation-defined output encoding for
.Fa pc16
instead of UTF-16.
Writing portable code for an arbitrary output encoding is impossible
because the rules when and how often the function needs to be called
again depend on the output encoding; the rules explained above are
specific to UTF-16.
Using UTF-16 as the output encoding of
.Fn wcrtoc16
becomes mandatory in C23.

102
lib/libc/locale/mbrtoc16.c Normal file
View File

@ -0,0 +1,102 @@
/* $OpenBSD: mbrtoc16.c,v 1.1 2023/08/20 15:02:51 schwarze Exp $ */
/*
* Copyright (c) 2022 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 <stdint.h>
#include <uchar.h>
#include <wchar.h>
/*
* Keep this structure compatible with
* struct _utf8_state in the file citrus/citrus_utf8.c.
* In particular, only use values for the "want" field
* that do not collide with values used by the function
* _citrus_utf8_ctype_mbrtowc().
*/
struct _utf16_state {
wchar_t ch;
int want;
};
size_t
mbrtoc16(char16_t *pc16, const char *s, size_t n, mbstate_t *ps)
{
static mbstate_t mbs;
struct _utf16_state *us;
size_t rv;
wchar_t wc;
/*
* Fall back to a state object local to this function
* and do not use the fallback object in mbrtowc(3)
* because an application program might mix calls to mbrtowc(3)
* and mbrtoc16(3) decoding different strings, and they must
* not clobber each other's state.
*/
if (ps == NULL)
ps = &mbs;
us = (struct _utf16_state *)ps;
/*
* Handle the special case of NULL input first such that
* a low surrogate left over from a previous call does not
* clobber an object pointed to by the pc16 argument.
*/
if (s == NULL) {
s = "";
n = 1;
pc16 = NULL;
}
/*
* If the previous call stored a high surrogate,
* store the corresponding low surrogate now
* and do not inspect any further input yet.
*/
if (us->want == (size_t)-3) {
if (pc16 != NULL)
*pc16 = 0xdc00 + (us->ch & 0x3ff);
us->ch = 0;
us->want = 0;
return -3;
}
/*
* Decode the multibyte character.
* All the mbrtowc(3) use cases can be reached from here,
* including continuing an imcomplete character started earlier,
* decoding a NUL character, a valid complete character,
* an incomplete character to be continued later,
* or a decoding error.
*/
rv = mbrtowc(&wc, s, n, ps);
if (rv < (size_t)-2) {
/* A new character that is valid and complete. */
if (wc > UINT16_MAX) {
/* Store a high surrogate. */
if (pc16 != NULL)
*pc16 = 0xd7c0 + (wc >> 10);
/* Remember that the low surrogate is pending. */
us->ch = wc;
us->want = -3;
} else if (pc16 != NULL)
/* Store a basic multilingual plane codepoint. */
*pc16 = wc;
}
return rv;
}

View File

@ -0,0 +1,18 @@
/* $OpenBSD: mbrtoc32.c,v 1.1 2023/08/20 15:02:51 schwarze Exp $ */
/*
* Written by Ingo Schwarze <schwarze@openbsd.org>
* and placed in the public domain on March 19, 2022.
*/
#include <uchar.h>
#include <wchar.h>
size_t
mbrtoc32(char32_t *pc32, const char *s, size_t n, mbstate_t *ps)
{
static mbstate_t mbs;
if (ps == NULL)
ps = &mbs;
return mbrtowc(pc32, s, n, ps);
}

View File

@ -1,6 +1,8 @@
.\" $OpenBSD: mbrtowc.3,v 1.5 2016/02/08 09:56:16 schwarze Exp $
.\" $OpenBSD: mbrtowc.3,v 1.6 2023/08/20 15:02:51 schwarze Exp $
.\" $NetBSD: mbrtowc.3,v 1.5 2003/09/08 17:54:31 wiz Exp $
.\"
.\" Copyright (c)2023 Ingo Schwarze <schwarze@openbsd.org>
.\" Copyright (c)2010 Stefan Sperling <stsp@openbsd.org>
.\" Copyright (c)2002 Citrus Project,
.\" All rights reserved.
.\"
@ -25,27 +27,41 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd $Mdocdate: February 8 2016 $
.Dd $Mdocdate: August 20 2023 $
.Dt MBRTOWC 3
.Os
.Sh NAME
.Nm mbrtowc
.Nd converts a multibyte character to a wide character (restartable)
.Nm mbrtowc ,
.Nm mbrtoc32
.Nd convert a multibyte character to a wide character (restartable)
.Sh SYNOPSIS
.In wchar.h
.Ft size_t
.Fn mbrtowc "wchar_t * restrict wc" "const char * restrict s" "size_t n" \
"mbstate_t * restrict mbs"
.Fo mbrtowc
.Fa "wchar_t * restrict wc"
.Fa "const char * restrict s"
.Fa "size_t n"
.Fa "mbstate_t * restrict mbs"
.Fc
.In uchar.h
.Ft size_t
.Fo mbrtoc32
.Fa "char32_t * restrict wc"
.Fa "const char * restrict s"
.Fa "size_t n"
.Fa "mbstate_t * restrict mbs"
.Fc
.Sh DESCRIPTION
The
.Fn mbrtowc
function examines at most
and
.Fn mbrtoc32
functions examine at most
.Fa n
bytes of the multibyte character byte string pointed to by
.Fa s ,
converts those bytes to a wide character, and stores the wide character
in the wchar_t object pointed to by
.Fa wc
convert those bytes to a wide character, and store the wide character into
.Pf * Fa wc
if
.Fa wc
is not
@ -54,46 +70,47 @@ and
.Fa s
points to a valid character.
.Pp
Conversion happens in accordance with the conversion state described
by the mbstate_t object pointed to by
.Fa mbs .
The mbstate_t object must be initialized to zero before the application's
first call to
.Fn mbrtowc .
If the previous call to
Conversion happens in accordance with the conversion state
.Pf * Fa mbs ,
which must be initialized to zero before the application's first call to
.Fn mbrtowc
did not return (size_t)-1, the mbstate_t object can safely be reused
without reinitialization.
or
.Fn mbrtoc32 .
If the previous call did not return
.Po Vt size_t Pc Ns \-1 ,
.Fa mbs
can safely be reused without reinitialization.
.Pp
The behaviour of
The input encoding that
.Fn mbrtowc
is affected by the
and
.Fn mbrtoc32
use for
.Fa s
is determined by the
.Dv LC_CTYPE
category of the current locale.
If the locale is changed without reinitialization of the mbstate_t object
pointed to by
.Fa mbs ,
the behaviour of
.Fn mbrtowc
is undefined.
If the locale is changed without reinitialization of
.Pf * Fa mbs ,
the behaviour is undefined.
.Pp
Unlike
.Xr mbtowc 3 ,
.Fn mbrtowc
will accept an incomplete byte sequence pointed to by
and
.Fn mbrtoc32
accept an incomplete byte sequence pointed to by
.Fa s
which does not form a complete character but is potentially part of
a valid character.
In this case,
.Fn mbrtowc
consumes all such bytes.
The conversion state saved in the mbstate_t object pointed to by
.Fa mbs
will be used to restart the suspended conversion during the next
call to
.Fn mbrtowc .
In this case, both functions consume all such bytes.
The conversion state saved in
.Pf * Fa mbs
will be used to restart the suspended conversion during the next call.
.Pp
In state-dependent encodings,
On systems other than
.Ox
that support state-dependent encodings,
.Fa s
may point to a special sequence of bytes called a
.Dq shift sequence .
@ -104,61 +121,58 @@ can switch e.g. from ASCII (which uses one byte per character) to
JIS X 0208 (which uses two bytes per character).
Shift sequence bytes correspond to no individual wide character, so
.Fn mbrtowc
treats them as if they were part of the subsequent multibyte character.
and
.Fn mbrtoc32
treat them as if they were part of the subsequent multibyte character.
Therefore they do contribute to the number of bytes in the multibyte character.
.Pp
Special cases in interpretation of arguments are as follows:
The following arguments cause special processing:
.Bl -tag -width 012345678901
.It "wc == NULL "
.It Fa wc No == Dv NULL
The conversion from a multibyte character to a wide character is performed
and the conversion state may be affected, but the resulting wide character
is discarded.
.Pp
This can be used to find out how many bytes are contained in the
multibyte character pointed to by
.Fa s .
.It "s == NULL "
.Fn mbrtowc
ignores
.It Fa s No == Dv NULL
The arguments
.Fa wc
and
.Fa n ,
and behaves equivalent to
.Bd -literal -offset indent
mbrtowc(NULL, "", 1, mbs);
.Ed
.Pp
which attempts to use the mbstate_t object pointed to by
.Fa mbs
to start or continue conversion using the empty string as input,
and discards the conversion result.
.Pp
.Fa n
are ignored and starting or continuing the conversion with an empty string
is attempted, discarding the conversion result.
If conversion succeeds, this call always returns zero.
Unlike
.Xr mbtowc 3 ,
the value returned does not indicate whether the current encoding of
the locale is state-dependent, i.e. uses shift sequences.
.It "mbs == NULL "
.It Fa mbs No == Dv NULL
.Fn mbrtowc
uses its own internal state object to keep the conversion state,
instead of an mbstate_t object pointed to by
.Fa mbs .
This internal conversion state is initialized once at program startup.
It is not safe to call
and
.Fn mbrtoc32
each use their own internal state object instead of the
.Fa mbs
argument.
Both internal state objects are initialized at startup time of the program,
and no other libc function ever changes either of them.
.Pp
If
.Fn mbrtowc
again with a
or
.Fn mbrtoc32
is called with a
.Dv NULL
.Fa mbs
argument if
.Fn mbrtowc
returned (size_t)-1 because at this point the internal conversion state
is undefined.
.Pp
Calling any other functions in
.Em libc
never changes the internal
conversion state object of
.Fn mbrtowc .
argument and that call returns
.Po Vt size_t Pc Ns \-1 ,
the internal conversion state of the respective function becomes
permanently undefined and there is no way to reset it to any defined state.
Consequently, after such a mishap, it is not safe
to call the same function with a
.Dv NULL
.Fa mbs
argument ever again until the program is terminated.
.El
.Sh RETURN VALUES
.Bl -tag -width 012345678901
@ -183,14 +197,18 @@ is not
the corresponding wide character has been stored in the wchar_t object
pointed to by
.Fa wc .
.It (size_t)-1
.It Po Vt size_t Pc Ns \-1
.Fa s
points to an illegal byte sequence which does not form a valid multibyte
character in the current locale.
.Fn mbrtowc
sets
character in the current locale, or
.Fa mbs
points to an invalid or uninitialized object.
.Va errno
to EILSEQ.
is set to
.Er EILSEQ
or
.Er EINVAL ,
respectively.
The conversion state object pointed to by
.Fa mbs
is left in an undefined state and must be reinitialized before being
@ -198,6 +216,8 @@ used again.
.Pp
Because applications using
.Fn mbrtowc
or
.Fn mbrtoc32
are shielded from the specifics of the multibyte character encoding scheme,
it is impossible to repair byte sequences containing encoding errors.
Such byte sequences must be treated as invalid and potentially malicious input.
@ -205,66 +225,90 @@ Applications must stop processing the byte string pointed to by
.Fa s
and either discard any wide characters already converted, or cope with
truncated input.
.It (size_t)-2
.It Po Vt size_t Pc Ns \-2
.Fa s
points to an incomplete byte sequence of length
.Fa n
which has been consumed and contains part of a valid multibyte character.
The character may be completed by calling
.Fn mbrtowc
again with
The character may be completed by calling the same function again with
.Fa s
pointing to one or more subsequent bytes of the multibyte character and
.Fa mbs
pointing to the conversion state object used during conversion of the
incomplete byte sequence.
.It Po Vt size_t Pc Ns \-3
The next character resulting from a previous call has been stored into
.Fa wc ,
without consuming any additional bytes from
.Fa s .
This never happens for
.Fn mbrtowc ,
and on
.Ox ,
it never happens for
.Fn mbrtoc32
either.
.El
.Sh ERRORS
The
.Fn mbrtowc
function may cause an error in the following cases:
and
.Fn mbrtoc32
cause an error in the following cases:
.Bl -tag -width Er
.It Bq Er EILSEQ
.Fa s
points to an invalid multibyte character.
.It Bq Er EINVAL
.Fa mbs
points to an invalid or uninitialized mbstate_t object.
points to an invalid or uninitialized
.Vt mbstate_t
object.
.El
.Sh SEE ALSO
.Xr mbrlen 3 ,
.Xr mbtowc 3 ,
.Xr setlocale 3
.Xr setlocale 3 ,
.Xr wcrtomb 3
.Sh STANDARDS
The
.Fn mbrtowc
function conforms to
.\" .St -isoC-amd1 .
ISO/IEC 9899/AMD1:1995
.Pq Dq ISO C90, Amendment 1 .
The restrict qualifier is added at
.\" .St -isoC99 .
ISO/IEC 9899:1999
.Pq Dq ISO C99 .
conforms to
.St -isoC-amd1 .
The restrict qualifier was added at
.St -isoC-99 .
.Pp
.Fn mbrtoc32
conforms to
.St -isoC-2011 .
.Sh HISTORY
.Fn mbrtowc
has been available since since
.Ox 3.8
and has provided support for UTF-8 since
.Ox 4.8 .
.Pp
.Fn mbrtoc32
has been available since since
.Ox 7.4 .
.Sh CAVEATS
.Fn mbrtowc
is not suitable for programs that care about internals of the character
and
.Fn mbrtoc32
are not suitable for programs that care about internals of the character
encoding scheme used by the byte string pointed to by
.Fa s .
.Pp
It is possible that
.Fn mbrtowc
fails because of locale configuration errors.
It is possible that these functions
fail because of locale configuration errors.
An
.Dq invalid
character sequence may simply be encoded in a different encoding than that
of the current locale.
.Pp
The special cases for
.Fa s
== NULL and
.Fa mbs
== NULL do not make any sense.
.Fa s No == Dv NULL
and
.Fa mbs No == Dv NULL
do not make any sense.
Instead of passing
.Dv NULL
for

View File

@ -1,6 +1,7 @@
.\" $OpenBSD: wcrtomb.3,v 1.10 2015/03/22 18:02:11 stsp Exp $
.\" $OpenBSD: wcrtomb.3,v 1.11 2023/08/20 15:02:51 schwarze Exp $
.\" $NetBSD: wcrtomb.3,v 1.4 2003/09/08 17:54:31 wiz Exp $
.\"
.\" Copyright (c)2023 Ingo Schwarze <schwarze@openbsd.org>
.\" Copyright (c)2002 Citrus Project,
.\" All rights reserved.
.\"
@ -25,117 +26,161 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd $Mdocdate: March 22 2015 $
.Dd $Mdocdate: August 20 2023 $
.Dt WCRTOMB 3
.Os
.\" ----------------------------------------------------------------------
.Sh NAME
.Nm wcrtomb
.Nd converts a wide character to a multibyte character (restartable)
.\" ----------------------------------------------------------------------
.Nm wcrtomb ,
.Nm c32rtomb
.Nd convert a wide character to a multibyte character
.Sh SYNOPSIS
.In wchar.h
.Ft size_t
.Fn wcrtomb "const char * restrict s" "wchar_t wc" "mbstate_t * restrict ps"
.\" ----------------------------------------------------------------------
.Fo wcrtomb
.Fa "const char * restrict s"
.Fa "wchar_t wc"
.Fa "mbstate_t * restrict mbs"
.Fc
.In uchar.h
.Ft size_t
.Fo c32rtomb
.Fa "char * restrict s"
.Fa "char32_t wc"
.Fa "mbstate_t * restrict mbs"
.Fc
.Sh DESCRIPTION
.Fn wcrtomb
converts the wide character given by
and
.Fn c32rtomb
convert the wide character
.Fa wc
to the corresponding multibyte character, and stores up to
to the corresponding multibyte character, and store up to
.Dv MB_CUR_MAX
bytes in the array pointed to by
.Fa s
if
.Fa s
is not a null pointer.
is not a
.Dv NULL
pointer.
The interpretation of
.Fa wc
is implementation-defined.
On
.Ox ,
.Vt wchar_t
and
.Vt char32_t
are of the same width and both are always interpreted as Unicode codepoints.
.Pp
The behaviour of
The output encoding that
.Fn wcrtomb
is affected by the
and
.Fn c32rtomb
use in
.Fa s
is determined by the
.Dv LC_CTYPE
category of the current locale.
.Ox
only supports UTF-8 and ASCII output,
and these functions are only useful for UTF-8.
.Pp
These are the special cases:
The following arguments cause special processing:
.Bl -tag -width 012345678901
.It "wc == 0"
For state-dependent encodings,
.Fn wcrtomb
stores a null byte preceded by a special byte sequence (if any)
to return to an initial state to the array pointed by
.Fa s ,
and the state object pointed by
.Fa ps
also returned to an initial state.
.It "s == NULL"
.Fn wcrtomb
just places
.Fa ps
into an initial state.
It is equivalent to the following call:
.Bd -literal -offset indent
wcrtomb(buf, L'\e0', ps);
.Ed
.Pp
Here,
.Fa buf
is a dummy buffer.
In this case,
.Fa wc
is ignored.
.It "ps == NULL"
.It Fa wc No == 0
A NUL byte is stored to
.Pf * Fa s
and the state object pointed to by
.Fa mbs
is reset to the initial state.
On operating systems other than
.Ox
that support state-dependent multibyte encodings, a special byte sequence
.Pq Dq shift sequence
is written before the NUL byte to return to the initial state
if that is required by the output encoding
and by the current output encoding state.
.It Fa mbs No == Dv NULL
.Fn mbrtowc
uses its own internal state object to keep the conversion state,
instead of
.Fa ps
mentioned in this manual page.
.Pp
Calling any other functions in
and
.Fn c32rtomb
each use their own internal state object instead of the
.Fa mbs
argument.
Both internal state objects are initialized at startup time of the program,
and no other
.Em libc
never change the internal
state of
.Fn mbrtowc ,
which is initialized at startup time of the program.
function ever changes either of them.
.It Fa s No == Dv NULL
The object pointed to by
.Fa mbs ,
or the internal object if
.Fa mbs
is a
.Dv NULL
pointer, is reset to the initial state,
.Fa wc
is ignored, and 1 is returned.
.El
.\" ----------------------------------------------------------------------
.Sh RETURN VALUES
.Fn wcrtomb
returns the number of bytes (including any shift sequences)
and
.Fn c32rtomb
return the number of bytes (including any shift sequences)
which are stored in the array pointed to by
.Fa s .
.Fa s ,
or 1 if
.Fa s
is
.Dv NULL .
If
.Fa wc
is not a valid wide character,
.Fn wcrtomb
returns (size_t)-1
and sets
is not a valid wide character
or if it cannot be represented in the multibyte encoding selected with
.Dv LC_CTYPE ,
both functions return
.Po Vt size_t Pc Ns \-1
and set
.Va errno
to indicate error.
.\" ----------------------------------------------------------------------
to indicate the error.
.Sh ERRORS
.Fn wcrtomb
may cause an error in the following cases:
and
.Fn c32rtomb
cause an error in the following cases:
.Bl -tag -width Er
.It Bq Er EILSEQ
.Fa wc
is not a valid wide character.
is not a valid wide character or cannot be represented using
.Dv LC_CTYPE .
.It Bq Er EINVAL
.Fa ps
points to an invalid or uninitialized mbstate_t object.
.Fa mbs
points to an invalid or uninitialized
.Vt mbstate_t
object.
.El
.\" ----------------------------------------------------------------------
.Sh SEE ALSO
.Xr mbrtowc 3 ,
.Xr setlocale 3 ,
.Xr wctomb 3
.\" ----------------------------------------------------------------------
.Sh STANDARDS
The
.Fn wcrtomb
function conforms to
.\" .St -isoC-amd1 .
ISO/IEC 9899/AMD1:1995
.Pq Dq ISO C90, Amendment 1 .
The restrict qualifier is added at
.\" .St -isoC99 .
ISO/IEC 9899/1999
.Pq Dq ISO C99 .
conforms to
.St -isoC-amd1 .
The restrict qualifier was added at
.St -isoC-99 .
.Pp
.Fn c32rtomb
conforms to
.St -isoC-2011 .
.Sh HISTORY
.Fn wcrtomb
has been available since
.Ox 3.8
and has provided support for UTF-8 since
.Ox 4.8 .
.Pp
.Fn c32rtomb
has been available since since
.Ox 7.4 .

View File

@ -1,4 +1,4 @@
major=97
minor=0
minor=1
# note: If changes were made to include/thread_private.h or if system calls
# were added/changed then librthread/shlib_version must also be updated.

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile.inc,v 1.173 2023/02/27 14:59:33 deraadt Exp $
# $OpenBSD: Makefile.inc,v 1.174 2023/08/20 15:17:53 visa Exp $
# $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $
# @(#)Makefile.inc 8.1 (Berkeley) 6/17/93
@ -73,7 +73,7 @@ ASM= __semctl.o __thrsigdivert.o \
getpriority.o getresgid.o getresuid.o \
getrlimit.o getrusage.o getsid.o getsockname.o \
getsockopt.o ioctl.o \
kevent.o kill.o kqueue.o ktrace.o lchown.o \
kevent.o kill.o kqueue.o kqueue1.o ktrace.o lchown.o \
link.o linkat.o listen.o lseek.o lstat.o \
madvise.o mimmutable.o minherit.o mkdir.o mkdirat.o mkfifo.o mkfifoat.o \
mknod.o mknodat.o mlock.o mlockall.o mmap.o mount.o mprotect.o \

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: kqueue.2,v 1.49 2023/08/13 10:23:26 jmc Exp $
.\" $OpenBSD: kqueue.2,v 1.51 2023/08/20 19:52:40 jmc Exp $
.\"
.\" Copyright (c) 2000 Jonathan Lemon
.\" All rights reserved.
@ -26,11 +26,12 @@
.\"
.\" $FreeBSD: src/lib/libc/sys/kqueue.2,v 1.18 2001/02/14 08:48:35 guido Exp $
.\"
.Dd $Mdocdate: August 13 2023 $
.Dd $Mdocdate: August 20 2023 $
.Dt KQUEUE 2
.Os
.Sh NAME
.Nm kqueue ,
.Nm kqueue1 ,
.Nm kevent ,
.Nm EV_SET
.Nd kernel event notification mechanism
@ -43,6 +44,12 @@
.Ft int
.Fn kevent "int kq" "const struct kevent *changelist" "int nchanges" "struct kevent *eventlist" "int nevents" "const struct timespec *timeout"
.Fn EV_SET "&kev" ident filter flags fflags data udata
.In sys/types.h
.In sys/event.h
.In sys/time.h
.In fcntl.h
.Ft int
.Fn kqueue1 "int flags"
.Sh DESCRIPTION
.Fn kqueue
provides a generic method of notifying the user when an event
@ -78,6 +85,18 @@ The queue is not inherited by a child created with
.Xr fork 2 .
Similarly, kqueues cannot be passed across UNIX-domain sockets.
.Pp
The
.Fn kqueue1
function is identical to
.Fn kqueue
except that the close-on-exec flag on the new file descriptor
is determined by the
.Dv O_CLOEXEC
flag
in the
.Fa flags
argument.
.Pp
.Fn kevent
is used to register events with the queue, and return any pending
events to the user.
@ -545,7 +564,9 @@ contains the events which triggered the filter.
.El
.Sh RETURN VALUES
.Fn kqueue
creates a new kernel event queue and returns a file descriptor.
and
.Fn kqueue1
create a new kernel event queue and returns a file descriptor.
If there was an error creating the kernel event queue, a value of -1 is
returned and
.Va errno
@ -577,7 +598,9 @@ returns 0.
.Sh ERRORS
The
.Fn kqueue
function fails if:
and
.Fn kqueue1
functions fail if:
.Bl -tag -width Er
.It Bq Er ENOMEM
The kernel failed to allocate enough memory for the kernel queue.
@ -587,6 +610,15 @@ The per-process descriptor table is full.
The system file table is full.
.El
.Pp
In addition,
.Fn kqueue1
fails if:
.Bl -tag -width Er
.It Bq Er EINVAL
.Fa flags
is invalid.
.El
.Pp
The
.Fn kevent
function fails if:

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: pledge.2,v 1.66 2023/06/02 17:44:29 cheloha Exp $
.\" $OpenBSD: pledge.2,v 1.67 2023/08/20 15:17:53 visa Exp $
.\"
.\" Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
.\"
@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: June 2 2023 $
.Dd $Mdocdate: August 20 2023 $
.Dt PLEDGE 2
.Os
.Sh NAME
@ -198,6 +198,7 @@ As a result, all the expected functionalities of libc stdio work.
.Xr issetugid 2 ,
.Xr kevent 2 ,
.Xr kqueue 2 ,
.Xr kqueue1 2 ,
.Xr lseek 2 ,
.Xr madvise 2 ,
.Xr minherit 2 ,

View File

@ -1,2 +1,2 @@
major=27
minor=0
minor=1

View File

@ -1,8 +1,23 @@
ChangeLog file for zlib
Changes in 1.2.13.1 (xx Oct 2022)
-
Changes in 1.3 (18 Aug 2023)
- Remove K&R function definitions and zlib2ansi
- Fix bug in deflateBound() for level 0 and memLevel 9
- Fix bug when gzungetc() is used immediately after gzopen()
- Fix bug when using gzflush() with a very small buffer
- Fix crash when gzsetparams() attempted for transparent write
- Fix test/example.c to work with FORCE_STORED
- Rewrite of zran in examples (see zran.c version history)
- Fix minizip to allow it to open an empty zip file
- Fix reading disk number start on zip64 files in minizip
- Fix logic error in minizip argument processing
- Add minizip testing to Makefile
- Read multiple bytes instead of byte-by-byte in minizip unzip.c
- Add memory sanitizer to configure (--memory)
- Various portability improvements
- Various documentation improvements
- Various spelling and typo corrections
Changes in 1.2.13 (13 Oct 2022)
- Fix configure issue that discarded provided CC definition
@ -1448,7 +1463,7 @@ Changes in 0.99 (27 Jan 96)
- fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
- in fcalloc, normalize pointer if size > 65520 bytes
- don't use special fcalloc for 32 bit Borland C++
- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc.
- use Z_BINARY instead of BINARY
- document that gzclose after gzdopen will close the file
- allow "a" as mode in gzopen

View File

@ -1,6 +1,6 @@
ZLIB DATA COMPRESSION LIBRARY
zlib 1.2.13.1 is a general purpose data compression library. All the code is
zlib 1.3 is a general purpose data compression library. All the code is
thread safe. The data format used by the zlib library is described by RFCs
(Request for Comments) 1950 to 1952 in the files
http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
@ -31,7 +31,7 @@ Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
issue of Dr. Dobb's Journal; a copy of the article is available at
https://marknelson.us/posts/1997/01/01/zlib-engine.html .
The changes made in version 1.2.13.1 are documented in the file ChangeLog.
The changes made in version 1.3 are documented in the file ChangeLog.
Unsupported third party contributions are provided in directory contrib/ .
@ -83,7 +83,7 @@ Acknowledgments:
Copyright notice:
(C) 1995-2022 Jean-loup Gailly and Mark Adler
(C) 1995-2023 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,5 +1,5 @@
/* deflate.c -- compress data using the deflation algorithm
* Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
* Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/

View File

@ -1,5 +1,5 @@
/* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2022 Mark Adler
* Copyright (C) 1995-2023 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@ -55,7 +55,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 77, 76};
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 198, 203};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,

View File

@ -1,7 +1,7 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.2.13.1, October xxth, 2022
version 1.3, August 18th, 2023
Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -37,12 +37,12 @@
extern "C" {
#endif
#define ZLIB_VERSION "1.2.13.1-motley"
#define ZLIB_VERNUM 0x12d1
#define ZLIB_VERSION "1.3"
#define ZLIB_VERNUM 0x1300
#define ZLIB_VER_MAJOR 1
#define ZLIB_VER_MINOR 2
#define ZLIB_VER_REVISION 13
#define ZLIB_VER_SUBREVISION 1
#define ZLIB_VER_MINOR 3
#define ZLIB_VER_REVISION 0
#define ZLIB_VER_SUBREVISION 0
/*
The 'zlib' compression library provides in-memory compression and

View File

@ -1,25 +1,25 @@
/* $OpenBSD: casttest.c,v 1.2 2018/07/17 17:06:49 tb Exp $ */
/* $OpenBSD: casttest.c,v 1.7 2023/08/20 22:35:52 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@ -34,10 +34,10 @@
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@ -49,7 +49,7 @@
* 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 licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
@ -59,164 +59,139 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <openssl/opensslconf.h> /* To see if OPENSSL_NO_CAST is defined */
#include <openssl/cast.h>
#define FULL_TEST
static const unsigned char k[16] = {
0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A,
};
static unsigned char k[16]={
0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A
};
static const unsigned char in[8] = {
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
};
static unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
static int k_len[3]={16,10,5};
static unsigned char c[3][8]={
{0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2},
{0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B},
{0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E},
};
static int k_len[3] = {16, 10, 5};
static const unsigned char c[3][8] = {
{0x23, 0x8B, 0x4F, 0xE5, 0x84, 0x7E, 0x44, 0xB2},
{0xEB, 0x6A, 0x71, 0x1A, 0x2C, 0x02, 0x27, 0x1B},
{0x7A, 0xC8, 0x16, 0xD1, 0x6E, 0x9B, 0x30, 0x2E},
};
static unsigned char out[80];
static unsigned char in_a[16]={
0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
static unsigned char in_b[16]={
0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
static const unsigned char in_a[16] = {
0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A,
};
static const unsigned char in_b[16] = {
0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A,
};
static unsigned char c_a[16]={
0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6,
0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92};
static unsigned char c_b[16]={
0xB2,0xC9,0x5E,0xB0,0x0C,0x31,0xAD,0x71,
0x80,0xAC,0x05,0xB8,0xE8,0x3D,0x69,0x6E};
static const unsigned char c_a[16] = {
0xEE, 0xA9, 0xD0, 0xA2, 0x49, 0xFD, 0x3B, 0xA6,
0xB3, 0x43, 0x6F, 0xB8, 0x9D, 0x6D, 0xCA, 0x92,
};
static const unsigned char c_b[16] = {
0xB2, 0xC9, 0x5E, 0xB0, 0x0C, 0x31, 0xAD, 0x71,
0x80, 0xAC, 0x05, 0xB8, 0xE8, 0x3D, 0x69, 0x6E,
};
#if 0
char *text="Hello to all people out there";
int
main(int argc, char *argv[])
{
long l;
CAST_KEY key_b;
int i, z, err = 0;
CAST_KEY key;
static unsigned char cfb_key[16]={
0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96,
0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e,
};
static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd};
static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
#define CFB_TEST_SIZE 24
static unsigned char plain[CFB_TEST_SIZE]=
{
0x4e,0x6f,0x77,0x20,0x69,0x73,
0x20,0x74,0x68,0x65,0x20,0x74,
0x69,0x6d,0x65,0x20,0x66,0x6f,
0x72,0x20,0x61,0x6c,0x6c,0x20
};
static unsigned char cfb_cipher64[CFB_TEST_SIZE]={
0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F,
0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A,
0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45
for (z = 0; z < 3; z++) {
CAST_set_key(&key, k_len[z], k);
/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38,
0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9,
0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/
};
#endif
CAST_ecb_encrypt(in, out, &key, CAST_ENCRYPT);
if (memcmp(out, &(c[z][0]), 8) != 0) {
printf("ecb cast error encrypting for keysize %d\n",
k_len[z]*8);
printf("got :");
for (i = 0; i < 8; i++)
printf("%02X ", out[i]);
printf("\n");
printf("expected:");
for (i = 0; i < 8; i++)
printf("%02X ", c[z][i]);
err = 20;
printf("\n");
}
int main(int argc, char *argv[])
{
#ifdef FULL_TEST
long l;
CAST_KEY key_b;
#endif
int i,z,err=0;
CAST_KEY key;
for (z=0; z<3; z++)
{
CAST_set_key(&key,k_len[z],k);
CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT);
if (memcmp(out,&(c[z][0]),8) != 0)
{
printf("ecb cast error encrypting for keysize %d\n",k_len[z]*8);
printf("got :");
for (i=0; i<8; i++)
printf("%02X ",out[i]);
printf("\n");
printf("expected:");
for (i=0; i<8; i++)
printf("%02X ",c[z][i]);
err=20;
printf("\n");
}
CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT);
if (memcmp(out,in,8) != 0)
{
printf("ecb cast error decrypting for keysize %d\n",k_len[z]*8);
printf("got :");
for (i=0; i<8; i++)
printf("%02X ",out[i]);
printf("\n");
printf("expected:");
for (i=0; i<8; i++)
printf("%02X ",in[i]);
printf("\n");
err=3;
}
CAST_ecb_encrypt(out, out, &key, CAST_DECRYPT);
if (memcmp(out, in, 8) != 0) {
printf("ecb cast error decrypting for keysize %d\n",
k_len[z]*8);
printf("got :");
for (i = 0; i < 8; i++)
printf("%02X ", out[i]);
printf("\n");
printf("expected:");
for (i = 0; i < 8; i++)
printf("%02X ", in[i]);
printf("\n");
err = 3;
}
}
if (err == 0)
printf("ecb cast5 ok\n");
if (err == 0)
printf("ecb cast5 ok\n");
#ifdef FULL_TEST
{
unsigned char out_a[16],out_b[16];
static char *hex="0123456789ABCDEF";
printf("This test will take some time....");
fflush(stdout);
memcpy(out_a,in_a,sizeof(in_a));
memcpy(out_b,in_b,sizeof(in_b));
i=1;
{
unsigned char out_a[16], out_b[16];
static char *hex = "0123456789ABCDEF";
for (l=0; l<1000000L; l++)
{
CAST_set_key(&key_b,16,out_b);
CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT);
CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT);
CAST_set_key(&key,16,out_a);
CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT);
CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT);
if ((l & 0xffff) == 0xffff)
{
printf("%c",hex[i&0x0f]);
fflush(stdout);
i++;
}
}
printf("This test will take some time....");
fflush(stdout);
memcpy(out_a, in_a, sizeof(in_a));
memcpy(out_b, in_b, sizeof(in_b));
i = 1;
if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) ||
(memcmp(out_b,c_b,sizeof(c_b)) != 0))
{
printf("\n");
printf("Error\n");
for (l = 0; l < 1000000L; l++) {
CAST_set_key(&key_b, 16, out_b);
CAST_ecb_encrypt(&(out_a[0]), &(out_a[0]), &key_b,
CAST_ENCRYPT);
CAST_ecb_encrypt(&(out_a[8]), &(out_a[8]), &key_b,
CAST_ENCRYPT);
CAST_set_key(&key, 16, out_a);
CAST_ecb_encrypt(&(out_b[0]), &(out_b[0]), &key,
CAST_ENCRYPT);
CAST_ecb_encrypt(&(out_b[8]), &(out_b[8]), &key,
CAST_ENCRYPT);
if ((l & 0xffff) == 0xffff) {
printf("%c", hex[i & 0x0f]);
fflush(stdout);
i++;
}
}
printf("A out =");
for (i=0; i<16; i++) printf("%02X ",out_a[i]);
printf("\nactual=");
for (i=0; i<16; i++) printf("%02X ",c_a[i]);
printf("\n");
if ((memcmp(out_a, c_a, sizeof(c_a)) != 0) ||
(memcmp(out_b, c_b, sizeof(c_b)) != 0)) {
printf("\n");
printf("Error\n");
printf("B out =");
for (i=0; i<16; i++) printf("%02X ",out_b[i]);
printf("\nactual=");
for (i=0; i<16; i++) printf("%02X ",c_b[i]);
printf("\n");
}
else
printf(" ok\n");
}
#endif
printf("A out =");
for (i = 0; i < 16; i++)
printf("%02X ", out_a[i]);
printf("\nactual=");
for (i = 0; i < 16; i++)
printf("%02X ", c_a[i]);
printf("\n");
exit(err);
}
printf("B out =");
for (i = 0; i < 16; i++)
printf("%02X ", out_b[i]);
printf("\nactual=");
for (i = 0; i < 16; i++)
printf("%02X ", c_b[i]);
printf("\n");
} else
printf(" ok\n");
}
exit(err);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: dhtest.c,v 1.12 2023/08/12 06:30:43 tb Exp $ */
/* $OpenBSD: dhtest.c,v 1.14 2023/08/20 22:21:00 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -56,12 +56,6 @@
* [including the GNU Public Licence.]
*/
/* Until the key-gen callbacks are modified to use newer prototypes, we allow
* deprecated functions for openssl-internal code */
#ifdef OPENSSL_NO_DEPRECATED
#undef OPENSSL_NO_DEPRECATED
#endif
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
@ -98,7 +92,8 @@ main(int argc, char *argv[])
BN_GENCB *_cb;
DH *dh = NULL;
unsigned char *buf = NULL;
int i, buf_len, secret_len;
int flags, buf_len, secret_len;
int i;
int ret = 1;
if ((_cb = BN_GENCB_new()) == NULL)
@ -118,15 +113,15 @@ main(int argc, char *argv[])
if (!DH_generate_parameters_ex(dh, 64, DH_GENERATOR_5, _cb))
goto err;
if (!DH_check(dh, &i))
if (!DH_check(dh, &flags))
goto err;
if (i & DH_CHECK_P_NOT_PRIME)
if (flags & DH_CHECK_P_NOT_PRIME)
printf("p value is not prime\n");
if (i & DH_CHECK_P_NOT_SAFE_PRIME)
if (flags & DH_CHECK_P_NOT_SAFE_PRIME)
printf("p value is not a safe prime\n");
if (i & DH_UNABLE_TO_CHECK_GENERATOR)
if (flags & DH_UNABLE_TO_CHECK_GENERATOR)
printf("unable to check the generator value\n");
if (i & DH_NOT_SUITABLE_GENERATOR)
if (flags & DH_NOT_SUITABLE_GENERATOR)
printf("the g value is not a generator\n");
printf("\np = ");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: dsatest.c,v 1.8 2023/08/12 06:23:59 tb Exp $ */
/* $OpenBSD: dsatest.c,v 1.9 2023/08/20 22:22:55 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -56,12 +56,6 @@
* [including the GNU Public Licence.]
*/
/* Until the key-gen callbacks are modified to use newer prototypes, we allow
* deprecated functions for openssl-internal code */
#ifdef OPENSSL_NO_DEPRECATED
#undef OPENSSL_NO_DEPRECATED
#endif
#include <err.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -0,0 +1,41 @@
# $OpenBSD: Makefile,v 1.1 2023/08/20 23:19:00 kn Exp $
BIOCTL ?= /sbin/bioctl
CHUNKFILE = disk.img
CHUNKDEVFILE = chunk.txt
VOLDEVFILE = vol.txt
OLDPW = oldsecret
NEWPW = securenew
REGRESS_SETUP_ONCE = create-chunk
create-chunk:
dd if=/dev/zero of=${CHUNKFILE} bs=512k count=0 seek=1 status=none
${SUDO} vnconfig -- ${CHUNKFILE} 1>${CHUNKDEVFILE}
echo 'RAID *' | ${SUDO} disklabel -wAT- -- "$$(<${CHUNKDEVFILE})"
REGRESS_TARGETS = scripted-create-volume \
scripted-change-passphrase
scripted-create-volume:
printf '%s\n' '${OLDPW}' | \
${SUDO} ${BIOCTL} -s -cC -l"$$(<${CHUNKDEVFILE})a" -- softraid0 | \
grep -o 'sd[0-9]*$$' -- 1>${VOLDEVFILE}
scripted-change-passphrase:
printf '%s\n%s\n' '${OLDPW}' '${NEWPW}' | \
${SUDO} ${BIOCTL} -s -P -- "$$(<${VOLDEVFILE})"
CLEANFILES = *.txt *.img
REGRESS_CLEANUP = cleanup
cleanup:
${SUDO} ${BIOCTL} -d -- "$$(<${VOLDEVFILE})" 2>/dev/null
${SUDO} vnconfig -u -- "$$(<${CHUNKDEVFILE})" 2>/dev/null
.include <bsd.regress.mk>

View File

@ -1,13 +1,15 @@
# $OpenBSD: Makefile,v 1.31 2022/03/30 05:11:52 anton Exp $
# $OpenBSD: Makefile,v 1.32 2023/08/20 15:19:34 visa Exp $
PROG= kqueue-test
CFLAGS+=-Wall
SRCS= kqueue-pipe.c kqueue-fork.c main.c kqueue-process.c kqueue-random.c \
kqueue-pty.c kqueue-tun.c kqueue-signal.c kqueue-fdpass.c \
kqueue-flock.c kqueue-timer.c kqueue-regress.c
kqueue-exec.c kqueue-flock.c kqueue-timer.c kqueue-regress.c
LDADD= -levent -lutil
DPADD= ${LIBEVENT} ${LIBUTIL}
kq-exec: ${PROG}
./${PROG} -e
kq-pipe: ${PROG}
./${PROG} -p
kq-fork: ${PROG}
@ -51,6 +53,7 @@ kq-regress-5: ${PROG}
kq-regress-6: ${PROG}
./${PROG} -R6
TESTS+= kq-exec
TESTS+= kq-fdpass
TESTS+= kq-flock
TESTS+= kq-fork

View File

@ -0,0 +1,113 @@
/* $OpenBSD: kqueue-exec.c,v 1.1 2023/08/20 15:19:34 visa Exp $ */
/*
* Copyright (c) 2023 Visa Hankala
*
* 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 <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "main.h"
static void do_exec_child(void);
static void do_exec_parent(const char *, int);
int
do_exec(const char *argv0)
{
do_exec_parent(argv0, 0);
do_exec_parent(argv0, 1);
return 0;
}
static void
do_exec_parent(const char *argv0, int cloexec)
{
char *args[] = {
(char *)argv0,
"-e",
NULL
};
char fdbuf[12];
pid_t pid;
int kq, status;
if (getenv("REGRESS_KQUEUE_FD") != NULL) {
do_exec_child();
_exit(0);
}
pid = fork();
if (pid == -1)
err(1, "fork");
if (pid == 0) {
kq = kqueue1(cloexec ? O_CLOEXEC : 0);
if (kq == -1)
err(1, "kqueue1");
snprintf(fdbuf, sizeof(fdbuf), "%d", kq);
if (setenv("REGRESS_KQUEUE_FD", fdbuf, 1) == -1)
err(1, "setenv");
if (setenv("REGRESS_KQUEUE_CLOEXEC",
cloexec ? "1" : "0", 1) == -1)
err(1, "setenv 2");
execv(argv0, args);
err(1, "execve");
}
if (waitpid(pid, &status, 0) == -1)
err(1, "waitpid");
if (status != 0)
errx(1, "child failed");
}
static void
do_exec_child(void)
{
char *arg;
int cloexec, fd;
arg = getenv("REGRESS_KQUEUE_FD");
if (arg == NULL)
errx(1, "fd arg is missing");
fd = atoi(arg);
arg = getenv("REGRESS_KQUEUE_CLOEXEC");
if (arg != NULL && strcmp(arg, "1") == 0)
cloexec = 1;
else
cloexec = 0;
if (cloexec) {
if (kevent(fd, NULL, 0, NULL, 0, 0) == -1) {
if (errno != EBADF)
err(1, "child after exec: kevent cloexec");
} else {
errx(1, "child after exec: "
"kqueue cloexec fd is not closed");
}
} else {
if (kevent(fd, NULL, 0, NULL, 0, 0) == -1) {
err(1, "child after exec: kevent");
}
}
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.15 2021/06/12 13:30:14 visa Exp $ */
/* $OpenBSD: main.c,v 1.16 2023/08/20 15:19:34 visa Exp $ */
/*
* Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain
*/
@ -17,8 +17,11 @@ main(int argc, char **argv)
int n, ret, c;
ret = 0;
while ((c = getopt(argc, argv, "fFiIjlpPrR:stT:")) != -1) {
while ((c = getopt(argc, argv, "efFiIjlpPrR:stT:")) != -1) {
switch (c) {
case 'e':
ret |= do_exec(argv[0]);
break;
case 'f':
ret |= check_inheritance();
break;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main.h,v 1.6 2021/06/12 13:30:14 visa Exp $ */
/* $OpenBSD: main.h,v 1.7 2023/08/20 15:19:34 visa Exp $ */
/*
* Written by Alexaner Bluhm <bluhm@openbsd.org> 2016 Public Domain
*/
@ -16,6 +16,7 @@
__FILE__, __LINE__))
int check_inheritance(void);
int do_exec(const char *);
int do_fdpass(void);
int do_flock(void);
int do_invalid_timer(void);

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.38 2023/02/07 15:04:27 kn Exp $
# $OpenBSD: Makefile,v 1.39 2023/08/20 22:38:49 kn Exp $
INSTALLBOOT ?= /usr/sbin/installboot
DRY_RUN = ${INSTALLBOOT} -n
@ -84,7 +84,7 @@ create-root: create-disks
.if ${USE_SOFTRAID:L} == "yes"
${SUDO} bioctl -l"$$(sed -- s/$$/a/ ${DISKDEVFILES} | paste -sd, -- -)" \
-c1C -k"$$(<${KEYDEVFILE})"a -- softraid0 | \
awk -- '{ print $$NF }' 1>${ROOTDEVFILE}
grep -o -- 'sd[0-9]*$$' 1>${ROOTDEVFILE}
${SUDO} ${FORMAT_DISK} -- "$$(<${ROOTDEVFILE})" 1>/dev/null
.else
ln -s -- ${DISKDEVFILES} ${ROOTDEVFILE}

View File

@ -1,10 +1,10 @@
/* $OpenBSD: init_sysent.c,v 1.267 2023/07/24 19:33:29 miod Exp $ */
/* $OpenBSD: init_sysent.c,v 1.268 2023/08/20 15:14:20 visa Exp $ */
/*
* System call switch table.
*
* DO NOT EDIT-- this file is automatically generated.
* created from; OpenBSD: syscalls.master,v 1.249 2023/07/24 19:32:23 miod Exp
* created from; OpenBSD: syscalls.master,v 1.250 2023/08/20 15:13:43 visa Exp
*/
#include <sys/param.h>
@ -604,8 +604,8 @@ const struct sysent sysent[] = {
sys_nosys }, /* 268 = obsolete pad_pwritev */
{ 0, 0, SY_NOLOCK | 0,
sys_kqueue }, /* 269 = kqueue */
{ 0, 0, 0,
sys_nosys }, /* 270 = obsolete t32_kevent */
{ 1, s(struct sys_kqueue1_args), SY_NOLOCK | 0,
sys_kqueue1 }, /* 270 = kqueue1 */
{ 1, s(struct sys_mlockall_args), 0,
sys_mlockall }, /* 271 = mlockall */
{ 0, 0, 0,

View File

@ -1,4 +1,4 @@
/* $OpenBSD: kern_event.c,v 1.197 2023/08/13 08:29:28 visa Exp $ */
/* $OpenBSD: kern_event.c,v 1.198 2023/08/20 15:13:43 visa Exp $ */
/*-
* Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
@ -60,6 +60,7 @@
#define KLIST_ASSERT_LOCKED(kl) ((void)(kl))
#endif
int dokqueue(struct proc *, int, register_t *);
struct kqueue *kqueue_alloc(struct filedesc *);
void kqueue_terminate(struct proc *p, struct kqueue *);
void KQREF(struct kqueue *);
@ -912,12 +913,14 @@ kqueue_alloc(struct filedesc *fdp)
}
int
sys_kqueue(struct proc *p, void *v, register_t *retval)
dokqueue(struct proc *p, int flags, register_t *retval)
{
struct filedesc *fdp = p->p_fd;
struct kqueue *kq;
struct file *fp;
int fd, error;
int cloexec, error, fd;
cloexec = (flags & O_CLOEXEC) ? UF_EXCLOSE : 0;
kq = kqueue_alloc(fdp);
@ -925,14 +928,14 @@ sys_kqueue(struct proc *p, void *v, register_t *retval)
error = falloc(p, &fp, &fd);
if (error)
goto out;
fp->f_flag = FREAD | FWRITE;
fp->f_flag = FREAD | FWRITE | (flags & FNONBLOCK);
fp->f_type = DTYPE_KQUEUE;
fp->f_ops = &kqueueops;
fp->f_data = kq;
*retval = fd;
LIST_INSERT_HEAD(&fdp->fd_kqlist, kq, kq_next);
kq = NULL;
fdinsert(fdp, fd, 0, fp);
fdinsert(fdp, fd, cloexec, fp);
FRELE(fp, p);
out:
fdpunlock(fdp);
@ -941,6 +944,24 @@ out:
return (error);
}
int
sys_kqueue(struct proc *p, void *v, register_t *retval)
{
return (dokqueue(p, 0, retval));
}
int
sys_kqueue1(struct proc *p, void *v, register_t *retval)
{
struct sys_kqueue1_args /* {
syscallarg(int) flags;
} */ *uap = v;
if (SCARG(uap, flags) & ~(O_CLOEXEC | FNONBLOCK))
return (EINVAL);
return (dokqueue(p, SCARG(uap, flags), retval));
}
int
sys_kevent(struct proc *p, void *v, register_t *retval)
{

View File

@ -1,4 +1,4 @@
/* $OpenBSD: kern_pledge.c,v 1.306 2023/06/02 17:44:29 cheloha Exp $ */
/* $OpenBSD: kern_pledge.c,v 1.307 2023/08/20 15:13:43 visa Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
@ -209,6 +209,7 @@ const uint64_t pledge_syscalls[SYS_MAXSYSCALL] = {
[SYS_ppoll] = PLEDGE_STDIO,
[SYS_kevent] = PLEDGE_STDIO,
[SYS_kqueue] = PLEDGE_STDIO,
[SYS_kqueue1] = PLEDGE_STDIO,
[SYS_select] = PLEDGE_STDIO,
[SYS_pselect] = PLEDGE_STDIO,

View File

@ -1,10 +1,10 @@
/* $OpenBSD: syscalls.c,v 1.265 2023/07/24 19:33:29 miod Exp $ */
/* $OpenBSD: syscalls.c,v 1.266 2023/08/20 15:14:20 visa Exp $ */
/*
* System call names.
*
* DO NOT EDIT-- this file is automatically generated.
* created from; OpenBSD: syscalls.master,v 1.249 2023/07/24 19:32:23 miod Exp
* created from; OpenBSD: syscalls.master,v 1.250 2023/08/20 15:13:43 visa Exp
*/
const char *const syscallnames[] = {
@ -312,7 +312,7 @@ const char *const syscallnames[] = {
"#267 (obsolete pad_preadv)", /* 267 = obsolete pad_preadv */
"#268 (obsolete pad_pwritev)", /* 268 = obsolete pad_pwritev */
"kqueue", /* 269 = kqueue */
"#270 (obsolete t32_kevent)", /* 270 = obsolete t32_kevent */
"kqueue1", /* 270 = kqueue1 */
"mlockall", /* 271 = mlockall */
"munlockall", /* 272 = munlockall */
"#273 (unimplemented sys_getpeereid)", /* 273 = unimplemented sys_getpeereid */

View File

@ -1,4 +1,4 @@
; $OpenBSD: syscalls.master,v 1.249 2023/07/24 19:32:23 miod Exp $
; $OpenBSD: syscalls.master,v 1.250 2023/08/20 15:13:43 visa Exp $
; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $
; @(#)syscalls.master 8.2 (Berkeley) 1/13/94
@ -462,7 +462,7 @@
267 OBSOL pad_preadv
268 OBSOL pad_pwritev
269 STD NOLOCK { int sys_kqueue(void); }
270 OBSOL t32_kevent
270 STD NOLOCK { int sys_kqueue1(int flags); }
271 STD { int sys_mlockall(int flags); }
272 STD { int sys_munlockall(void); }
273 UNIMPL sys_getpeereid

View File

@ -1,5 +1,5 @@
/* deflate.c -- compress data using the deflation algorithm
* Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
* Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/

View File

@ -1,5 +1,5 @@
/* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2022 Mark Adler
* Copyright (C) 1995-2023 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@ -55,7 +55,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 77, 76};
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 198, 203};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,

View File

@ -1,7 +1,7 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.2.13.1, October xxth, 2022
version 1.3, August 18th, 2023
Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -37,12 +37,12 @@
extern "C" {
#endif
#define ZLIB_VERSION "1.2.13.1-motley"
#define ZLIB_VERNUM 0x12d1
#define ZLIB_VERSION "1.3"
#define ZLIB_VERNUM 0x1300
#define ZLIB_VER_MAJOR 1
#define ZLIB_VER_MINOR 2
#define ZLIB_VER_REVISION 13
#define ZLIB_VER_SUBREVISION 1
#define ZLIB_VER_MINOR 3
#define ZLIB_VER_REVISION 0
#define ZLIB_VER_SUBREVISION 0
/*
The 'zlib' compression library provides in-memory compression and

View File

@ -1,4 +1,4 @@
/* $OpenBSD: event.h,v 1.70 2023/08/13 08:29:28 visa Exp $ */
/* $OpenBSD: event.h,v 1.71 2023/08/20 15:13:43 visa Exp $ */
/*-
* Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
@ -369,6 +369,7 @@ struct timespec;
__BEGIN_DECLS
int kqueue(void);
int kqueue1(int flags);
int kevent(int kq, const struct kevent *changelist, int nchanges,
struct kevent *eventlist, int nevents,
const struct timespec *timeout);

View File

@ -1,10 +1,10 @@
/* $OpenBSD: syscall.h,v 1.264 2023/07/24 19:33:29 miod Exp $ */
/* $OpenBSD: syscall.h,v 1.265 2023/08/20 15:14:20 visa Exp $ */
/*
* System call numbers.
*
* DO NOT EDIT-- this file is automatically generated.
* created from; OpenBSD: syscalls.master,v 1.249 2023/07/24 19:32:23 miod Exp
* created from; OpenBSD: syscalls.master,v 1.250 2023/08/20 15:13:43 visa Exp
*/
/* syscall: "syscall" ret: "int" args: "int" "..." */
@ -599,7 +599,9 @@
/* syscall: "kqueue" ret: "int" args: */
#define SYS_kqueue 269
/* 270 is obsolete t32_kevent */
/* syscall: "kqueue1" ret: "int" args: "int" */
#define SYS_kqueue1 270
/* syscall: "mlockall" ret: "int" args: "int" */
#define SYS_mlockall 271

View File

@ -1,10 +1,10 @@
/* $OpenBSD: syscallargs.h,v 1.267 2023/07/24 19:33:29 miod Exp $ */
/* $OpenBSD: syscallargs.h,v 1.268 2023/08/20 15:14:20 visa Exp $ */
/*
* System call argument lists.
*
* DO NOT EDIT-- this file is automatically generated.
* created from; OpenBSD: syscalls.master,v 1.249 2023/07/24 19:32:23 miod Exp
* created from; OpenBSD: syscalls.master,v 1.250 2023/08/20 15:13:43 visa Exp
*/
#ifdef syscallarg
@ -960,6 +960,10 @@ struct sys_fhopen_args {
syscallarg(int) flags;
};
struct sys_kqueue1_args {
syscallarg(int) flags;
};
struct sys_mlockall_args {
syscallarg(int) flags;
};
@ -1355,6 +1359,7 @@ int sys_msync(struct proc *, void *, register_t *);
int sys_pipe(struct proc *, void *, register_t *);
int sys_fhopen(struct proc *, void *, register_t *);
int sys_kqueue(struct proc *, void *, register_t *);
int sys_kqueue1(struct proc *, void *, register_t *);
int sys_mlockall(struct proc *, void *, register_t *);
int sys_munlockall(struct proc *, void *, register_t *);
int sys_getresuid(struct proc *, void *, register_t *);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: kdump.c,v 1.157 2023/04/16 19:42:40 otto Exp $ */
/* $OpenBSD: kdump.c,v 1.158 2023/08/21 01:37:56 visa Exp $ */
/*-
* Copyright (c) 1988, 1993
@ -876,6 +876,7 @@ static const formatter scargs[][8] = {
[SYS_msync] = { Pptr, Pbigsize, Msyncflagsname },
[SYS_pipe] = { Pptr },
[SYS_fhopen] = { Pptr, Openflagsname },
[SYS_kqueue1] = { Flagsname },
[SYS_mlockall] = { Mlockallname },
[SYS_getresuid] = { Pptr, Pptr, Pptr },
[SYS_setresuid] = { Uidname, Uidname, Uidname },