Пример #1
0
        public static int ll_os_open(string name, int flags, int mode)
        {
            FileAccess f_access = get_file_access(flags);
            FileMode   f_mode   = get_file_mode(flags);
            FileStream stream;
            IFile      f;

            try {
                stream = new FileStream(name, f_mode, f_access, FileShare.ReadWrite);
            }
            catch (UnauthorizedAccessException e) {
                raise_OSError(Errno.EACCES, e.Message);
                return(-1);
            }
            catch (FileNotFoundException e) {
                raise_OSError(Errno.ENOENT, e.Message);
                return(-1);
            }
            catch (IOException e) {
                raise_OSError(Errno.EIO, e.Message);
                return(-1);
            }

            // - on Unix there is no difference between text and binary modes
            // - on Windows text mode means that we should convert '\n' from and to '\r\n'
            // - on Mac < OS9 text mode means that we should convert '\n' from and to '\r' -- XXX: TODO!
            if ((flags & O_BINARY) == 0 && System.Environment.NewLine == "\r\n")
            {
                f = new CRLFTextFile(stream);
            }
            else
            {
                f = new BinaryFile(stream);
            }

            fdcount++;
            FileDescriptors[fdcount] = f;
            return(fdcount);
        }
Пример #2
0
        public static int ll_os_open(string name, int flags, int mode)
        {
            FileAccess f_access = get_file_access(flags);
            FileMode f_mode = get_file_mode(flags);
            FileStream stream;
            IFile f;

            try {
                stream = new FileStream(name, f_mode, f_access, FileShare.ReadWrite);
            }
            catch(UnauthorizedAccessException e) {
                raise_OSError(Errno.EACCES, e.Message);
                return -1;
            }
            catch(FileNotFoundException e) {
                raise_OSError(Errno.ENOENT, e.Message);
                return -1;
            }
            catch(IOException e) {
                raise_OSError(Errno.EIO, e.Message);
                return -1;
            }

            // - on Unix there is no difference between text and binary modes
            // - on Windows text mode means that we should convert '\n' from and to '\r\n'
            // - on Mac < OS9 text mode means that we should convert '\n' from and to '\r' -- XXX: TODO!
            if ((flags & O_BINARY) == 0 && System.Environment.NewLine == "\r\n")
                f = new CRLFTextFile(stream);
            else
                f = new BinaryFile(stream);

            fdcount++;
            FileDescriptors[fdcount] = f;
            return fdcount;
        }