How do I SHORTEN a file without rewriting it?

Otto J. Makela otto at tukki.jyu.fi
Wed Nov 7 02:56:32 AEST 1990


In article <9505 at jarthur.Claremont.EDU> dfoster at jarthur.Claremont.EDU (Derek R. Foster) writes:
   In article <747 at csource.oz.au> david at csource.oz.au (david nugent) writes:
   >In <1162 at bilver.UUCP> alex at 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 <otto at jyu.fi> * * * * * * * * * * * * * * * * * * */
  /* 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 * * * * * * * * * * * * * * * * */



More information about the Comp.lang.c mailing list