summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/fmemopen
diff options
context:
space:
mode:
authormpi <>2013-01-01 17:43:07 +0000
committermpi <>2013-01-01 17:43:07 +0000
commitcb6e574cb86d4a97e7a9cc6ae79f181476188b21 (patch)
tree53d2af9885a4ad7ec3a7e5d1e0d59ea5195e5d3a /src/regress/lib/libc/fmemopen
parent6453f215f5463a02d8367c503969b10d3f8e0ccf (diff)
downloadopenbsd-cb6e574cb86d4a97e7a9cc6ae79f181476188b21.tar.gz
openbsd-cb6e574cb86d4a97e7a9cc6ae79f181476188b21.tar.bz2
openbsd-cb6e574cb86d4a97e7a9cc6ae79f181476188b21.zip
Simple tests for fmemopen(3) and open_memstream(3)
Diffstat (limited to 'src/regress/lib/libc/fmemopen')
-rw-r--r--src/regress/lib/libc/fmemopen/Makefile5
-rw-r--r--src/regress/lib/libc/fmemopen/fmemopentest.c68
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
3PROG= 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
24int
25main(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}