summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-03-27 18:35:46 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-04-22 17:15:24 +0000
commit4524c578581b427145ae136844fc655a89e94777 (patch)
tree12d368ed993e0e98786af558bc92e1e39251b5bc /test
parentf131de92d6c4e2f62934e85b012287276ecf009c (diff)
downloadxorg-lib-libXpm-4524c578581b427145ae136844fc655a89e94777.tar.gz
Set close-on-exec when opening filesHEADmaster
Relies on platforms with O_CLOEXEC support following POSIX requirement to not copy the close-on-exec flag to the new fd in dup2(), but to leave it unset instead, since that's how fd's are passed to child processes to handled compressed files. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'test')
-rw-r--r--test/XpmRead.c6
-rw-r--r--test/XpmWrite.c6
2 files changed, 10 insertions, 2 deletions
diff --git a/test/XpmRead.c b/test/XpmRead.c
index df7a826..a231419 100644
--- a/test/XpmRead.c
+++ b/test/XpmRead.c
@@ -33,6 +33,10 @@
#include "TestAllFiles.h"
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
+
#ifndef g_assert_no_errno /* defined in glib 2.66 & later */
#define g_assert_no_errno(n) g_assert_cmpint(n, >=, 0)
#endif
@@ -147,7 +151,7 @@ TestReadFileToBuffer(const gchar *filepath)
g_assert_nonnull(buffer);
/* Read file ourselves and verify the data matches */
- g_assert_no_errno(fd = open(filepath, O_RDONLY));
+ g_assert_no_errno(fd = open(filepath, O_RDONLY | O_CLOEXEC));
while ((rd = read(fd, readbuf, sizeof(readbuf))) > 0) {
g_assert_cmpmem(b, rd, readbuf, rd);
b += rd;
diff --git a/test/XpmWrite.c b/test/XpmWrite.c
index 49b5b21..998b1bb 100644
--- a/test/XpmWrite.c
+++ b/test/XpmWrite.c
@@ -38,6 +38,10 @@
#include "TestAllFiles.h"
#include "CompareXpmImage.h"
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
+
#ifndef g_assert_no_errno /* defined in glib 2.66 & later */
#define g_assert_no_errno(n) g_assert_cmpint(n, >=, 0)
#endif
@@ -295,7 +299,7 @@ TestWriteFileFromBuffer(const gchar *filepath)
ssize_t rd;
/* Read file ourselves and verify the data matches */
- g_assert_no_errno(fd = open(newfilepath, O_RDONLY));
+ g_assert_no_errno(fd = open(newfilepath, O_RDONLY | O_CLOEXEC));
while ((rd = read(fd, readbuf, sizeof(readbuf))) > 0) {
g_assert_cmpmem(b, rd, readbuf, rd);
b += rd;