diff options
-rw-r--r-- | src/AsciiSrc.c | 14 | ||||
-rw-r--r-- | src/MultiSrc.c | 15 | ||||
-rw-r--r-- | src/TextPop.c | 7 |
3 files changed, 27 insertions, 9 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", 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", diff --git a/src/TextPop.c b/src/TextPop.c index 6407c98..d47fbd4 100644 --- a/src/TextPop.c +++ b/src/TextPop.c @@ -68,6 +68,11 @@ in this Software without prior written authorization from the X Consortium. #include <X11/Xos.h> /* for O_RDONLY */ #include <errno.h> +#ifdef O_CLOEXEC +#define FOPEN_CLOEXEC "e" +#else +#define FOPEN_CLOEXEC "" +#endif #define INSERT_FILE ("Enter Filename:") @@ -274,7 +279,7 @@ InsertFileNamed(Widget tw, char *str) XawTextPosition pos; if ( (str == NULL) || (strlen(str) == 0) || - ((file = fopen(str, "r")) == NULL)) + ((file = fopen(str, "r" FOPEN_CLOEXEC)) == NULL)) return(FALSE); pos = XawTextGetInsertionPoint(tw); |