From a353f02a7ac4504ad5edb5407278c7a03c507aef Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 25 Mar 2023 12:14:36 -0700 Subject: If O_CLOEXEC is defined, add "e" to fopen modes Signed-off-by: Alan Coopersmith --- src/cursor.c | 4 ++-- src/file.c | 12 ++++++------ src/library.c | 4 ++-- src/xcursorint.h | 7 +++++++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/cursor.c b/src/cursor.c index 8dd61a0..2e4d821 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -146,7 +146,7 @@ _XcursorPixelToColor (XcursorPixel p, XColor *color) static void _XcursorDumpImage (XImage *image) { - FILE *f = fopen ("/tmp/images", "a"); + FILE *f = fopen ("/tmp/images", "a" FOPEN_CLOEXEC); int x, y; if (!f) return; @@ -164,7 +164,7 @@ _XcursorDumpImage (XImage *image) static void _XcursorDumpColor (XColor *color, char *name) { - FILE *f = fopen ("/tmp/images", "a"); + FILE *f = fopen ("/tmp/images", "a" FOPEN_CLOEXEC); fprintf (f, "%s: %x %x %x\n", name, color->red, color->green, color->blue); fflush (f); diff --git a/src/file.c b/src/file.c index dacbf5c..0e26955 100644 --- a/src/file.c +++ b/src/file.c @@ -1019,7 +1019,7 @@ XcursorFilenameLoadImage (const char *file, int size) if (!file || size < 0) return NULL; - f = fopen (file, "r"); + f = fopen (file, "r" FOPEN_CLOEXEC); if (!f) return NULL; image = XcursorFileLoadImage (f, size); @@ -1036,7 +1036,7 @@ XcursorFilenameLoadImages (const char *file, int size) if (!file || size < 0) return NULL; - f = fopen (file, "r"); + f = fopen (file, "r" FOPEN_CLOEXEC); if (!f) return NULL; images = XcursorFileLoadImages (f, size); @@ -1053,7 +1053,7 @@ XcursorFilenameLoadAllImages (const char *file) if (!file) return NULL; - f = fopen (file, "r"); + f = fopen (file, "r" FOPEN_CLOEXEC); if (!f) return NULL; images = XcursorFileLoadAllImages (f); @@ -1072,7 +1072,7 @@ XcursorFilenameLoad (const char *file, if (!file) return XcursorFalse; - f = fopen (file, "r"); + f = fopen (file, "r" FOPEN_CLOEXEC); if (!f) return 0; ret = XcursorFileLoad (f, commentsp, imagesp); @@ -1089,7 +1089,7 @@ XcursorFilenameSaveImages (const char *file, const XcursorImages *images) if (!file || !images) return XcursorFalse; - f = fopen (file, "w"); + f = fopen (file, "w" FOPEN_CLOEXEC); if (!f) return 0; ret = XcursorFileSaveImages (f, images); @@ -1107,7 +1107,7 @@ XcursorFilenameSave (const char *file, if (!file || !comments || !images) return XcursorFalse; - f = fopen (file, "w"); + f = fopen (file, "w" FOPEN_CLOEXEC); if (!f) return 0; ret = XcursorFileSave (f, comments, images); diff --git a/src/library.c b/src/library.c index c8fa2c5..eeba35d 100644 --- a/src/library.c +++ b/src/library.c @@ -172,7 +172,7 @@ _XcursorThemeInherits (const char *full) if (!full) return NULL; - f = fopen (full, "r"); + f = fopen (full, "r" FOPEN_CLOEXEC); if (f) { while (fgets (line, sizeof (line), f)) @@ -254,7 +254,7 @@ XcursorScanTheme (const char *theme, const char *name) full = _XcursorBuildFullname (dir, "cursors", name); if (full) { - f = fopen (full, "r"); + f = fopen (full, "r" FOPEN_CLOEXEC); free (full); } if (!f && inherits[d + 1].line == NULL) diff --git a/src/xcursorint.h b/src/xcursorint.h index d8f9ea3..121fb29 100644 --- a/src/xcursorint.h +++ b/src/xcursorint.h @@ -38,6 +38,13 @@ #include "Xcursor.h" #include "config.h" +#include +#ifdef O_CLOEXEC +#define FOPEN_CLOEXEC "e" +#else +#define FOPEN_CLOEXEC "" +#endif + typedef struct _XcursorFontInfo { struct _XcursorFontInfo *next; Font font; -- cgit v1.2.3