1. readfile.e
- Posted by Alan Tu <ATU5713 at COMPUSERVE.COM>
Sep 18, 1998
-
Last edited Sep 19, 1998
This file includes two global functions. filesize(integer file_num)
returns the length of an open file. readfile(filename) opens a file
specified by a path, reads the file into a returned sequence, and closes
the file.
--readfile.e
include file.e
global function filesize(integer file_num)
integer seek_success, file_length, orig_position
orig_position =3D where(file_num)
seek_success =3D seek(file_num,-1)
file_length =3D where(file_num)
seek_success =3D seek(file_num,orig_position)
return file_length
end function
global function readfile(sequence filename)
sequence file
integer file_length, seek_success, file_num
file_num =3D open(filename, "rb")
file_length =3D filesize(file_num)
file =3D repeat(0,file_length)
seek_success =3D seek(file_num,0)
for i =3D 1 to file_length do
file[i] =3D getc(file_num)
end for
close(file_num)
return file
end function
--end readfile.e
--Alan
=