diff options
Diffstat (limited to 'src/regress/lib/libc/fmemopen')
-rw-r--r-- | src/regress/lib/libc/fmemopen/Makefile | 5 | ||||
-rw-r--r-- | src/regress/lib/libc/fmemopen/fmemopentest.c | 68 |
2 files changed, 73 insertions, 0 deletions
diff --git a/src/regress/lib/libc/fmemopen/Makefile b/src/regress/lib/libc/fmemopen/Makefile new file mode 100644 index 0000000000..9cfbfaa99c --- /dev/null +++ b/src/regress/lib/libc/fmemopen/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2013/01/01 17:43:07 mpi Exp $ | ||
2 | |||
3 | PROG= fmemopentest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/fmemopen/fmemopentest.c b/src/regress/lib/libc/fmemopen/fmemopentest.c new file mode 100644 index 0000000000..ef7e9ff64f --- /dev/null +++ b/src/regress/lib/libc/fmemopen/fmemopentest.c | |||
@@ -0,0 +1,68 @@ | |||
1 | /* $OpenBSD: fmemopentest.c,v 1.1 2013/01/01 17:43:07 mpi Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <err.h> | ||
19 | #include <stdio.h> | ||
20 | #include <stdlib.h> | ||
21 | #include <string.h> | ||
22 | #include <unistd.h> | ||
23 | |||
24 | int | ||
25 | main(void) | ||
26 | { | ||
27 | FILE *s1, *s2; | ||
28 | char c, string[] = "fmemopen test string!"; | ||
29 | char buffer[1024], *buf = NULL; | ||
30 | size_t len; | ||
31 | int failures = 0; | ||
32 | |||
33 | s1 = fmemopen(string, strlen(string), "r"); | ||
34 | if (s1 == NULL) { | ||
35 | warn("unable to open a stream s1"); | ||
36 | return (1); | ||
37 | } | ||
38 | |||
39 | s2 = fmemopen(buf, 22, "w+"); | ||
40 | if (s2 == NULL) { | ||
41 | warn("unable to create a stream s2"); | ||
42 | fclose(s1); | ||
43 | return (1); | ||
44 | } | ||
45 | |||
46 | while ((c = fgetc(s1)) != EOF) | ||
47 | fputc(c, s2); | ||
48 | |||
49 | if (ftell(s2) != strlen(string)) { | ||
50 | warnx("failed copy test (1)"); | ||
51 | failures++; | ||
52 | } | ||
53 | fclose(s1); | ||
54 | |||
55 | fseek(s2, 0, SEEK_SET); | ||
56 | if (ftell(s2) != 0) { | ||
57 | warnx("failed seek test (2)"); | ||
58 | failures++; | ||
59 | } | ||
60 | |||
61 | len = fread(buffer, 1, sizeof(buffer) - 1, s2); | ||
62 | if (len != strlen(string)) { | ||
63 | warnx("failed read test (3)"); | ||
64 | failures++; | ||
65 | } | ||
66 | |||
67 | return (failures); | ||
68 | } | ||