set return value when file open fails, do not fail silently

This commit is contained in:
Uwe 2013-04-21 18:37:42 +02:00
parent 2d84dd5d65
commit f03fbb9f9b

View file

@ -100,19 +100,24 @@ unsigned long long gen_oshash(char const *filename) {
return t1; return t1;
} }
void print_oshash(FILE *output, char const *filename) { int print_oshash(FILE *output, char const *filename) {
char hash[32]; char hash[32];
#ifdef WIN32 #ifdef WIN32
sprintf(hash, "%016I64x", gen_oshash(filename)); sprintf(hash, "%016I64x", gen_oshash(filename));
#else #else
sprintf(hash, "%016qx", gen_oshash(filename)); sprintf(hash, "%016qx", gen_oshash(filename));
#endif #endif
if (strcmp(hash,"0000000000000000") > 0) if (strcmp(hash,"0000000000000000") > 0) {
fprintf(output, "%s %s\n", hash, filename); 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 main(int argc, char **argv) {
int i; int i,r=0;
FILE* output = stdout; FILE* output = stdout;
if(argc == 1) { if(argc == 1) {
@ -120,6 +125,6 @@ int main(int argc, char **argv) {
exit(1); exit(1);
} }
for(i=1;i<argc;i++) for(i=1;i<argc;i++)
print_oshash(output, argv[i]); r+=print_oshash(output, argv[i]);
return 0; return r>0?1:0;
} }