main: Return errno when applicable

This commit is contained in:
lat9nq 2023-05-27 19:29:07 -04:00
parent 0cc0aed335
commit c91a0ccc43

View File

@ -59,7 +59,7 @@ int main(int argc, char *argv[]) {
case 'h': case 'h':
PrintHelp(argv[0]); PrintHelp(argv[0]);
return -1; return -1;
default: case '?':
ShortHelp(argv[0]); ShortHelp(argv[0]);
return -1; return -1;
} }
@ -72,7 +72,7 @@ int main(int argc, char *argv[]) {
if (f == -1) { if (f == -1) {
const int err = errno; const int err = errno;
std::fprintf(stderr, "%s: %s\n", filename, std::strerror(err)); std::fprintf(stderr, "%s: %s\n", filename, std::strerror(err));
return -1; return err;
} }
struct stat statbuf; struct stat statbuf;
@ -98,13 +98,13 @@ int main(int argc, char *argv[]) {
if (filesize == static_cast<std::size_t>(-1)) { if (filesize == static_cast<std::size_t>(-1)) {
const int err = errno; const int err = errno;
std::fprintf(stderr, "%s: %s\n", filename, std::strerror(err)); std::fprintf(stderr, "%s: %s\n", filename, std::strerror(err));
return -1; return err;
} }
int result = close(f); int result = close(f);
if (result == -1) { if (result == -1) {
const int err = errno; const int err = errno;
std::fprintf(stderr, "%s: %s\n", filename, std::strerror(err)); std::fprintf(stderr, "%s: %s\n", filename, std::strerror(err));
return -1; return err;
} }
if (filesize < 4) { if (filesize < 4) {
@ -134,7 +134,7 @@ int main(int argc, char *argv[]) {
if (f == -1) { if (f == -1) {
const int err = errno; const int err = errno;
std::fprintf(stderr, "%s: %s\n", filename, std::strerror(err)); std::fprintf(stderr, "%s: %s\n", filename, std::strerror(err));
return -1; return err;
} }
} }
@ -142,14 +142,14 @@ int main(int argc, char *argv[]) {
if (result == -1) { if (result == -1) {
const int err = errno; const int err = errno;
std::fprintf(stderr, "%s: %s\n", filename, std::strerror(err)); std::fprintf(stderr, "%s: %s\n", filename, std::strerror(err));
return -1; return err;
} }
result = close(f); result = close(f);
if (result == -1) { if (result == -1) {
const int err = errno; const int err = errno;
std::fprintf(stderr, "%s: %s\n", filename, std::strerror(err)); std::fprintf(stderr, "%s: %s\n", filename, std::strerror(err));
return -1; return err;
} }
return 0; return 0;