]> git.corax.cc Git - corax/commitdiff
sys/io: Add proc_get_fd() function implementation
authorMatthias Kruk <m@m10k.eu>
Sat, 15 Aug 2020 06:20:11 +0000 (15:20 +0900)
committerMatthias Kruk <m@m10k.eu>
Sat, 15 Aug 2020 06:20:11 +0000 (15:20 +0900)
sys/io/proc.c
sys/io/proc.h

index ef49397eb73b1b1ff842ee5da3e2f33a0d0a4563..781210236eb7f037da1e9bb37913b1129debe9a1 100644 (file)
@@ -235,3 +235,39 @@ int proc_add_fd(struct proc *proc, struct filedesc *fd)
 
        return(ret_val);
 }
+
+/*
+ * proc_get_fd() - Look up a file descriptor using its number
+ *
+ * SYNOPSIS
+ *  int proc_get_fd(struct proc *proc, const int fd, struct filedesc **dst);
+ *
+ * DESCRIPTION
+ *  The proc_get_fd() function retrieves the file descriptor structure that is associated with the
+ *  descriptor number `fd' in the process pointed to by `proc'. Upon success, the pointer pointed
+ *  to by `dst' will be adjusted to point to the file descriptor.
+ *
+ * RETURN VALUE
+ *  Upon success, zero is returned. Otherwise, a negative error number is returned and the value
+ *  of `*dst' is undefined.
+ *
+ * ERRORS
+ *  -EINVAL Invalid arguments have been passed to the function
+ *  -ENOENT There is no file descriptor associated with the file descriptor number `fd'
+ */
+int proc_get_fd(struct proc *proc, const int fd, struct filedesc **dst)
+{
+       int ret_val;
+
+       ret_val = -EINVAL;
+
+       if(proc && fd >= 0 && dst) {
+               ret_val = -ENOENT;
+
+               if(!cx_array_get(proc->p_fds, fd, (void**)dst)) {
+                       ret_val = 0;
+               }
+       }
+
+       return(ret_val);
+}
index 858882340b59bfc45d80baf3bcb0406c355de0c8..7836544338abd68d86f57b2b66200682f759e49e 100644 (file)
@@ -12,5 +12,6 @@ int proc_new(const pid_t, struct proc**);
 void proc_free(struct proc*);
 
 int proc_add_fd(struct proc*, struct filedesc*);
+int proc_get_fd(struct proc*, const int, struct filedesc**);
 
 #endif /* PROC_H */