Xref: utzoo comp.lang.c:33354 comp.os.msdos.programmer:1777 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!munnari.oz.au!csource!david From: david@csource.oz.au (david nugent) Newsgroups: comp.lang.c,comp.os.msdos.programmer Subject: Re: How do I SHORTEN a file without rewriting it? Keywords: truncation Message-ID: <747@csource.oz.au> Date: 2 Nov 90 14:32:44 GMT References: <1162@bilver.UUCP> Organization: Unique Computing Pty Ltd, Melb, Aust. Lines: 52 In <1162@bilver.UUCP> alex@bilver.UUCP (Alex Matulich) writes: >Is there a way to shorten a file, that is, chop some data off the end of >it, so that it doesn't consume as much physical space on the disk? The >file I have is too big to read into memory and write back out again, and >there is not enough room on the disk to write out a temporary file. Write zero bytes at that position. Some C libraries have a chsize() function which does exactly that. Since those libraries also don't seem to allow writing of zero bytes you will need to create your own write function. chsize.c: int chsize (int fd, long newsize) { r = -1; if (lseek (fd, newsize, SEEK_SET) != -1L) r = _write (fd, NULL, 0); return r; } _write.asm: .model c,small .code _write PROC, fd:WORD, buf:PTR, count:WORD mov bx,[fd] mov cx,[count] mov dx,[buf] mov ah,40H int 21H jnc .W0 mov ax,-1 .W0: ret _write ENDP -- Fidonet: 3:632/348 SIGnet: 28:4100/1 Imex: 90:833/387 Data: +61-3-885-7864 Voice: +61-3-826-6711 Internet/ACSnet: david@csource.oz.au Uucp: ..!uunet!munnari!csource!david