- if (argc < 2) {
- return -1;
- }
- int fd;
- if (_sopen_s(&fd, argv[1], _O_BINARY, _SH_DENYNO, _S_IREAD) != 0)
- {
- cout << "error :" << errno << " opening file: " << argv[1] << "\n";
- return -1;
- }
- struct _stat fs;
- if (_fstat(fd, &fs) != 0) {
- cout << "error: " << errno << " from _fstat.\n";
- return -1;
- }
-
- FILE *f =_fdopen(fd, "rb");
- if (f == NULL) {
- cout << "error: " << errno << " from _fdopen.\n";
- return -1;
- }
- len = fs.st_size;
- input = new char[len+1];
- size_t count = fread(input, 1, len, f) ;
- if (count != len) {
- cout << "expected " << len << " bytes from fread; got " << count << ".\n";
- return -1;
- }
- fclose(f);
-#else
- ssize_t readThisRound;
- size_t readTotal, readRemaining;
+ _setmode(_fileno(stdin), _O_BINARY);
+#endif
+ int readThisRound, readTotal, readRemaining;