summaryrefslogtreecommitdiff
path: root/wmiistatus.c
diff options
context:
space:
mode:
authorMichael Stapelberg <michael+x200@stapelberg.de>2008-11-30 01:46:01 +0100
committerMichael Stapelberg <michael+x200@stapelberg.de>2008-11-30 01:46:01 +0100
commit9388ee56e183ccb0210f6ee03bdb2f4ee9f3ebcf (patch)
tree2665b55381339bd450795bddc61f444a715e7b90 /wmiistatus.c
parentd9ff643b1040e3e56545b2d1ba9f664b6c258f4e (diff)
Correctly open new files
Diffstat (limited to 'wmiistatus.c')
-rw-r--r--wmiistatus.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/wmiistatus.c b/wmiistatus.c
index 95cc2ef..6604533 100644
--- a/wmiistatus.c
+++ b/wmiistatus.c
@@ -102,9 +102,16 @@ static void cleanup_rbar_dir() {
static void create_file(const char *name) {
char pathbuf[strlen(wmii_path)+256+1];
int fd;
+ int flags = O_CREAT | O_WRONLY;
+ struct stat statbuf;
(void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name);
- if ((fd = open(pathbuf, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR)) < 0)
+
+ /* Overwrite file's contents if it exists */
+ if (stat(pathbuf, &statbuf) >= 0)
+ flags |= O_TRUNC;
+
+ if ((fd = open(pathbuf, flags, S_IRUSR | S_IWUSR)) < 0)
exit(EXIT_FAILURE);
if (use_colors) {
char *tmp = concat("#888888 ", wmii_normcolors);