propagator/common.c
Led 1915f90346 add common mkdir_dev() and mkdirs_dev() funcs
mkdir_dev() use for create subdir with mode 0755 in /dev directory
and return success if subdir already exist.
mkdirs_dev() used mkdir_dev() for create multiple subdirs.
2013-11-06 20:34:29 +04:00

33 lines
565 B
C

#include <limits.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include "common.h"
int mkdir_dev(const char * name)
{
char pathname[PATH_MAX + 1] = "/dev/";
strcpy(pathname + 5, name);
return (mkdir(pathname, 0755) == 0 || errno == EEXIST) ? 0 : -1;
}
int mkdirs_dev(const char * name, ...)
{
va_list args;
int ret = 0;
va_start(args, name);
for (; name; name = va_arg(args, const char *))
if (mkdir_dev(name) && errno != EEXIST) {
ret = -1;
break;
}
va_end(args);
return ret;
}