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/statistics/gnunet-service-statistics.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/statistics/gnunet-service-statistics.c')
-rw-r--r-- | src/statistics/gnunet-service-statistics.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c index 58ef763e3..1ec07ad5d 100644 --- a/src/statistics/gnunet-service-statistics.c +++ b/src/statistics/gnunet-service-statistics.c | |||
@@ -224,6 +224,7 @@ load (struct GNUNET_SERVER_Handle *server) | |||
224 | char *fn; | 224 | char *fn; |
225 | struct GNUNET_BIO_ReadHandle *rh; | 225 | struct GNUNET_BIO_ReadHandle *rh; |
226 | struct stat sb; | 226 | struct stat sb; |
227 | uint64_t fsize; | ||
227 | char *buf; | 228 | char *buf; |
228 | struct GNUNET_SERVER_MessageStreamTokenizer *mst; | 229 | struct GNUNET_SERVER_MessageStreamTokenizer *mst; |
229 | char *emsg; | 230 | char *emsg; |
@@ -232,12 +233,12 @@ load (struct GNUNET_SERVER_Handle *server) | |||
232 | NULL); | 233 | NULL); |
233 | if (fn == NULL) | 234 | if (fn == NULL) |
234 | return; | 235 | return; |
235 | if ((0 != stat (fn, &sb)) || (sb.st_size == 0)) | 236 | if ((GNUNET_OK != GNUNET_DISK_file_size (fn, &fsize, GNUNET_NO, GNUNET_YES)) || (fsize == 0)) |
236 | { | 237 | { |
237 | GNUNET_free (fn); | 238 | GNUNET_free (fn); |
238 | return; | 239 | return; |
239 | } | 240 | } |
240 | buf = GNUNET_malloc (sb.st_size); | 241 | buf = GNUNET_malloc (fsize); |
241 | rh = GNUNET_BIO_read_open (fn); | 242 | rh = GNUNET_BIO_read_open (fn); |
242 | if (!rh) | 243 | if (!rh) |
243 | { | 244 | { |
@@ -245,7 +246,7 @@ load (struct GNUNET_SERVER_Handle *server) | |||
245 | GNUNET_free (fn); | 246 | GNUNET_free (fn); |
246 | return; | 247 | return; |
247 | } | 248 | } |
248 | if (GNUNET_OK != GNUNET_BIO_read (rh, fn, buf, sb.st_size)) | 249 | if (GNUNET_OK != GNUNET_BIO_read (rh, fn, buf, fsize)) |
249 | { | 250 | { |
250 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", fn); | 251 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", fn); |
251 | GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, &emsg)); | 252 | GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, &emsg)); |
@@ -256,10 +257,10 @@ load (struct GNUNET_SERVER_Handle *server) | |||
256 | } | 257 | } |
257 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 258 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
258 | _("Loading %llu bytes of statistics from `%s'\n"), | 259 | _("Loading %llu bytes of statistics from `%s'\n"), |
259 | (unsigned long long) sb.st_size, fn); | 260 | fsize, fn); |
260 | mst = GNUNET_SERVER_mst_create (&inject_message, server); | 261 | mst = GNUNET_SERVER_mst_create (&inject_message, server); |
261 | GNUNET_break (GNUNET_OK == | 262 | GNUNET_break (GNUNET_OK == |
262 | GNUNET_SERVER_mst_receive (mst, NULL, buf, sb.st_size, | 263 | GNUNET_SERVER_mst_receive (mst, NULL, buf, fsize, |
263 | GNUNET_YES, GNUNET_NO)); | 264 | GNUNET_YES, GNUNET_NO)); |
264 | GNUNET_SERVER_mst_destroy (mst); | 265 | GNUNET_SERVER_mst_destroy (mst); |
265 | GNUNET_free (buf); | 266 | GNUNET_free (buf); |