diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-03-04 08:41:27 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-03-04 08:41:27 -0500 |
commit | 674768caa67722992a16fbe1453ce625fa149955 (patch) | |
tree | 2b1e6321552fe107a939fdd758683380539a0fcf | |
parent | a691ba8c27d71fc4887500abe677a01809727600 (diff) | |
download | stasis-674768caa67722992a16fbe1453ce625fa149955.tar.gz |
xmkstemp allow setting file mode
* add usage comment function
-rw-r--r-- | include/utils.h | 17 | ||||
-rw-r--r-- | src/deliverable.c | 2 | ||||
-rw-r--r-- | src/docker.c | 2 | ||||
-rw-r--r-- | src/system.c | 2 | ||||
-rw-r--r-- | src/utils.c | 4 |
5 files changed, 21 insertions, 6 deletions
diff --git a/include/utils.h b/include/utils.h index d32a123..52f4f2d 100644 --- a/include/utils.h +++ b/include/utils.h @@ -55,7 +55,22 @@ void debug_shell(); * @return system path to the temporary file * @return NULL on failure */ -char *xmkstemp(FILE **fp); +char *xmkstemp(FILE **fp, const char *mode); + +/** + * Is the path an empty directory structure? + * + * ```c + * if (isempty_dir("/some/path")) { + * fprintf(stderr, "The directory is is empty!\n"); + * } else { + * printf("The directory contains dirs/files\n"); + * } + * ``` + * + * @param path directory + * @return 0 = no, 1 = yes + */ int isempty_dir(const char *path); #endif //OMC_UTILS_H diff --git a/src/deliverable.c b/src/deliverable.c index 4397c1c..b935b64 100644 --- a/src/deliverable.c +++ b/src/deliverable.c @@ -1215,7 +1215,7 @@ void delivery_rewrite_spec(struct Delivery *ctx, char *filename) { msg(OMC_MSG_ERROR, "failed to generate release header string\n", filename); exit(1); } - tempfile = xmkstemp(&tp); + tempfile = xmkstemp(&tp, "w"); if (!tempfile || !tp) { msg(OMC_MSG_ERROR, "%s: unable to create temporary file\n", strerror(errno)); exit(1); diff --git a/src/docker.c b/src/docker.c index 49d8b08..dafdd58 100644 --- a/src/docker.c +++ b/src/docker.c @@ -79,7 +79,7 @@ char *docker_ident() { char line[PATH_MAX]; struct Process proc; - tempfile = xmkstemp(&fp); + tempfile = xmkstemp(&fp, "w"); if (!fp || !tempfile) { return NULL; } diff --git a/src/system.c b/src/system.c index 154bd87..17b9a13 100644 --- a/src/system.c +++ b/src/system.c @@ -15,7 +15,7 @@ int shell(struct Process *proc, char *args) { FILE *tp = NULL; char *t_name; - t_name = xmkstemp(&tp); + t_name = xmkstemp(&tp, "w"); if (!t_name || !tp) { return -1; } diff --git a/src/utils.c b/src/utils.c index d8cf929..2b4d275 100644 --- a/src/utils.c +++ b/src/utils.c @@ -470,12 +470,12 @@ void debug_shell() { exit(255); } -char *xmkstemp(FILE **fp) { +char *xmkstemp(FILE **fp, const char *mode) { char t_name[PATH_MAX]; sprintf(t_name, "%s/%s", globals.tmpdir, "OMC.XXXXXX"); int fd = mkstemp(t_name); - *fp = fdopen(fd, "w"); + *fp = fdopen(fd, mode); if (!*fp) { if (fd > 0) close(fd); |