diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-03-19 10:48:51 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-03-19 10:48:51 +0000 |
commit | b3e1d0806fb274c62a5acf19c56369b71f992312 (patch) | |
tree | 657a7cd7a327aad0e7598b3d28cecc0d5cd95cd4 /src/transport/gnunet-service-transport_blacklist.c | |
parent | 0385dc1043912d3ddc5d57f6b7346054a30f64ef (diff) | |
download | gnunet-b3e1d0806fb274c62a5acf19c56369b71f992312.tar.gz gnunet-b3e1d0806fb274c62a5acf19c56369b71f992312.zip |
-LRN: calculate file size for single files when needed and use GNUNET_DISK_file_size instead of STAT
Diffstat (limited to 'src/transport/gnunet-service-transport_blacklist.c')
-rw-r--r-- | src/transport/gnunet-service-transport_blacklist.c | 29 |
1 files changed, 15 insertions, 14 deletions
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 () | |||
221 | size_t colon_pos; | 221 | size_t colon_pos; |
222 | int tsize; | 222 | int tsize; |
223 | struct GNUNET_PeerIdentity pid; | 223 | struct GNUNET_PeerIdentity pid; |
224 | struct stat frstat; | 224 | uint64_t fsize; |
225 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; | 225 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; |
226 | unsigned int entries_found; | 226 | unsigned int entries_found; |
227 | char *transport_name; | 227 | char *transport_name; |
@@ -241,14 +241,15 @@ read_blacklist_file () | |||
241 | GNUNET_DISK_fn_write (fn, NULL, 0, | 241 | GNUNET_DISK_fn_write (fn, NULL, 0, |
242 | GNUNET_DISK_PERM_USER_READ | | 242 | GNUNET_DISK_PERM_USER_READ | |
243 | GNUNET_DISK_PERM_USER_WRITE); | 243 | GNUNET_DISK_PERM_USER_WRITE); |
244 | if (0 != STAT (fn, &frstat)) | 244 | if (GNUNET_OK != GNUNET_DISK_file_size (fn, |
245 | &fsize, GNUNET_NO, GNUNET_YES)) | ||
245 | { | 246 | { |
246 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 247 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
247 | _("Could not read blacklist file `%s'\n"), fn); | 248 | _("Could not read blacklist file `%s'\n"), fn); |
248 | GNUNET_free (fn); | 249 | GNUNET_free (fn); |
249 | return; | 250 | return; |
250 | } | 251 | } |
251 | if (frstat.st_size == 0) | 252 | if (fsize == 0) |
252 | { | 253 | { |
253 | #if DEBUG_TRANSPORT | 254 | #if DEBUG_TRANSPORT |
254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Blacklist file `%s' is empty.\n"), | 255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Blacklist file `%s' is empty.\n"), |
@@ -258,9 +259,9 @@ read_blacklist_file () | |||
258 | return; | 259 | return; |
259 | } | 260 | } |
260 | /* FIXME: use mmap */ | 261 | /* FIXME: use mmap */ |
261 | data = GNUNET_malloc_large (frstat.st_size); | 262 | data = GNUNET_malloc_large (fsize); |
262 | GNUNET_assert (data != NULL); | 263 | GNUNET_assert (data != NULL); |
263 | if (frstat.st_size != GNUNET_DISK_fn_read (fn, data, frstat.st_size)) | 264 | if (fsize != GNUNET_DISK_fn_read (fn, data, fsize)) |
264 | { | 265 | { |
265 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 266 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
266 | _("Failed to read blacklist from `%s'\n"), fn); | 267 | _("Failed to read blacklist from `%s'\n"), fn); |
@@ -270,17 +271,17 @@ read_blacklist_file () | |||
270 | } | 271 | } |
271 | entries_found = 0; | 272 | entries_found = 0; |
272 | pos = 0; | 273 | pos = 0; |
273 | while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos])) | 274 | while ((pos < fsize) && isspace ((unsigned char) data[pos])) |
274 | pos++; | 275 | pos++; |
275 | while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) && | 276 | while ((fsize >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) && |
276 | (pos <= | 277 | (pos <= |
277 | frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))) | 278 | fsize - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))) |
278 | { | 279 | { |
279 | colon_pos = pos; | 280 | colon_pos = pos; |
280 | while ((colon_pos < frstat.st_size) && (data[colon_pos] != ':') && | 281 | while ((colon_pos < fsize) && (data[colon_pos] != ':') && |
281 | (!isspace ((unsigned char) data[colon_pos]))) | 282 | (!isspace ((unsigned char) data[colon_pos]))) |
282 | colon_pos++; | 283 | colon_pos++; |
283 | if (colon_pos >= frstat.st_size) | 284 | if (colon_pos >= fsize) |
284 | { | 285 | { |
285 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 286 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
286 | _ | 287 | _ |
@@ -298,12 +299,12 @@ read_blacklist_file () | |||
298 | ("Syntax error in blacklist file at offset %llu, skipping bytes.\n"), | 299 | ("Syntax error in blacklist file at offset %llu, skipping bytes.\n"), |
299 | (unsigned long long) colon_pos); | 300 | (unsigned long long) colon_pos); |
300 | pos = colon_pos; | 301 | pos = colon_pos; |
301 | while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos])) | 302 | while ((pos < fsize) && isspace ((unsigned char) data[pos])) |
302 | pos++; | 303 | pos++; |
303 | continue; | 304 | continue; |
304 | } | 305 | } |
305 | tsize = colon_pos - pos; | 306 | tsize = colon_pos - pos; |
306 | if ((pos >= frstat.st_size) || (pos + tsize >= frstat.st_size) || | 307 | if ((pos >= fsize) || (pos + tsize >= fsize) || |
307 | (tsize == 0)) | 308 | (tsize == 0)) |
308 | { | 309 | { |
309 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 310 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -336,7 +337,7 @@ read_blacklist_file () | |||
336 | ("Syntax error in blacklist file at offset %llu, skipping bytes.\n"), | 337 | ("Syntax error in blacklist file at offset %llu, skipping bytes.\n"), |
337 | (unsigned long long) pos); | 338 | (unsigned long long) pos); |
338 | pos++; | 339 | pos++; |
339 | while ((pos < frstat.st_size) && (!isspace ((unsigned char) data[pos]))) | 340 | while ((pos < fsize) && (!isspace ((unsigned char) data[pos]))) |
340 | pos++; | 341 | pos++; |
341 | GNUNET_free_non_null (transport_name); | 342 | GNUNET_free_non_null (transport_name); |
342 | continue; | 343 | continue; |
@@ -367,7 +368,7 @@ read_blacklist_file () | |||
367 | } | 368 | } |
368 | pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded); | 369 | pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded); |
369 | GNUNET_free_non_null (transport_name); | 370 | GNUNET_free_non_null (transport_name); |
370 | while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos])) | 371 | while ((pos < fsize) && isspace ((unsigned char) data[pos])) |
371 | pos++; | 372 | pos++; |
372 | } | 373 | } |
373 | GNUNET_STATISTICS_update (GST_stats, "# Transport entries blacklisted", | 374 | GNUNET_STATISTICS_update (GST_stats, "# Transport entries blacklisted", |