fread return value?

Andy Valencia dont at spam.me
Wed Jul 30 19:45:20 UTC 2025


Scratching my head here.  fread() really appears to be the 
standard C idea of an fread(), so it returns a count.  Instead, 
it returns 0.  The buf[] does indeed have the expected content, 
but I'd like to understand what's up before just changing my code 
to assume 0 is a success value?

(Linux, ldc2 seen on versions 1.40.0 and 1.41.0)

Thanks,
Andy

```d
import core.stdc.stdio : fopen, fread, fclose;
import std.string : toStringz;

void main(string[] argv) {
     import std.stdio : writeln;

     foreach(a; argv[1 .. $]) {
         auto f = fopen(a.toStringz(), "r".ptr);
         ubyte[1024] buf;
         auto res = fread(&buf[0], buf.length, 1, f);
         writeln(res, ": ", buf);
         f.fclose();
     }
}
```



More information about the Digitalmars-d-learn mailing list