Ejemplo n.º 1
0
        public static int SysOpen(RubyClass /*!*/ self, [NotNull] MutableString path, [Optional] MutableString mode, [Optional] int perm)
        {
            if (RubyFileOps.DirectoryExists(self.Context, path))
            {
                // TODO: What file descriptor should be returned for a directory?
                return(-1);
            }
            RubyIO io       = new RubyFile(self.Context, path.ToString(), IOModeEnum.Parse(mode));
            int    fileDesc = io.GetFileDescriptor();

            io.Close();
            return(fileDesc);
        }
Ejemplo n.º 2
0
        public static IOInfo Parse(RubyContext /*!*/ context, MutableString /*!*/ modeAndEncoding)
        {
            if (!modeAndEncoding.IsAscii())
            {
                throw IOModeEnum.IllegalMode(modeAndEncoding.ToAsciiString());
            }

            string[] parts = modeAndEncoding.ToString().Split(':');
            return(new IOInfo(
                       IOModeEnum.Parse(parts[0]),
                       (parts.Length > 1) ? TryParseEncoding(context, parts[1]) : null,
                       (parts.Length > 2) ? TryParseEncoding(context, parts[2]) : null
                       ));
        }
Ejemplo n.º 3
0
 public static RubyFile /*!*/ CreateFile(RubyClass /*!*/ self, [NotNull] MutableString /*!*/ path, MutableString mode)
 {
     return(new RubyFile(self.Context, path, IOModeEnum.Parse(mode)));
 }
Ejemplo n.º 4
0
 public static RubyFile /*!*/ CreateFile(RubyClass /*!*/ self,
                                         [DefaultProtocol, NotNull] Union <int, MutableString> descriptorOrPath, [Optional, DefaultProtocol] MutableString mode, [Optional] int permission)
 {
     if (descriptorOrPath.IsFixnum())
     {
         return(new RubyFile(
                    self.Context, RubyIOOps.GetDescriptorStream(self.Context, descriptorOrPath.Fixnum()), descriptorOrPath.Fixnum(), IOModeEnum.Parse(mode)
                    ));
     }
     else
     {
         // TODO: permissions
         return(CreateFile(self, descriptorOrPath.Second, mode));
     }
 }
Ejemplo n.º 5
0
 public static IOMode Parse(MutableString mode, IOMode defaultMode)
 {
     return((mode != null) ? IOModeEnum.Parse(mode.ToString()) : defaultMode);
 }
Ejemplo n.º 6
0
 public static RubyIO /*!*/ Reinitialize(RubyIO /*!*/ self, [DefaultProtocol] int descriptor,
                                         [DefaultProtocol, Optional, NotNull] MutableString mode)
 {
     return(Reinitialize(self, descriptor, (int)IOModeEnum.Parse(mode)));
 }
Ejemplo n.º 7
0
 public static RubyIO /*!*/ OpenPipe(RubyContext /*!*/ context, RubyClass /*!*/ self,
                                     [DefaultProtocol, NotNull] MutableString /*!*/ command, [DefaultProtocol, Optional, NotNull] MutableString modeString)
 {
     return(OpenPipe(context, command, IOModeEnum.Parse(modeString)));
 }
Ejemplo n.º 8
0
 public static RubyIO /*!*/ Reopen(RubyIO /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ path,
                                   [DefaultProtocol, Optional, NotNull] MutableString mode)
 {
     return(Reopen(self, path, (int)IOModeEnum.Parse(mode, self.Mode)));
 }