Add is_writable() function to check whether a path is writable or not

This commit is contained in:
Christian Ruppert 2012-01-26 20:44:33 +01:00
parent de5cee2c21
commit 44019f6542
2 changed files with 16 additions and 0 deletions

View File

@ -36,6 +36,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define RC_LEVEL_BOOT "boot"
#define RC_LEVEL_DEFAULT "default"
@ -166,6 +167,12 @@ int svc_lock(const char *);
int svc_unlock(const char *, int);
pid_t exec_service(const char *, const char *);
/*
* Check whether path is writable or not,
* this also works properly with read-only filesystems
*/
int is_writable(const char *);
#define service_start(service) exec_service(service, "start");
#define service_stop(service) exec_service(service, "stop");

View File

@ -331,3 +331,12 @@ parse_mode(mode_t *mode, char *text)
errno = EINVAL;
return -1;
}
int
is_writable(const char *path)
{
if (access(path, W_OK) == 0)
return 1;
return 0;
}