diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-03-27 16:57:10 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-03-27 17:03:46 -0700 |
commit | 0e4641adfdaf74b366aded06fa584d81532f5954 (patch) | |
tree | 267271d27e145eb6ff4f317e6813aa835d623048 /src/MultiSrc.c | |
parent | a3b9a4efba1737df15bb6acaf6621622ab85b929 (diff) |
Set close-on-exec when opening files
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'src/MultiSrc.c')
-rw-r--r-- | src/MultiSrc.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/MultiSrc.c b/src/MultiSrc.c index 22d9c16..df85339 100644 --- a/src/MultiSrc.c +++ b/src/MultiSrc.c @@ -76,6 +76,13 @@ in this Software without prior written authorization from the X Consortium. #include <ctype.h> #include <errno.h> +#ifdef O_CLOEXEC +#define FOPEN_CLOEXEC "e" +#else +#define FOPEN_CLOEXEC "" +#define O_CLOEXEC 0 +#endif + /**************************************************************** * * Full class record constant @@ -966,7 +973,7 @@ WriteToFile(String string, String name) int fd; Bool result = True; - if ((fd = creat(name, 0666)) == -1) + if ((fd = open(name, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0666)) == -1) return(FALSE); if (write(fd, string, sizeof(unsigned char) * strlen(string)) == -1) @@ -1084,7 +1091,7 @@ InitStringOrFile(MultiSrcObject src, Boolean newString) XtErrorMsg("NoFile", "multiSourceCreate", "XawError", "Creating a read only disk widget and no file specified.", NULL, 0); - open_mode = "r"; + open_mode = "r" FOPEN_CLOEXEC; break; case XawtextAppend: case XawtextEdit: @@ -1097,9 +1104,9 @@ InitStringOrFile(MultiSrcObject src, Boolean newString) (void) tmpnam(src->multi_src.string); src->multi_src.is_tempfile = TRUE; - open_mode = "w"; + open_mode = "w" FOPEN_CLOEXEC; } else - open_mode = "r+"; + open_mode = "r+" FOPEN_CLOEXEC; break; default: XtErrorMsg("badMode", "multiSourceCreate", "XawError", |