Browse Source

* fixed the filesize() problems under linux and filerec.size=0 error

peter 27 years ago
parent
commit
dbeb47f3bc
2 changed files with 19 additions and 6 deletions
  1. 8 2
      rtl/inc/file.inc
  2. 11 4
      rtl/linux/syslinux.pp

+ 8 - 2
rtl/inc/file.inc

@@ -208,7 +208,10 @@ Function FileSize(var f:File):Longint;[IOCheck];
   Return the size of file f in records
   Return the size of file f in records
 }
 }
 Begin
 Begin
-  FileSize:=Do_FileSize(FileRec(f).Handle) div FileRec(f).RecSize;
+  if FileRec(f).RecSize=0 then
+   FileSize:=0
+  else 
+   FileSize:=Do_FileSize(FileRec(f).Handle) div FileRec(f).RecSize;
 End;
 End;
 
 
 
 
@@ -291,7 +294,10 @@ End;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.3  1998-05-21 19:30:56  peter
+  Revision 1.4  1998-06-23 16:57:16  peter
+    * fixed the filesize() problems under linux and filerec.size=0 error
+
+  Revision 1.3  1998/05/21 19:30:56  peter
     * objects compiles for linux
     * objects compiles for linux
     + assign(pchar), assign(char), rename(pchar), rename(char)
     + assign(pchar), assign(char), rename(pchar), rename(char)
     * fixed read_text_as_array
     * fixed read_text_as_array

+ 11 - 4
rtl/linux/syslinux.pp

@@ -253,7 +253,7 @@ begin
  Sys_ENAMETOOLONG,
  Sys_ENAMETOOLONG,
     Sys_ELOOP,
     Sys_ELOOP,
   Sys_ENOTDIR : Inoutres:=3;
   Sys_ENOTDIR : Inoutres:=3;
-    Sys_EROFS : Inoutres:=150;
+    Sys_EROFS,
    Sys_EEXIST,
    Sys_EEXIST,
    Sys_EACCES : Inoutres:=5;
    Sys_EACCES : Inoutres:=5;
   Sys_ETXTBSY : Inoutres:=162;
   Sys_ETXTBSY : Inoutres:=162;
@@ -366,7 +366,7 @@ Begin
   if SysCall(SysCall_nr_fstat,regs)=0 then
   if SysCall(SysCall_nr_fstat,regs)=0 then
    Do_FileSize:=Info.Size
    Do_FileSize:=Info.Size
   else
   else
-   Do_FileSize:=-1;
+   Do_FileSize:=0;
   Errno2Inoutres;
   Errno2Inoutres;
 {$endif}
 {$endif}
 End;
 End;
@@ -425,7 +425,6 @@ Begin
          oflags :=Open_WRONLY;
          oflags :=Open_WRONLY;
          FileRec(f).mode:=fmoutput;
          FileRec(f).mode:=fmoutput;
        end;
        end;
-
    2 : begin
    2 : begin
          oflags :=Open_RDWR;
          oflags :=Open_RDWR;
          FileRec(f).mode:=fminout;
          FileRec(f).mode:=fminout;
@@ -458,6 +457,11 @@ Begin
    InOutRes:=0;
    InOutRes:=0;
 {$else}
 {$else}
   FileRec(f).Handle:=sys_open(p,oflags,438);
   FileRec(f).Handle:=sys_open(p,oflags,438);
+  if (ErrNo=Sys_EROFS) and ((OFlags and Open_RDWR)<>0) then
+   begin
+     Oflags:=Oflags and not(Open_RDWR);
+     FileRec(f).Handle:=sys_open(p,oflags,438);
+   end;     
   Errno2Inoutres;
   Errno2Inoutres;
 {$endif}
 {$endif}
 End;
 End;
@@ -661,7 +665,10 @@ End.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.4  1998-05-30 14:18:43  peter
+  Revision 1.5  1998-06-23 16:57:17  peter
+    * fixed the filesize() problems under linux and filerec.size=0 error
+
+  Revision 1.4  1998/05/30 14:18:43  peter
     * fixed to remake with -Rintel in the ppc386.cfg
     * fixed to remake with -Rintel in the ppc386.cfg
 
 
   Revision 1.3  1998/05/12 10:42:48  peter
   Revision 1.3  1998/05/12 10:42:48  peter