diff options
| author | millert <> | 2026-05-08 14:37:16 +0000 |
|---|---|---|
| committer | millert <> | 2026-05-08 14:37:16 +0000 |
| commit | 338f5824685b5705cb660c43d3fd220962a668f3 (patch) | |
| tree | 5248d2bb21f52a50156c4ef60bff7ac8cc41488a /src | |
| parent | 4461e1044c1f5d62e73b506069783fec8c68da0b (diff) | |
| download | openbsd-338f5824685b5705cb660c43d3fd220962a668f3.tar.gz openbsd-338f5824685b5705cb660c43d3fd220962a668f3.tar.bz2 openbsd-338f5824685b5705cb660c43d3fd220962a668f3.zip | |
Add wide version of open_memstream regress.
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libc/Makefile | 4 | ||||
| -rw-r--r-- | src/regress/lib/libc/open_wmemstream/Makefile | 5 | ||||
| -rw-r--r-- | src/regress/lib/libc/open_wmemstream/open_wmemstreamtest.c | 189 |
3 files changed, 196 insertions, 2 deletions
diff --git a/src/regress/lib/libc/Makefile b/src/regress/lib/libc/Makefile index 7a8db225ef..7012e12310 100644 --- a/src/regress/lib/libc/Makefile +++ b/src/regress/lib/libc/Makefile | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.62 2025/08/04 06:10:40 tb Exp $ | 1 | # $OpenBSD: Makefile,v 1.63 2026/05/08 14:37:16 millert Exp $ |
| 2 | 2 | ||
| 3 | SUBDIR+= _setjmp | 3 | SUBDIR+= _setjmp |
| 4 | SUBDIR+= alloca arc4random-fork atexit | 4 | SUBDIR+= alloca arc4random-fork atexit |
| @@ -15,7 +15,7 @@ SUBDIR+= ieeefp ifnameindex illumos | |||
| 15 | SUBDIR+= ldexp locale longjmp | 15 | SUBDIR+= ldexp locale longjmp |
| 16 | SUBDIR+= malloc mkstemp modf | 16 | SUBDIR+= malloc mkstemp modf |
| 17 | SUBDIR+= netdb | 17 | SUBDIR+= netdb |
| 18 | SUBDIR+= open_memstream orientation | 18 | SUBDIR+= open_memstream orientation open_wmemstream |
| 19 | SUBDIR+= popen printf | 19 | SUBDIR+= popen printf |
| 20 | SUBDIR+= qsort | 20 | SUBDIR+= qsort |
| 21 | SUBDIR+= regex | 21 | SUBDIR+= regex |
diff --git a/src/regress/lib/libc/open_wmemstream/Makefile b/src/regress/lib/libc/open_wmemstream/Makefile new file mode 100644 index 0000000000..232bc4a176 --- /dev/null +++ b/src/regress/lib/libc/open_wmemstream/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2026/05/08 14:37:16 millert Exp $ | ||
| 2 | |||
| 3 | PROG= open_wmemstreamtest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/open_wmemstream/open_wmemstreamtest.c b/src/regress/lib/libc/open_wmemstream/open_wmemstreamtest.c new file mode 100644 index 0000000000..fa2a17d33c --- /dev/null +++ b/src/regress/lib/libc/open_wmemstream/open_wmemstreamtest.c | |||
| @@ -0,0 +1,189 @@ | |||
| 1 | /* $OpenBSD: open_wmemstreamtest.c,v 1.1 2026/05/08 14:37:16 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software for any | ||
| 7 | * purpose with or without fee is hereby granted, provided that the above | ||
| 8 | * copyright notice and this permission notice appear in all copies. | ||
| 9 | * | ||
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <err.h> | ||
| 20 | #include <stdio.h> | ||
| 21 | #include <stdlib.h> | ||
| 22 | #include <string.h> | ||
| 23 | #include <wchar.h> | ||
| 24 | #include <unistd.h> | ||
| 25 | |||
| 26 | #define OFFSET 16384 | ||
| 27 | |||
| 28 | const wchar_t start[] = { 's', 't', 'a', 'r', 't', 0 }; | ||
| 29 | const wchar_t hello[] = { 'h', 'e', 'l', 'l', 'o', 0 }; | ||
| 30 | |||
| 31 | int | ||
| 32 | main(void) | ||
| 33 | { | ||
| 34 | FILE *fp; | ||
| 35 | wchar_t *buf = (wchar_t *)0xff; | ||
| 36 | size_t size = 0; | ||
| 37 | off_t off; | ||
| 38 | int i, failures = 0; | ||
| 39 | |||
| 40 | if ((fp = open_wmemstream(&buf, &size)) == NULL) { | ||
| 41 | warn("open_wmemstream failed"); | ||
| 42 | return (1); | ||
| 43 | } | ||
| 44 | |||
| 45 | off = ftello(fp); | ||
| 46 | if (off != 0) { | ||
| 47 | warnx("ftello failed. (1)"); | ||
| 48 | failures++; | ||
| 49 | } | ||
| 50 | |||
| 51 | if (fflush(fp) != 0) { | ||
| 52 | warnx("fflush failed. (2)"); | ||
| 53 | failures++; | ||
| 54 | } | ||
| 55 | |||
| 56 | if (size != 0) { | ||
| 57 | warnx("string should be empty. (3)"); | ||
| 58 | failures++; | ||
| 59 | } | ||
| 60 | |||
| 61 | if (buf == (wchar_t *)0xff) { | ||
| 62 | warnx("buf not updated. (4)"); | ||
| 63 | failures++; | ||
| 64 | } | ||
| 65 | |||
| 66 | if (fseek(fp, OFFSET, SEEK_SET) != 0) { | ||
| 67 | warnx("failed to fseek. (5)"); | ||
| 68 | failures++; | ||
| 69 | } | ||
| 70 | |||
| 71 | if (fwprintf(fp, hello) == EOF) { | ||
| 72 | warnx("fwprintf failed. (6)"); | ||
| 73 | failures++; | ||
| 74 | } | ||
| 75 | |||
| 76 | if (fflush(fp) == EOF) { | ||
| 77 | warnx("fflush failed. (7)"); | ||
| 78 | failures++; | ||
| 79 | } | ||
| 80 | |||
| 81 | if (size != OFFSET + wcslen(hello)) { | ||
| 82 | warnx("failed, size %zu should be %zu. (8)", | ||
| 83 | size, OFFSET + wcslen(hello)); | ||
| 84 | failures++; | ||
| 85 | } | ||
| 86 | |||
| 87 | if (fseek(fp, 0, SEEK_SET) != 0) { | ||
| 88 | warnx("failed to fseek. (9)"); | ||
| 89 | failures++; | ||
| 90 | } | ||
| 91 | |||
| 92 | if (fwprintf(fp, start) == EOF) { | ||
| 93 | warnx("fwprintf failed. (10)"); | ||
| 94 | failures++; | ||
| 95 | } | ||
| 96 | |||
| 97 | if (fflush(fp) == EOF) { | ||
| 98 | warnx("fflush failed. (11)"); | ||
| 99 | failures++; | ||
| 100 | } | ||
| 101 | |||
| 102 | if (size != wcslen(start)) { | ||
| 103 | warnx("failed, size %zu should be %zu. (12)", | ||
| 104 | size, wcslen(start)); | ||
| 105 | failures++; | ||
| 106 | } | ||
| 107 | |||
| 108 | /* Needed for sparse files */ | ||
| 109 | if (wcsncmp(buf, start, wcslen(start)) != 0) { | ||
| 110 | char buf[sizeof(start)]; | ||
| 111 | wcstombs(buf, start, sizeof(buf)); | ||
| 112 | warnx("failed, buffer didn't start with '%s'. (13)", buf); | ||
| 113 | failures++; | ||
| 114 | } | ||
| 115 | for (i = wcslen(start); i < OFFSET; i++) | ||
| 116 | if (buf[i] != '\0') { | ||
| 117 | warnx("failed, buffer non zero (offset %d). (14)", i); | ||
| 118 | failures++; | ||
| 119 | break; | ||
| 120 | } | ||
| 121 | |||
| 122 | if (memcmp(buf + OFFSET, hello, wcslen(hello)) != 0) { | ||
| 123 | warnx("written string incorrect. (15)"); | ||
| 124 | failures++; | ||
| 125 | } | ||
| 126 | |||
| 127 | /* verify that simply seeking past the end doesn't increase the size */ | ||
| 128 | if (fseek(fp, 100, SEEK_END) != 0) { | ||
| 129 | warnx("failed to fseek. (16)"); | ||
| 130 | failures++; | ||
| 131 | } | ||
| 132 | |||
| 133 | if (fflush(fp) == EOF) { | ||
| 134 | warnx("fflush failed. (17)"); | ||
| 135 | failures++; | ||
| 136 | } | ||
| 137 | |||
| 138 | if (size != OFFSET + wcslen(hello)) { | ||
| 139 | warnx("failed, size %zu should be %zu. (18)", | ||
| 140 | size, OFFSET + wcslen(hello)); | ||
| 141 | failures++; | ||
| 142 | } | ||
| 143 | |||
| 144 | if (fseek(fp, -1, SEEK_END) != 0) { | ||
| 145 | warnx("failed to fseek. (19)"); | ||
| 146 | failures++; | ||
| 147 | } | ||
| 148 | |||
| 149 | if (fseek(fp, 8, SEEK_SET) != 0) { | ||
| 150 | warnx("failed to fseek. (20)"); | ||
| 151 | failures++; | ||
| 152 | } | ||
| 153 | |||
| 154 | if (ftell(fp) != 8) { | ||
| 155 | warnx("failed seek test. (21)"); | ||
| 156 | failures++; | ||
| 157 | } | ||
| 158 | |||
| 159 | /* Try to seek backward */ | ||
| 160 | if (fseek(fp, -1, SEEK_CUR) != 0) { | ||
| 161 | warnx("failed to fseek. (22)"); | ||
| 162 | failures++; | ||
| 163 | } | ||
| 164 | |||
| 165 | if (ftell(fp) != 7) { | ||
| 166 | warnx("failed seeking backward. (23)"); | ||
| 167 | failures++; | ||
| 168 | } | ||
| 169 | |||
| 170 | if (fseek(fp, 5, SEEK_CUR) != 0) { | ||
| 171 | warnx("failed to fseek. (24)"); | ||
| 172 | failures++; | ||
| 173 | } | ||
| 174 | |||
| 175 | if (fclose(fp) == EOF) { | ||
| 176 | warnx("fclose failed. (25)"); | ||
| 177 | failures++; | ||
| 178 | } | ||
| 179 | |||
| 180 | if (size != 12) { | ||
| 181 | warnx("failed, size %zu should be %u. (26)", | ||
| 182 | size, 12); | ||
| 183 | failures++; | ||
| 184 | } | ||
| 185 | |||
| 186 | free(buf); | ||
| 187 | |||
| 188 | return (failures); | ||
| 189 | } | ||
