ddh@hare.cdc.com (Dan Horsfall) (03/20/91)
I have what would be a straightforward requirement, but for two "minor obstacles" that may force me to toss out an entire design and start over. Hopefully, the wisdom that comes only from experience can help me out here! I need an I/O package for a Un*x variant OS, which implies but does NOT require language C. For basic functionality, it needs only to be able to read and write arbitrary byte-streams to or from arbitrary byte addresses/offsets in a file. Supporting code (open and close) merely builds on top of that stuff, in my mind. Reading an existing file is trivial with stdio: seek to address, move bytes. Except for BA+LEN<EOF, there's not even error checking :-)! Writing poses some hurdles: 1) I'm told that stdio assumes EOF always follows the last byte written; thus rewriting a block into the middle of an existing file will likely trash the rest of it. 2) Writing to an offset beyond the previous EOF requires that "something" be done in the intervening gap. It _is_ legal to write to byte address 1,000,000 as the first operation on such a file. An ISAM package is overkill for this application. Any suggestions?? Anyone seen this done, in a piratable fashion?? Anybody actually got any source code they'd like to share, thus earning my undying gratitude for a finite period of time?? -- Horse + Control Data Corporation Dan Horsfall +1-612-482-4622 + 4201 Lexington Ave North Internet ddh@dash.udev.cdc.com + Arden Hills MN 55126 USA
mouse@thunder.mcrcim.mcgill.edu (der Mouse) (03/23/91)
In article <31503@shamash.cdc.com>, ddh@hare.cdc.com (Dan Horsfall) writes: > I need an I/O package for a Un*x variant [...]. For basic > functionality, it needs only to be able to read and write arbitrary > byte-streams to or from arbitrary byte addresses/offsets in a file. > Reading an existing file is trivial with stdio: seek to address, move > bytes. Except for BA+LEN<EOF, there's not even error checking :-)! > Writing poses some hurdles: My responses are based on the Berkeley stdio. I don't think anything I say is terribly Berkeley-specific, but y'never know. > 1) I'm told that stdio assumes EOF always follows the last byte > written; thus rewriting a block into the middle of an existing > file will likely trash the rest of it. Not so at all. You will need to take care when reading and writing the same file without closing and re-opening, but nothing more than a little care should be necessary; UNIX has always (at least since it escaped into the world) supported writing into the middle of an existing file. > 2) Writing to an offset beyond the previous EOF requires that > "something" be done in the intervening gap. It _is_ legal to > write to byte address 1,000,000 as the first operation on such a > file. UNIX normally deals with this just fine. stdio has no idea where EOF is, except when it stumbles across it while reading. In short, unless you have a spectacularly variant variant of UNIX, I would expect stdio to do just fine. der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu