Stories
Slash Boxes
Comments

SoylentNews is people

Submission Preview

Link to Story

Learn Something Old Every Day, Part XII: Strange File Resizing on DOS

Accepted submission by owl at 2024-06-08 17:36:33
Software
http://www.os2museum.com/wp/learn-something-old-every-day-part-xii-strange-file-resizing-on-dos/ [os2museum.com]

Someone recently asked an interesting question: Why do Microsoft C and compatible DOS compilers have no truncate() and/or ftruncate() library functions? And how does one resize files on DOS?

OK, that’s actually two questions. The first one is easy enough to answer: Because XENIX had no truncate() or ftruncate() either. Instead, XENIX had a chsize() function which, sure enough, can be found in the Microsoft C libraries at least as far back as MS C 3.0 (early 1985).

The second question is rather more interesting. The way files are resized on DOS is moving the file pointer to the desired size by calling the LSEEK function (INT 21h/42h), and then calling the WRITE function (INT 21h/40h) with zero length (CX=0).

Now, this mechanism is rather curious, because the handle-based file API in DOS 2.0 was modeled on XENIX, yet on UNIX systems, the write() function asked to transfer zero bytes simply does nothing. If the mechanism didn’t come from XENIX, where did it come from?


Original Submission