Random Access I/O

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Mar 25 17:51:06 PDT 2016


On Saturday, 26 March 2016 at 00:10:23 UTC, Chris Williams wrote:
> None of the access modes for std.stdio.File seem to allow that. 
> Any usage of the "w" mode causes my code to consider the file 
> empty if it pre-exists (though, it doesn't always actually 
> truncate the disk on file?)

Mode "a+" or "r+" for append+read or read+write will do it, same 
as in C.

> If I was coding in C, I would use open() as it gives more 
> options for access:

This function is in `import core.sys.posix.fcntl;` (the 
documentation is lax on this but generally when you see a Posix 
function in C that is #include<x.h>, you can get it in D with 
`import core.sys.posix.X`.


More information about the Digitalmars-d-learn mailing list