patch-2.0.2 linux/fs/fcntl.c
Next file: linux/fs/open.c
Previous file: linux/fs/exec.c
Back to the patch index
Back to the overall index
- Lines: 34
- Date:
Thu Jul 4 21:23:45 1996
- Orig file:
v2.0.1/linux/fs/fcntl.c
- Orig date:
Sun May 5 08:52:03 1996
diff -u --recursive --new-file v2.0.1/linux/fs/fcntl.c linux/fs/fcntl.c
@@ -13,23 +13,24 @@
#include <linux/fcntl.h>
#include <linux/string.h>
+#include <asm/bitops.h>
+
extern int sock_fcntl (struct file *, unsigned int cmd, unsigned long arg);
static inline int dupfd(unsigned int fd, unsigned int arg)
{
- if (fd >= NR_OPEN || !current->files->fd[fd])
+ struct files_struct * files = current->files;
+
+ if (fd >= NR_OPEN || !files->fd[fd])
return -EBADF;
if (arg >= NR_OPEN)
return -EINVAL;
- while (arg < NR_OPEN)
- if (current->files->fd[arg])
- arg++;
- else
- break;
- if (arg >= NR_OPEN)
+ arg = find_next_zero_bit(&files->open_fds, NR_OPEN, arg);
+ if (arg >= current->rlim[RLIMIT_NOFILE].rlim_cur)
return -EMFILE;
- FD_CLR(arg, ¤t->files->close_on_exec);
- (current->files->fd[arg] = current->files->fd[fd])->f_count++;
+ FD_SET(arg, &files->open_fds);
+ FD_CLR(arg, &files->close_on_exec);
+ (files->fd[arg] = files->fd[fd])->f_count++;
return arg;
}
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov