standard read_file()
- Posted by c.k.lester <euphoric at cklest??.com> Apr 23, 2008
- 678 views
Jeremy, the read_file() function in EusLibs and the new one in file.e are giving different results. I don't know which one is valid, though. The code for the EusLibs version is below. The only significant difference I see is that EusLibs reads it in binary mode, while the standard one does not.
-- read_file(object f) -- returns the contents of file /f -- /f can be a filename or a file number as returned by open() -- -1 is returned if failed global function euslibs_read_file(object f) object fn, ret, kar, len if sequence(f) then len = file_length(f) if len = 0 then return "" elsif len < 0 then return -1 end if ret = repeat(0, len) fn = open(f, "rb") if fn < 0 then return -1 end if for i = 1 to len do ret[i] = getc(fn) end for close(fn) else ret = "" while 1 do kar = getc(f) if kar != -1 then ret &= kar else exit end if end while end if return ret end function