[source navigation] [diff markup] [identifier search] [freetext search] [file search]

Oldlinux Cross Reference
Linux/fs/fcntl.c

Version: [1.0] [0.99.11] [0.99] [0.98] [0.97] [0.96a] [0.95] [0.12] [0.11] [0.01]
Architecture: [i386]

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

[source navigation] [diff markup] [identifier search] [freetext search] [file search]

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.