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/topology | |
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/topology')
-rw-r--r-- | src/topology/gnunet-daemon-topology.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index 38a648afc..4e332496c 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c | |||
@@ -970,7 +970,7 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
970 | char *data; | 970 | char *data; |
971 | size_t pos; | 971 | size_t pos; |
972 | struct GNUNET_PeerIdentity pid; | 972 | struct GNUNET_PeerIdentity pid; |
973 | struct stat frstat; | 973 | uint64_t fsize; |
974 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; | 974 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; |
975 | unsigned int entries_found; | 975 | unsigned int entries_found; |
976 | struct Peer *fl; | 976 | struct Peer *fl; |
@@ -987,7 +987,8 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
987 | GNUNET_DISK_fn_write (fn, NULL, 0, | 987 | GNUNET_DISK_fn_write (fn, NULL, 0, |
988 | GNUNET_DISK_PERM_USER_READ | | 988 | GNUNET_DISK_PERM_USER_READ | |
989 | GNUNET_DISK_PERM_USER_WRITE); | 989 | GNUNET_DISK_PERM_USER_WRITE); |
990 | if (0 != STAT (fn, &frstat)) | 990 | if (GNUNET_OK != GNUNET_DISK_file_size (fn, |
991 | &fsize, GNUNET_NO, GNUNET_YES)) | ||
991 | { | 992 | { |
992 | if ((friends_only) || (minimum_friend_count > 0)) | 993 | if ((friends_only) || (minimum_friend_count > 0)) |
993 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 994 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -995,14 +996,14 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
995 | GNUNET_free (fn); | 996 | GNUNET_free (fn); |
996 | return; | 997 | return; |
997 | } | 998 | } |
998 | if (frstat.st_size == 0) | 999 | if (fsize == 0) |
999 | { | 1000 | { |
1000 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Friends file `%s' is empty.\n"), | 1001 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Friends file `%s' is empty.\n"), |
1001 | fn); | 1002 | fn); |
1002 | GNUNET_free (fn); | 1003 | GNUNET_free (fn); |
1003 | return; | 1004 | return; |
1004 | } | 1005 | } |
1005 | data = GNUNET_malloc_large (frstat.st_size); | 1006 | data = GNUNET_malloc_large (fsize); |
1006 | if (data == NULL) | 1007 | if (data == NULL) |
1007 | { | 1008 | { |
1008 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1009 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -1011,7 +1012,7 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1011 | GNUNET_free (fn); | 1012 | GNUNET_free (fn); |
1012 | return; | 1013 | return; |
1013 | } | 1014 | } |
1014 | if (frstat.st_size != GNUNET_DISK_fn_read (fn, data, frstat.st_size)) | 1015 | if (fsize != GNUNET_DISK_fn_read (fn, data, fsize)) |
1015 | { | 1016 | { |
1016 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1017 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1017 | _("Failed to read friends list from `%s'\n"), fn); | 1018 | _("Failed to read friends list from `%s'\n"), fn); |
@@ -1021,11 +1022,11 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1021 | } | 1022 | } |
1022 | entries_found = 0; | 1023 | entries_found = 0; |
1023 | pos = 0; | 1024 | pos = 0; |
1024 | while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos])) | 1025 | while ((pos < fsize) && isspace ((unsigned char) data[pos])) |
1025 | pos++; | 1026 | pos++; |
1026 | while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) && | 1027 | while ((fsize >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) && |
1027 | (pos <= | 1028 | (pos <= |
1028 | frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))) | 1029 | fsize - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))) |
1029 | { | 1030 | { |
1030 | memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 1031 | memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
1031 | if (!isspace | 1032 | if (!isspace |
@@ -1037,7 +1038,7 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1037 | ("Syntax error in topology specification at offset %llu, skipping bytes.\n"), | 1038 | ("Syntax error in topology specification at offset %llu, skipping bytes.\n"), |
1038 | (unsigned long long) pos); | 1039 | (unsigned long long) pos); |
1039 | pos++; | 1040 | pos++; |
1040 | while ((pos < frstat.st_size) && (!isspace ((unsigned char) data[pos]))) | 1041 | while ((pos < fsize) && (!isspace ((unsigned char) data[pos]))) |
1041 | pos++; | 1042 | pos++; |
1042 | continue; | 1043 | continue; |
1043 | } | 1044 | } |
@@ -1068,7 +1069,7 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1068 | } | 1069 | } |
1069 | } | 1070 | } |
1070 | pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded); | 1071 | pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded); |
1071 | while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos])) | 1072 | while ((pos < fsize) && isspace ((unsigned char) data[pos])) |
1072 | pos++; | 1073 | pos++; |
1073 | } | 1074 | } |
1074 | GNUNET_free (data); | 1075 | GNUNET_free (data); |