Example #1
0
        public static Record_Stat_Result ll_os_stat(string path)
        {
            if (path == "")
            {
                raise_OSError(Errno.ENOENT, "No such file or directory: ''");
            }

            FileInfo f;

            try {
                f = new FileInfo(path);
            }
            catch (System.ArgumentException e) {
                raise_OSError(Errno.EINVAL, e.Message);
                return(null);
            }
            catch (System.NotSupportedException e) {
                raise_OSError(Errno.EINVAL, e.Message);
                return(null);
            }
            catch (System.IO.IOException e) {
                raise_OSError(Errno.EINVAL, e.Message);
                return(null);
            }

            if (f.Exists)
            {
                Record_Stat_Result res = new Record_Stat_Result();
                TimeSpan           t   = File.GetLastWriteTime(path) - new DateTime(1970, 1, 1);
                res.item0 ^= S_IFREG;
                res.item6  = (int)f.Length;
                res.item8  = (int)t.TotalSeconds;
                return(res);
            }

            DirectoryInfo d = new DirectoryInfo(path);

            if (d.Exists)
            {
                Record_Stat_Result res = new Record_Stat_Result();
                res.item0 ^= S_IFDIR;
                return(res);
            }
            // path is not a file nor a dir, raise OSError
            raise_OSError(Errno.ENOENT, string.Format("No such file or directory: '{0}'", path));
            return(null); // never reached
        }
Example #2
0
        public static Record_Stat_Result ll_os_stat(string path)
        {
            if (path == "")
                raise_OSError(Errno.ENOENT, "No such file or directory: ''");

            FileInfo f;
            try {
                f = new FileInfo(path);
            }
            catch(System.ArgumentException e) {
                raise_OSError(Errno.EINVAL, e.Message);
                return null;
            }

            if (f.Exists) {
                Record_Stat_Result res = new Record_Stat_Result();
                TimeSpan t = File.GetLastWriteTime(path) - new DateTime(1970, 1, 1);
                res.item0 ^= S_IFREG;
                res.item6 = (int)f.Length;
                res.item8 = (int)t.TotalSeconds;
                return res;
            }

            DirectoryInfo d = new DirectoryInfo(path);
            if (d.Exists) {
                Record_Stat_Result res = new Record_Stat_Result();
                res.item0 ^= S_IFDIR;
                return res;
            }
            // path is not a file nor a dir, raise OSError
            raise_OSError(Errno.ENOENT, string.Format("No such file or directory: '{0}'", path));
            return null; // never reached
        }