summaryrefslogtreecommitdiff
path: root/libio/test-fmemopen.c
diff options
context:
space:
mode:
Diffstat (limited to 'libio/test-fmemopen.c')
-rw-r--r--libio/test-fmemopen.c53
1 files changed, 51 insertions, 2 deletions
diff --git a/libio/test-fmemopen.c b/libio/test-fmemopen.c
index 63ca89f300..1e52e86ce5 100644
--- a/libio/test-fmemopen.c
+++ b/libio/test-fmemopen.c
@@ -1,5 +1,5 @@
/* Test for fmemopen implementation.
- Copyright (C) 2000-2015 Free Software Foundation, Inc.
+ Copyright (C) 2000-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Hanno Mueller, kontakt@hanno.de, 2000.
@@ -19,9 +19,56 @@
static char buffer[] = "foobar";
+#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <mcheck.h>
+
+static int
+do_bz18820 (void)
+{
+ char ch;
+ FILE *stream;
+
+ errno = 0;
+ stream = fmemopen (&ch, 1, "?");
+ if (stream)
+ {
+ printf ("fmemopen: expected NULL, got %p\n", stream);
+ fclose (stream);
+ return 1;
+ }
+ if (errno != EINVAL)
+ {
+ printf ("fmemopen: got %i, expected EINVAL (%i)\n", errno, EINVAL);
+ return 10;
+ }
+
+ stream = fmemopen (NULL, 42, "?");
+ if (stream)
+ {
+ printf ("fmemopen: expected NULL, got %p\n", stream);
+ fclose (stream);
+ return 2;
+ }
+
+ errno = 0;
+ stream = fmemopen (NULL, ~0, "w");
+ if (stream)
+ {
+ printf ("fmemopen: expected NULL, got %p\n", stream);
+ fclose (stream);
+ return 3;
+ }
+ if (errno != ENOMEM)
+ {
+ printf ("fmemopen: got %i, expected ENOMEM (%i)\n", errno, ENOMEM);
+ return 20;
+ }
+
+ return 0;
+}
static int
do_test (void)
@@ -30,6 +77,8 @@ do_test (void)
FILE *stream;
int ret = 0;
+ mtrace ();
+
stream = fmemopen (buffer, strlen (buffer), "r+");
while ((ch = fgetc (stream)) != EOF)
@@ -44,7 +93,7 @@ do_test (void)
fclose (stream);
- return ret;
+ return ret + do_bz18820 ();
}
#define TEST_FUNCTION do_test ()