diff options
author | sr | 2012-09-25 19:56:04 +0200 |
---|---|---|
committer | sr | 2012-09-25 19:56:04 +0200 |
commit | 5a329ef4cba5688842d7d945e5c5956109797e60 (patch) | |
tree | 720c56b41892e0e9772590d5e86fb3628fe2441f /src/server/helper.c | |
parent | [SERVER] IPC: Add calls to add/remove trusted namespaces and servers (diff) | |
download | dnbd3-5a329ef4cba5688842d7d945e5c5956109797e60.tar.gz dnbd3-5a329ef4cba5688842d7d945e5c5956109797e60.tar.xz dnbd3-5a329ef4cba5688842d7d945e5c5956109797e60.zip |
[SERVER] Fix return code for IPC_IMAGE_ADD
[SERVER] Check if image exists on IPC_IMAGE_ADD
Diffstat (limited to 'src/server/helper.c')
-rw-r--r-- | src/server/helper.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/server/helper.c b/src/server/helper.c index c86fcb6..e5f520a 100644 --- a/src/server/helper.c +++ b/src/server/helper.c @@ -3,6 +3,7 @@ #include <string.h> #include <stdlib.h> #include <glib/gmacros.h> +#include <fcntl.h> #include "../config.h" /** @@ -167,3 +168,28 @@ void remove_trailing_slash(char *string) while (ptr >= string && *ptr == '/') *ptr-- = '\0'; } + +int file_exists(char *file) +{ + int fd = open(file, O_RDONLY); + if (fd < 0) + return FALSE; + close(fd); + return TRUE; +} + +int file_writable(char *file) +{ + int fd = open(file, O_WRONLY); + if (fd >= 0) + { + close(fd); + return TRUE; + } + fd = open(file, O_WRONLY | O_CREAT, 0600); + if (fd < 0) + return FALSE; + close(fd); + unlink(file); + return TRUE; +} |