|
|
1.1.1.2 root 1: /*
2: * linux/fs/fcntl.c
3: *
4: * (C) 1991 Linus Torvalds
5: */
6:
1.1 root 7: #include <errno.h>
8: #include <fcntl.h>
1.1.1.4 ! root 9:
1.1 root 10: #include <sys/stat.h>
11:
1.1.1.4 ! root 12: #include <asm/segment.h>
! 13:
! 14: #include <linux/string.h>
! 15: #include <linux/sched.h>
! 16: #include <linux/kernel.h>
! 17:
1.1 root 18: extern int sys_close(int fd);
19:
20: static int dupfd(unsigned int fd, unsigned int arg)
21: {
22: if (fd >= NR_OPEN || !current->filp[fd])
23: return -EBADF;
24: if (arg >= NR_OPEN)
25: return -EINVAL;
26: while (arg < NR_OPEN)
27: if (current->filp[arg])
28: arg++;
29: else
30: break;
31: if (arg >= NR_OPEN)
32: return -EMFILE;
33: current->close_on_exec &= ~(1<<arg);
34: (current->filp[arg] = current->filp[fd])->f_count++;
35: return arg;
36: }
37:
38: int sys_dup2(unsigned int oldfd, unsigned int newfd)
39: {
1.1.1.3 root 40: if (newfd == oldfd)
41: return newfd;
1.1 root 42: sys_close(newfd);
43: return dupfd(oldfd,newfd);
44: }
45:
46: int sys_dup(unsigned int fildes)
47: {
48: return dupfd(fildes,0);
49: }
50:
51: int sys_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg)
52: {
53: struct file * filp;
54:
55: if (fd >= NR_OPEN || !(filp = current->filp[fd]))
56: return -EBADF;
57: switch (cmd) {
58: case F_DUPFD:
59: return dupfd(fd,arg);
60: case F_GETFD:
61: return (current->close_on_exec>>fd)&1;
62: case F_SETFD:
63: if (arg&1)
64: current->close_on_exec |= (1<<fd);
65: else
66: current->close_on_exec &= ~(1<<fd);
67: return 0;
68: case F_GETFL:
69: return filp->f_flags;
70: case F_SETFL:
71: filp->f_flags &= ~(O_APPEND | O_NONBLOCK);
72: filp->f_flags |= arg & (O_APPEND | O_NONBLOCK);
73: return 0;
74: case F_GETLK: case F_SETLK: case F_SETLKW:
1.1.1.3 root 75: return -ENOSYS;
1.1 root 76: default:
1.1.1.3 root 77: return -EINVAL;
1.1 root 78: }
79: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.