set return value when file open fails, do not fail silently
This commit is contained in:
parent
2d84dd5d65
commit
f03fbb9f9b
1 changed files with 10 additions and 5 deletions
15
src/oshash.c
15
src/oshash.c
|
@ -100,19 +100,24 @@ unsigned long long gen_oshash(char const *filename) {
|
|||
return t1;
|
||||
}
|
||||
|
||||
void print_oshash(FILE *output, char const *filename) {
|
||||
int print_oshash(FILE *output, char const *filename) {
|
||||
char hash[32];
|
||||
#ifdef WIN32
|
||||
sprintf(hash, "%016I64x", gen_oshash(filename));
|
||||
#else
|
||||
sprintf(hash, "%016qx", gen_oshash(filename));
|
||||
#endif
|
||||
if (strcmp(hash,"0000000000000000") > 0)
|
||||
if (strcmp(hash,"0000000000000000") > 0) {
|
||||
fprintf(output, "%s %s\n", hash, filename);
|
||||
return 0;
|
||||
} else {
|
||||
fprintf(output,"%s: No such file or permission denied\n",filename);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
int i,r=0;
|
||||
FILE* output = stdout;
|
||||
|
||||
if(argc == 1) {
|
||||
|
@ -120,6 +125,6 @@ int main(int argc, char **argv) {
|
|||
exit(1);
|
||||
}
|
||||
for(i=1;i<argc;i++)
|
||||
print_oshash(output, argv[i]);
|
||||
return 0;
|
||||
r+=print_oshash(output, argv[i]);
|
||||
return r>0?1:0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue