]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
new helpers: fdget()/fdput()
authorAl Viro <viro@zeniv.linux.org.uk>
Mon, 27 Aug 2012 23:55:01 +0000 (19:55 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Thu, 6 Sep 2012 13:49:15 +0000 (09:49 -0400)
Signed-off-bs: Al Viro <viro@zeniv.linux.org.uk>

include/linux/file.h

index 6eee54aea2794c3da1af2ae7735228ba7050920f..45f10bbc3fc7fd16886cdd65d91706196dc661de 100644 (file)
@@ -26,8 +26,27 @@ static inline void fput_light(struct file *file, int fput_needed)
                fput(file);
 }
 
+struct fd {
+       struct file *file;
+       int need_put;
+};
+
+static inline void fdput(struct fd fd)
+{
+       if (fd.need_put)
+               fput(fd.file);
+}
+
 extern struct file *fget(unsigned int fd);
 extern struct file *fget_light(unsigned int fd, int *fput_needed);
+
+static inline struct fd fdget(unsigned int fd)
+{
+       int b;
+       struct file *f = fget_light(fd, &b);
+       return (struct fd){f,b};
+}
+
 extern struct file *fget_raw(unsigned int fd);
 extern struct file *fget_raw_light(unsigned int fd, int *fput_needed);
 extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);