DEADSOFTWARE

add osx-ppc support via cpfront
[cpc.git] / src / posix / generic / Host / Mod / Files.cp
index 19517f242be6beb03c5d0e9d36b8c4ba6c80b1ed..76c7a5b8f8b3e096ebedf2748683ef6a4a4b9cbb 100644 (file)
@@ -1,11 +1,12 @@
 MODULE HostFiles;
 
-  IMPORT S := SYSTEM, Kernel, HostLang, Files, Log, stdlib := C99stdlib,
-    unistd := C99unistd, dirent := C99dirent, fcntl := C99fcntl,
-    sysstat := C99sys_stat, stdio := C99stdio, errno := C99errno,
-    macro := C99macro, libgen := C99libgen, time := C99time;
+  IMPORT S := SYSTEM, Kernel, HostLang, Files, Log, stdlib := PosixCstdlib,
+    unistd := PosixCunistd, dirent := PosixCdirent, fcntl := PosixCfcntl,
+    sysstat := PosixCsys_stat, stdio := PosixCstdio, errno := PosixCerrno,
+    macro := PosixCmacro, libgen := PosixClibgen, time := PosixCtime;
 
   (* !!! add buffer cache *)
+  (* !!! HostFiles64 must be base for HostFiles *)
 
   CONST
     closed = 0; new = 1; temp = 2; shared = 3; exclusive = 4;
@@ -22,7 +23,7 @@ MODULE HostFiles;
 
     File = POINTER TO RECORD (Files.File)
       state: INTEGER;
-      len: INTEGER;
+      len: INTEGER; (* !!! must be sysstat.off_t *)
       fd: unistd.int;
       ino: sysstat.ino_t;
       pathname: FullName
@@ -141,7 +142,7 @@ MODULE HostFiles;
   PROCEDURE (f: File) Flush;
     VAR res: unistd.int;
   BEGIN
-    IF f.state # closed THEN
+    IF f.state = exclusive THEN
       res := unistd.fsync(f.fd);
       ASSERT(res = 0, 100)
     END
@@ -179,11 +180,11 @@ MODULE HostFiles;
     ASSERT(f.state = new, 20);
     ASSERT(name # "", 21);
     ASSERT(IsName(name), 22);
-    HostLang.StringToHost(f.pathname, p0, FALSE, err);
+    HostLang.StringToHost(f.pathname, p0, HostLang.pep383, err);
     IF err = 0 THEN
       dir := f.pathname$;
       DirName(dir);
-      HostLang.StringToHost(dir + "/" + name, p1, FALSE, err);
+      HostLang.StringToHost(dir + "/" + name, p1, HostLang.pep383, err);
       IF err = 0 THEN
         x := stdio.rename(p0, p1);
         IF x = 0 THEN res := 0 (* no error *)
@@ -205,7 +206,7 @@ MODULE HostFiles;
     IF f.state # closed THEN
       f.Flush;
       IF f.state = new THEN
-        HostLang.StringToHost(f.pathname, path, FALSE, err);
+        HostLang.StringToHost(f.pathname, path, HostLang.pep383, err);
         ASSERT(err = 0, 100);
         res := unistd.unlink(path);
         ASSERT(res = 0, 101);
@@ -339,7 +340,7 @@ MODULE HostFiles;
     VAR i: INTEGER; sep: BOOLEAN; err: unistd.int; s: sysstat.struct_stat; mode: sysstat.mode_t;
   BEGIN
     i := 0; err := 0;
-    mode := ORD(BITS(511(*a=rwx*)) - BITS(sysstat.umask(0)));
+    mode := S.VAL((*!!!*)sysstat.mode_t, ORD(BITS(511(*a=rwx*)) - BITS(sysstat.umask(0))));
     WHILE (err = 0) & (path[i] # 0X) DO
       WHILE (path[i] # "/") & (path[i] # 0X) DO INC(i) END;
       sep := path[i] = "/";
@@ -363,7 +364,7 @@ MODULE HostFiles;
   BEGIN
     ASSERT(loc # NIL, 20);
     WITH loc: Locator DO
-      HostLang.StringToHost(loc.path, pathname, FALSE, err);
+      HostLang.StringToHost(loc.path, pathname, HostLang.pep383, err);
       IF err = 0 THEN
         MakeDir(pathname, res);
         IF res = 0 THEN
@@ -371,7 +372,7 @@ MODULE HostFiles;
           pathname := pathname + "/" + ".newXXXXXX";
           fd := stdlib.mkstemp(pathname);
           IF fd # -1 THEN
-            NEW(f); HostLang.HostToString(pathname, f.pathname, FALSE, err);
+            NEW(f); HostLang.HostToString(pathname, f.pathname, HostLang.pep383, err);
             IF err = 0 THEN
               (* !!! get valid inode? *)
               f.fd := fd; f.len := 0; f.state := new; f.ino := 0;
@@ -421,14 +422,14 @@ MODULE HostFiles;
     ASSERT(name # "", 21);
     WITH loc: Locator DO
       IF IsName(name) THEN
-        HostLang.StringToHost(loc.path + "/" + name, pathname, FALSE, err);
+        HostLang.StringToHost(loc.path + "/" + name, pathname, HostLang.pep383, err);
         IF err = 0 THEN
           res := macro.stat(pathname, s);
           IF res = 0 THEN
             IF IsRegFile(s) THEN
               if := GetFileByInode(s.st_ino);
               IF (if = NIL) OR isShared & (if.state = shared) THEN
-                mode := ORD(BITS(rwrwrw) - BITS(sysstat.umask(0)));
+                mode := S.VAL((*!!!*)sysstat.mode_t, ORD(BITS(rwrwrw) - BITS(sysstat.umask(0))));
                 IF isShared THEN flags := fcntl.O_RDONLY
                 ELSE flags := fcntl.O_RDWR
                 END;
@@ -443,9 +444,9 @@ MODULE HostFiles;
                   lock.l_pid := 0;
                   res := fcntl.fcntl(fd, fcntl.F_SETLK, S.ADR(lock));
                   IF res # -1 THEN
-                    NEW(f); HostLang.HostToString(pathname, f.pathname, FALSE, err);
+                    NEW(f); HostLang.HostToString(pathname, f.pathname, HostLang.pep383, err);
                     IF err = 0 THEN
-                      f.fd := fd; f.len := s.st_size; f.ino := s.st_ino;
+                      f.fd := fd; f.len := S.VAL((*!!!*)INTEGER, s.st_size); f.ino := s.st_ino;
                       IF isShared THEN f.state := shared
                       ELSE f.state := exclusive
                       END;
@@ -501,7 +502,7 @@ MODULE HostFiles;
     ASSERT(IsName(name), 21);
     WITH loc: Locator DO
       IF IsName(name) THEN
-        HostLang.StringToHost(loc.path + "/" + name, pathname, FALSE, err);
+        HostLang.StringToHost(loc.path + "/" + name, pathname, HostLang.pep383, err);
         IF err = 0 THEN
           res := unistd.unlink(pathname);
           IF res = 0 THEN loc.res := 0 (* no error *)
@@ -526,9 +527,9 @@ MODULE HostFiles;
     ASSERT(new # "", 22);
     WITH loc: Locator DO
       IF IsName(old) & IsName(new) THEN
-        HostLang.StringToHost(loc.path + "/" + old, p0, FALSE, err);
+        HostLang.StringToHost(loc.path + "/" + old, p0, HostLang.pep383, err);
         IF err = 0 THEN
-          HostLang.StringToHost(loc.path + "/" + new, p1, FALSE, err);
+          HostLang.StringToHost(loc.path + "/" + new, p1, HostLang.pep383, err);
           IF err = 0 THEN
             res := stdio.rename(p0, p1);
             IF res = 0 THEN loc.res := 0 (* no error *)
@@ -559,11 +560,11 @@ MODULE HostFiles;
     WITH loc0: Locator DO
       WITH loc1: Locator DO
         IF IsName(name0) & IsName(name1) THEN
-          HostLang.StringToHost(loc0.path + "/" + name0, a0, FALSE, err);
+          HostLang.StringToHost(loc0.path + "/" + name0, a0, HostLang.pep383, err);
           IF err = 0 THEN
             err := macro.stat(a0, s0);
             IF err = 0 THEN
-              HostLang.StringToHost(loc1.path + "/" + name1, a1, FALSE, err);
+              HostLang.StringToHost(loc1.path + "/" + name1, a1, HostLang.pep383, err);
               IF err = 0 THEN
                 err := macro.stat(a1, s1);
                 IF err = 0 THEN
@@ -621,15 +622,15 @@ MODULE HostFiles;
   BEGIN
     ASSERT(loc # NIL, 20);
     WITH loc: Locator DO
-      HostLang.StringToHost(loc.path, pathname, FALSE, err);
+      HostLang.StringToHost(loc.path, pathname, HostLang.pep383, err);
       IF err = 0 THEN
         p := dirent.opendir(pathname);
         IF p # NIL THEN
           ent := dirent.readdir(p);
           WHILE ent # NIL DO
-            HostLang.HostToString(ent.d_name, name, FALSE, err);
+            HostLang.HostToString(ent.d_name, name, HostLang.pep383, err);
             IF err = 0 THEN
-              HostLang.StringToHost(loc.path + "/" + name, pathname, FALSE, err);
+              HostLang.StringToHost(loc.path + "/" + name, pathname, HostLang.pep383, err);
               IF err = 0 THEN
                 res := macro.stat(pathname, s);
                 IF (res = 0) & ~IsDir(s) THEN
@@ -638,7 +639,7 @@ MODULE HostFiles;
                   END;
                   t.name := name$;
                   t.type := ""; (* ??? *)
-                  t.length := s.st_size;
+                  t.length := S.VAL((*!!!*)INTEGER, s.st_size);
                   tm := time.localtime(s.st_mtim.tv_sec);
                   IF tm # NIL THEN
                     t.modified.year := tm.tm_year + 1900;
@@ -683,15 +684,15 @@ MODULE HostFiles;
   BEGIN
     ASSERT(loc # NIL, 20);
     WITH loc: Locator DO
-      HostLang.StringToHost(loc.path, pathname, FALSE, err);
+      HostLang.StringToHost(loc.path, pathname, HostLang.pep383, err);
       IF err = 0 THEN
         p := dirent.opendir(pathname);
         IF p # NIL THEN
           ent := dirent.readdir(p);
           WHILE ent # NIL DO
-            HostLang.HostToString(ent.d_name, name, FALSE, err);
+            HostLang.HostToString(ent.d_name, name, HostLang.pep383, err);
             IF err = 0 THEN
-              HostLang.StringToHost(loc.path + "/" + name, pathname, FALSE, err);
+              HostLang.StringToHost(loc.path + "/" + name, pathname, HostLang.pep383, err);
               IF err = 0 THEN
                 res := macro.stat(pathname, s);
                 IF (res = 0) & IsDir(s) & (name # ".") & (name # "..") THEN