Xref: utzoo comp.lang.c:33469 comp.os.msdos.programmer:1846 Path: utzoo!attcan!uunet!wuarchive!cs.utexas.edu!rice!uupsi!sunic!news.funet.fi!tukki.jyu.fi!jyu.fi!otto From: otto@tukki.jyu.fi (Otto J. Makela) Newsgroups: comp.lang.c,comp.os.msdos.programmer Subject: Re: How do I SHORTEN a file without rewriting it? Message-ID: Date: 6 Nov 90 15:56:32 GMT References: <1162@bilver.UUCP> <747@csource.oz.au> <9505@jarthur.Claremont.EDU> Sender: news@tukki.jyu.fi (News articles) Followup-To: comp.lang.c Organization: Turing Police, Criminal AI section Lines: 26 In-Reply-To: dfoster@jarthur.Claremont.EDU's message of 2 Nov 90 23:48:53 GMT In article <9505@jarthur.Claremont.EDU> dfoster@jarthur.Claremont.EDU (Derek R. Foster) writes: In article <747@csource.oz.au> david@csource.oz.au (david nugent) writes: >In <1162@bilver.UUCP> alex@bilver.UUCP (Alex Matulich) writes: >[how do I shorten a file ?] >Write zero bytes at that position. [MeSsy-DOS only solution] If this works, it isn't documented in the Microsoft C manuals I have. (And believe me, I searched!) After SEVERAL calls to Microsoft, (Two seperate people told me it couldn't be done from either within C or through DOS! I thought these people were supposed to be knowledgeable!) and a great deal of loud cursing, I was finally led to the chsize() function. This seems to be the only way of doing this from within Microsoft C, (And I suspect Turbo C as well.) If you are using streams, you will probably have to close your stream, reopen the file using handles, chsize() it, close it again, reopen using streams... What a mess. But it works, and is better than (in my case) copying a 20-meg file to a shorter length... Look at the fileno() function in your manual (your library does have it, I hope). Returns the file descriptor (handle as it's called in MeSsy-DOS) for the given stream. -- /* * * Otto J. Makela * * * * * * * * * * * * * * * * * * */ /* Phone: +358 41 613 847, BBS: +358 41 211 562 (CCITT, Bell 24/12/300) */ /* Mail: Kauppakatu 1 B 18, SF-40100 Jyvaskyla, Finland, EUROPE */ /* * * Computers Rule 01001111 01001011 * * * * * * * * * * * * * * * * */