cilibrar@athena.ecs.csus.edu (Rudi Cilibrasi) (05/05/91)
Suppose that I have a 100-byte file, and I want to get rid of the last ten bytes. Is there any way to do this other than freading in the entire file and then fwriting out only 90 bytes of it? I'd like to find a way to avoid having to read the whole file into memory. I've heard that there is a function called ftruncate that does this, but my compiler (Aztec C 5.0) doesn't have this one. (It also doesn't have chsize, which was another suggestion) Thanks for any help.
dillon@overload.Berkeley.CA.US (Matthew Dillon) (05/06/91)
In article <1991May5.063352.6627@csusac.csus.edu> cilibrar@athena.ecs.csus.edu (Rudi Cilibrasi) writes: >Suppose that I have a 100-byte file, and I want to get rid of the last >ten bytes. Is there any way to do this other than freading in the >entire file and then fwriting out only 90 bytes of it? I'd like to find >a way to avoid having to read the whole file into memory. I've heard >that there is a function called ftruncate that does this, but my >compiler (Aztec C 5.0) doesn't have this one. (It also doesn't have >chsize, which was another suggestion) Thanks for any help. Under 2.0 there is a filesystem call, SetFileSize(), that will truncate or extend a file as requested. Under 1.3 you have to rewrite the file. -Matt -- Matthew Dillon dillon@Overload.Berkeley.CA.US 891 Regal Rd. uunet.uu.net!overload!dillon Berkeley, Ca. 94708 USA
jap@convex.cl.msu.edu (Joe Porkka) (05/06/91)
dillon@overload.Berkeley.CA.US (Matthew Dillon) writes: >In article <1991May5.063352.6627@csusac.csus.edu> cilibrar@athena.ecs.csus.edu (Rudi Cilibrasi) writes: >>Suppose that I have a 100-byte file, and I want to get rid of the last >>ten bytes. Is there any way to do this other than freading in the > Under 2.0 there is a filesystem call, SetFileSize(), that will > truncate or extend a file as requested. Under 1.3 you have to > rewrite the file. The 1.3 FastFileSystem does support the truncate file packet, but there is no dos.library call for it. So if you are using 1.3FFS you can send a truncate packet to the filesystem directly. Check "pickpacket" (on a fish disk I think) for examples of how to send dos poackets.