Through using the access function I'm attempting to see whether a file has already had its hash computed (the hash is placed into a text file) however currently what is being returned is "File exists" repeated about 20 times... If the if and else statements are removed the entire program works without issue, it's simply this method and implementation of access that I've attempted which is creating this problem. I'm quite stuck trying to suss this one out unfortunately, I'd appreciate any tips.
snprintf(hashInBuf, sizeof(hashInBuf), "%s/%s", directory, event->name);
snprintf(hashOutBuf, sizeof(hashOutBuf), "%s/%s.txt", hashDirectory, event->name);
FILE *ftest=fopen(hashInBuf, "rb");
FILE *ftest2=fopen(hashOutBuf, "wt");
//HASH FUNCTION
SHA512_Init (&mdContext);
while ((bytes = fread (data, 1, 1024, ftest)) != 0)
SHA512_Update (&mdContext, data, bytes);
SHA512_Final (c,&mdContext);
for(i = 0; i < SHA512_DIGEST_LENGTH; i++){
if(access(hashOutBuf, F_OK) != -1) {
printf("File exists\n");
}
else {
fprintf(ftest2, "%02x", c[i]);
printf("%02x", c[i]);
}
}
fclose (ftest);
fclose (ftest2);
fflush(stdout);
(Files are placed into the Documents folder on my computer, and within that folder resides a folder called _HASH, where the computed hashes reside (named identically to the original file)
Aucun commentaire:
Enregistrer un commentaire