diff options
author | Ahmad Fatoum <ahmad@a3f.at> | 2023-01-30 08:27:04 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2023-01-31 09:19:47 +0100 |
commit | 955df99f2a5ad7c56f7677d20f3018db14d7f142 (patch) | |
tree | 4a000062912ca8e815b07294f53aa95394778d30 /fs | |
parent | cc5666f23a1d84fba3c8765fc0c203e6746042ad (diff) | |
download | barebox-955df99f2a5ad7c56f7677d20f3018db14d7f142.tar.gz |
fs: devfs: implement cdev_fdopen
As an alternative to cdev_open and using cdev_read/write, we define a
new cdev_fdopen function that returns a file descriptor. The benefit of
this is that code using it may use all the more high level helpers we
have for reading/writing file descriptors.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
Link: https://lore.barebox.org/20230130072707.2423294-2-ahmad@a3f.at
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/devfs-core.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/fs/devfs-core.c b/fs/devfs-core.c index 2a259c2fe0..fbcf68e815 100644 --- a/fs/devfs-core.c +++ b/fs/devfs-core.c @@ -177,6 +177,26 @@ int cdev_open(struct cdev *cdev, unsigned long flags) return 0; } +int cdev_fdopen(struct cdev *cdev, unsigned long flags) +{ + char *path; + int fd; + + if (!cdev) + return -ENODEV; + if (IS_ERR(cdev)) + return PTR_ERR(cdev); + + path = basprintf("/dev/%s", cdev->name); + if (!path) + return -ENOMEM; + + fd = open(path, flags); + + free(path); + return fd; +} + struct cdev *cdev_open_by_name(const char *name, unsigned long flags) { struct cdev *cdev; |