summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-05-24 20:40:01 +0200
committerBruno Haible <bruno@clisp.org>2020-05-24 21:20:51 +0200
commit48888b25625ddcdcc296e4cc1b0cd13e417e54f0 (patch)
tree972027baf7d082724f9b0ba3d4ad30bc21cea57f
parent10cb4be2a2114dd6fff347acc9841d7904636adf (diff)
downloadgnulib-48888b25625ddcdcc296e4cc1b0cd13e417e54f0.tar.gz
gnulib-48888b25625ddcdcc296e4cc1b0cd13e417e54f0.tar.bz2
fopen-gnu: Add tests.
* tests/test-fopen-gnu.c: New file. * modules/fopen-gnu-tests: New file.
-rw-r--r--ChangeLog4
-rw-r--r--modules/fopen-gnu-tests12
-rw-r--r--tests/test-fopen-gnu.c71
3 files changed, 87 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index fab0d875a5..d7c1e8d8a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2020-05-24 Bruno Haible <bruno@clisp.org>
+ fopen-gnu: Add tests.
+ * tests/test-fopen-gnu.c: New file.
+ * modules/fopen-gnu-tests: New file.
+
fopen-gnu: New module.
Suggested by Tim Rühsen <tim.ruehsen@gmx.de> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00119.html>.
diff --git a/modules/fopen-gnu-tests b/modules/fopen-gnu-tests
new file mode 100644
index 0000000000..9e4c4cad16
--- /dev/null
+++ b/modules/fopen-gnu-tests
@@ -0,0 +1,12 @@
+Files:
+tests/test-fopen-gnu.c
+tests/macros.h
+
+Depends-on:
+fcntl
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-fopen-gnu
+check_PROGRAMS += test-fopen-gnu
diff --git a/tests/test-fopen-gnu.c b/tests/test-fopen-gnu.c
new file mode 100644
index 0000000000..cae40421ab
--- /dev/null
+++ b/tests/test-fopen-gnu.c
@@ -0,0 +1,71 @@
+/* Test of opening a file stream.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2020. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdio.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "macros.h"
+
+#define BASE "test-fopen-gnu.t"
+
+int
+main (void)
+{
+ FILE *f;
+ int fd;
+ int flags;
+
+ /* Remove anything from prior partial run. */
+ unlink (BASE "file");
+
+ /* Create the file. */
+ f = fopen (BASE "file", "w");
+ ASSERT (f);
+ fd = fileno (f);
+ ASSERT (fd >= 0);
+ flags = fcntl (fd, F_GETFD);
+ ASSERT (flags >= 0);
+ ASSERT ((flags & FD_CLOEXEC) == 0);
+ ASSERT (fclose (f) == 0);
+
+ /* Create the file and check the 'e' mode. */
+ f = fopen (BASE "file", "we");
+ ASSERT (f);
+ fd = fileno (f);
+ ASSERT (fd >= 0);
+ flags = fcntl (fd, F_GETFD);
+ ASSERT (flags >= 0);
+ ASSERT ((flags & FD_CLOEXEC) != 0);
+ ASSERT (fclose (f) == 0);
+
+ /* Open the file and check the 'x' mode. */
+ f = fopen (BASE "file", "ax");
+ ASSERT (f == NULL);
+ ASSERT (errno == EEXIST);
+
+ /* Cleanup. */
+ ASSERT (unlink (BASE "file") == 0);
+
+ return 0;
+}

Return to:

Send suggestions and report system problems to the System administrator.