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/AsciiSrc.c | |
parent | a3b9a4efba1737df15bb6acaf6621622ab85b929 (diff) |
Set close-on-exec when opening files
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'src/AsciiSrc.c')
-rw-r--r-- | src/AsciiSrc.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/AsciiSrc.c b/src/AsciiSrc.c index 293f277..f069480 100644 --- a/src/AsciiSrc.c +++ b/src/AsciiSrc.c @@ -55,6 +55,12 @@ in this Software without prior written authorization from the X Consortium. # include <X11/Xaw3d/AsciiText.h> /* for Widget Classes. */ #endif +#ifdef O_CLOEXEC +#define FOPEN_CLOEXEC "e" +#else +#define FOPEN_CLOEXEC "" +#define O_CLOEXEC 0 +#endif /**************************************************************** * @@ -907,7 +913,7 @@ WriteToFile(_Xconst _XtString string, _Xconst _XtString name) { int fd; - 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) { @@ -1006,7 +1012,7 @@ InitStringOrFile(AsciiSrcObject src, Boolean newString) XtErrorMsg("NoFile", "asciiSourceCreate", "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: @@ -1014,9 +1020,9 @@ InitStringOrFile(AsciiSrcObject src, Boolean newString) src->ascii_src.string = fileName; (void) tmpnam(src->ascii_src.string); src->ascii_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", "asciiSourceCreate", "XawError", |