]> git.corax.cc Git - corax/commitdiff
sys/io: Add fd_read() and fd_write() wrapper functions for performing reads and write...
authorMatthias Kruk <m@m10k.eu>
Sat, 15 Aug 2020 06:24:03 +0000 (15:24 +0900)
committerMatthias Kruk <m@m10k.eu>
Sat, 15 Aug 2020 06:24:03 +0000 (15:24 +0900)
sys/io/filedesc.c
sys/io/filedesc.h

index 9c7f40e1e539213fdd348981c72c5e42148cbc72..78cd5700c133c0a1b2ad983a97661e4ad7e12ae9 100644 (file)
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <errno.h>
 #include "filedesc.h"
+#include "file.h"
 
 struct file;
 
@@ -236,3 +237,57 @@ int fd_unref(struct filedesc *fd)
 
        return(ret_val);
 }
+
+/*
+ * fd_read() - Read data from a file descriptor
+ *
+ * SYNOPSIS
+ *  ssize_t fd_read(struct filedesc *fd, void *dst, const size_t dst_size);
+ *
+ * DESCRIPTION
+ *  The fd_read() function attempts to read up to `dst_size' bytes of data from the file
+ *  descriptor pointed to by `fd' and writes it to the buffer pointed to by `dst'.
+ *
+ *  This function is the abstract interface to the file-specific read function. For implementation
+ *  details, please refer to the documentation of the more specific read function (for example
+ *  _pipe_read() for pipes).
+ *
+ * RETURN VALUE
+ *  Upon success, the number of bytes read is returned. Otherwise, a negative error number is
+ *  returned.
+ *
+ * ERRORS
+ *  For possible errors, please refer to the documentation of the read function for the respective
+ *  file type.
+ */
+ssize_t fd_read(struct filedesc *fd, void *dst, const size_t dst_size)
+{
+       return(file_read(fd->fd_file, dst, dst_size));
+}
+
+/*
+ * fd_write() - Write data to a file descriptor
+ *
+ * SYNOPSIS
+ *  ssize_t fd_write(struct filedesc *fd, const void *src, const size_t src_len);
+ *
+ * DESCRIPTION
+ *  The fd_write() function attempts to write up to `src_len' bytes from the buffer pointed to by
+ *  `src' and write that data to the file descriptor pointed to by `fd'.
+ *
+ *  This function is the abstract interface to the file-specific write function. For
+ *  implementation details, please refer to the documentation of the more specific write function
+ *  (for example _pipe_write() for pipes).
+ *
+ * RETURN VALUE
+ *  Upon success, the number of bytes read is returned. Otherwise a negative error number is
+ *  returned.
+ *
+ * ERRORS
+ *  For possible errors, please refer to the documentation of the write function for the
+ *  respective file type.
+ */
+ssize_t fd_write(struct filedesc *fd, const void *src, const size_t src_len)
+{
+       return(file_write(fd->fd_file, src, src_len));
+}
index 3f4d84bb8e00ce4e58f079a170d64ca4b84b7030..f4b08e80cd4f234860e60755236e17914c12222a 100644 (file)
@@ -30,4 +30,7 @@ int fd_set_file(struct filedesc*, struct file*);
 int fd_ref(struct filedesc*);
 int fd_unref(struct filedesc*);
 
+ssize_t fd_read(struct filedesc*, void*, const size_t);
+ssize_t fd_write(struct filedesc*, const void*, const size_t);
+
 #endif /* FILEDESC_H */