lib/internal: introduce service to open simple devices

This commit is contained in:
Philippe Gerum 2019-02-23 09:58:04 +01:00
parent a50d8e605d
commit 21c8e11add
2 changed files with 41 additions and 0 deletions

View File

@ -154,3 +154,42 @@ int open_evl_element(const char *type, const char *fmt, ...)
return efd;
}
int create_evl_file(const char *type)
{
char *devname;
int fd, ret;
ret = asprintf(&devname, "/dev/evenless/%s", type);
if (ret < 0)
return -ENOMEM;
fd = open(devname, O_RDWR);
if (fd < 0) {
ret = -errno;
goto fail;
}
ret = fcntl(fd, F_GETFD, 0);
if (ret < 0) {
ret = -errno;
goto fail_setfd;
}
ret = fcntl(fd, F_SETFD, ret | O_CLOEXEC);
if (ret) {
ret = -errno;
goto fail_setfd;
}
free(devname);
return fd;
fail_setfd:
close(fd);
fail:
free(devname);
return ret;
}

View File

@ -60,6 +60,8 @@ int open_evl_element_vargs(const char *type,
int open_evl_element(const char *type,
const char *path, ...);
int create_evl_file(const char *type);
extern int (*arch_clock_gettime)(clockid_t clk_id,
struct timespec *tp);