aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/crypto_hash.c')
-rw-r--r--src/util/crypto_hash.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 139496eac..5a7cb33d7 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -429,7 +429,7 @@ struct FileHashContext
429 /** 429 /**
430 * File descriptor. 430 * File descriptor.
431 */ 431 */
432 int fd; 432 struct GNUNET_IO_Handle *fh;
433 433
434}; 434};
435 435
@@ -443,8 +443,8 @@ file_hash_finish (struct FileHashContext *fhc, const GNUNET_HashCode * res)
443{ 443{
444 fhc->callback (fhc->callback_cls, res); 444 fhc->callback (fhc->callback_cls, res);
445 GNUNET_free (fhc->filename); 445 GNUNET_free (fhc->filename);
446 if (fhc->fd != -1) 446 if (!GNUNET_IO_handle_invalid (fhc->fh))
447 GNUNET_break (0 == CLOSE (fhc->fd)); 447 GNUNET_break (0 == GNUNET_DISK_file_close (&fhc->fh));
448 GNUNET_free (fhc); /* also frees fhc->buffer */ 448 GNUNET_free (fhc); /* also frees fhc->buffer */
449} 449}
450 450
@@ -466,7 +466,7 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
466 delta = fhc->bsize; 466 delta = fhc->bsize;
467 if (fhc->fsize - fhc->offset < delta) 467 if (fhc->fsize - fhc->offset < delta)
468 delta = fhc->fsize - fhc->offset; 468 delta = fhc->fsize - fhc->offset;
469 if (delta != READ (fhc->fd, fhc->buffer, delta)) 469 if (delta != GNUNET_DISK_file_read (fhc->fh, fhc->buffer, delta))
470 { 470 {
471 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 471 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
472 "read", fhc->filename); 472 "read", fhc->filename);
@@ -517,7 +517,7 @@ GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched,
517 fhc->callback_cls = callback_cls; 517 fhc->callback_cls = callback_cls;
518 fhc->buffer = (unsigned char *) &fhc[1]; 518 fhc->buffer = (unsigned char *) &fhc[1];
519 fhc->filename = GNUNET_strdup (filename); 519 fhc->filename = GNUNET_strdup (filename);
520 fhc->fd = -1; 520 fhc->fh = NULL;
521 sha512_init (&fhc->hctx); 521 sha512_init (&fhc->hctx);
522 fhc->bsize = blocksize; 522 fhc->bsize = blocksize;
523 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO)) 523 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO))
@@ -526,8 +526,9 @@ GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched,
526 return; 526 return;
527 } 527 }
528 fhc->run_on_shutdown = run_on_shutdown; 528 fhc->run_on_shutdown = run_on_shutdown;
529 fhc->fd = GNUNET_DISK_file_open (filename, O_RDONLY | O_LARGEFILE); 529 fhc->fh = GNUNET_DISK_file_open (filename,
530 if (fhc->fd == -1) 530 GNUNET_DISK_OPEN_READ);
531 if (!fhc->fh)
531 { 532 {
532 file_hash_finish (fhc, NULL); 533 file_hash_finish (fhc, NULL);
533 return; 534 return;