How do I SHORTEN a file without rewriting it?
david nugent
david at csource.oz.au
Sat Nov 3 01:32:44 AEST 1990
In <1162 at bilver.UUCP> alex at 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 at csource.oz.au Uucp: ..!uunet!munnari!csource!david
More information about the Comp.lang.c
mailing list