From b3e1d0806fb274c62a5acf19c56369b71f992312 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 19 Mar 2012 10:48:51 +0000 Subject: -LRN: calculate file size for single files when needed and use GNUNET_DISK_file_size instead of STAT --- src/transport/gnunet-service-transport_blacklist.c | 29 +++++++++++----------- src/transport/plugin_transport_http_server.c | 11 ++++---- src/transport/transport-testing.c | 2 +- 3 files changed, 22 insertions(+), 20 deletions(-) (limited to 'src/transport') diff --git a/src/transport/gnunet-service-transport_blacklist.c b/src/transport/gnunet-service-transport_blacklist.c index 2089949f7..10362681c 100644 --- a/src/transport/gnunet-service-transport_blacklist.c +++ b/src/transport/gnunet-service-transport_blacklist.c @@ -221,7 +221,7 @@ read_blacklist_file () size_t colon_pos; int tsize; struct GNUNET_PeerIdentity pid; - struct stat frstat; + uint64_t fsize; struct GNUNET_CRYPTO_HashAsciiEncoded enc; unsigned int entries_found; char *transport_name; @@ -241,14 +241,15 @@ read_blacklist_file () GNUNET_DISK_fn_write (fn, NULL, 0, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); - if (0 != STAT (fn, &frstat)) + if (GNUNET_OK != GNUNET_DISK_file_size (fn, + &fsize, GNUNET_NO, GNUNET_YES)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not read blacklist file `%s'\n"), fn); GNUNET_free (fn); return; } - if (frstat.st_size == 0) + if (fsize == 0) { #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Blacklist file `%s' is empty.\n"), @@ -258,9 +259,9 @@ read_blacklist_file () return; } /* FIXME: use mmap */ - data = GNUNET_malloc_large (frstat.st_size); + data = GNUNET_malloc_large (fsize); GNUNET_assert (data != NULL); - if (frstat.st_size != GNUNET_DISK_fn_read (fn, data, frstat.st_size)) + if (fsize != GNUNET_DISK_fn_read (fn, data, fsize)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to read blacklist from `%s'\n"), fn); @@ -270,17 +271,17 @@ read_blacklist_file () } entries_found = 0; pos = 0; - while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos])) + while ((pos < fsize) && isspace ((unsigned char) data[pos])) pos++; - while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) && + while ((fsize >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) && (pos <= - frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))) + fsize - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))) { colon_pos = pos; - while ((colon_pos < frstat.st_size) && (data[colon_pos] != ':') && + while ((colon_pos < fsize) && (data[colon_pos] != ':') && (!isspace ((unsigned char) data[colon_pos]))) colon_pos++; - if (colon_pos >= frstat.st_size) + if (colon_pos >= fsize) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ @@ -298,12 +299,12 @@ read_blacklist_file () ("Syntax error in blacklist file at offset %llu, skipping bytes.\n"), (unsigned long long) colon_pos); pos = colon_pos; - while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos])) + while ((pos < fsize) && isspace ((unsigned char) data[pos])) pos++; continue; } tsize = colon_pos - pos; - if ((pos >= frstat.st_size) || (pos + tsize >= frstat.st_size) || + if ((pos >= fsize) || (pos + tsize >= fsize) || (tsize == 0)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -336,7 +337,7 @@ read_blacklist_file () ("Syntax error in blacklist file at offset %llu, skipping bytes.\n"), (unsigned long long) pos); pos++; - while ((pos < frstat.st_size) && (!isspace ((unsigned char) data[pos]))) + while ((pos < fsize) && (!isspace ((unsigned char) data[pos]))) pos++; GNUNET_free_non_null (transport_name); continue; @@ -367,7 +368,7 @@ read_blacklist_file () } pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded); GNUNET_free_non_null (transport_name); - while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos])) + while ((pos < fsize) && isspace ((unsigned char) data[pos])) pos++; } GNUNET_STATISTICS_update (GST_stats, "# Transport entries blacklisted", diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 8ec5a5e43..68b6a2a4f 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c @@ -95,12 +95,13 @@ static char * server_load_file (const char *file) { struct GNUNET_DISK_FileHandle *gn_file; - struct stat fstat; + uint64_t fsize; char *text = NULL; - if (0 != STAT (file, &fstat)) + if (GNUNET_OK != GNUNET_DISK_file_size (file, + &fsize, GNUNET_NO, GNUNET_YES)) return NULL; - text = GNUNET_malloc (fstat.st_size + 1); + text = GNUNET_malloc (fsize + 1); gn_file = GNUNET_DISK_file_open (file, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_USER_READ); @@ -109,13 +110,13 @@ server_load_file (const char *file) GNUNET_free (text); return NULL; } - if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fstat.st_size)) + if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fsize)) { GNUNET_free (text); GNUNET_DISK_file_close (gn_file); return NULL; } - text[fstat.st_size] = '\0'; + text[fsize] = '\0'; GNUNET_DISK_file_close (gn_file); return text; } diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index 752106bfe..fd5cc4701 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c @@ -661,7 +661,7 @@ GNUNET_TRANSPORT_TESTING_init () return NULL; } - if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES)) + if (GNUNET_OK != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES, GNUNET_YES)) fs = 0; if (0 != (fs % HOSTKEYFILESIZE)) -- cgit v1.2.3