aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-directory.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-06 22:46:29 +0000
committerng0 <ng0@n0.is>2019-09-06 22:46:29 +0000
commit6e599264ad13e8fc105493d74d7c11d46f8739ed (patch)
tree169bef1ecbade5a659831fb169f3ae6943af127f /src/fs/gnunet-directory.c
parent4f13bc15113021ebf71d5d81e99bc29f8a07fc9c (diff)
downloadgnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.tar.gz
gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.zip
first step to remove plibc
Diffstat (limited to 'src/fs/gnunet-directory.c')
-rw-r--r--src/fs/gnunet-directory.c70
1 files changed, 39 insertions, 31 deletions
diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c
index 097dd4406..4cce69d72 100644
--- a/src/fs/gnunet-directory.c
+++ b/src/fs/gnunet-directory.c
@@ -50,7 +50,7 @@ item_printer (void *cls,
50{ 50{
51 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) 51 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
52 { 52 {
53 printf (_("\t<original file embedded in %u bytes of meta data>\n"), 53 printf (_ ("\t<original file embedded in %u bytes of meta data>\n"),
54 (unsigned int) data_size); 54 (unsigned int) data_size);
55 return 0; 55 return 0;
56 } 56 }
@@ -63,17 +63,14 @@ item_printer (void *cls,
63 printf ("\t%20s: %s\n", 63 printf ("\t%20s: %s\n",
64 dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, 64 dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN,
65 EXTRACTOR_metatype_to_string (type)), 65 EXTRACTOR_metatype_to_string (type)),
66 data);
67#else
68 printf ("\t%20d: %s\n",
69 type,
70 data); 66 data);
67#else
68 printf ("\t%20d: %s\n", type, data);
71#endif 69#endif
72 return 0; 70 return 0;
73} 71}
74 72
75 73
76
77/** 74/**
78 * Print an entry in a directory. 75 * Print an entry in a directory.
79 * 76 *
@@ -90,22 +87,25 @@ item_printer (void *cls,
90 * @param data data available for the file (length bytes) 87 * @param data data available for the file (length bytes)
91 */ 88 */
92static void 89static void
93print_entry (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, 90print_entry (void *cls,
94 const struct GNUNET_CONTAINER_MetaData *meta, size_t length, 91 const char *filename,
92 const struct GNUNET_FS_Uri *uri,
93 const struct GNUNET_CONTAINER_MetaData *meta,
94 size_t length,
95 const void *data) 95 const void *data)
96{ 96{
97 char *string; 97 char *string;
98 char *name; 98 char *name;
99 99
100 name = 100 name = GNUNET_CONTAINER_meta_data_get_by_type (
101 GNUNET_CONTAINER_meta_data_get_by_type (meta, 101 meta,
102 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 102 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
103 if (uri == NULL) 103 if (uri == NULL)
104 { 104 {
105 printf (_("Directory `%s' meta data:\n"), name ? name : ""); 105 printf (_ ("Directory `%s' meta data:\n"), name ? name : "");
106 GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL); 106 GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL);
107 printf ("\n"); 107 printf ("\n");
108 printf (_("Directory `%s' contents:\n"), name ? name : ""); 108 printf (_ ("Directory `%s' contents:\n"), name ? name : "");
109 GNUNET_free_non_null (name); 109 GNUNET_free_non_null (name);
110 return; 110 return;
111 } 111 }
@@ -127,7 +127,9 @@ print_entry (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
127 * @param cfg configuration 127 * @param cfg configuration
128 */ 128 */
129static void 129static void
130run (void *cls, char *const *args, const char *cfgfile, 130run (void *cls,
131 char *const *args,
132 const char *cfgfile,
131 const struct GNUNET_CONFIGURATION_Handle *cfg) 133 const struct GNUNET_CONFIGURATION_Handle *cfg)
132{ 134{
133 struct GNUNET_DISK_MapHandle *map; 135 struct GNUNET_DISK_MapHandle *map;
@@ -140,20 +142,21 @@ run (void *cls, char *const *args, const char *cfgfile,
140 142
141 if (NULL == args[0]) 143 if (NULL == args[0])
142 { 144 {
143 FPRINTF (stderr, "%s", _("You must specify a filename to inspect.\n")); 145 fprintf (stderr, "%s", _ ("You must specify a filename to inspect.\n"));
144 ret = 1; 146 ret = 1;
145 return; 147 return;
146 } 148 }
147 i = 0; 149 i = 0;
148 while (NULL != (filename = args[i++])) 150 while (NULL != (filename = args[i++]))
149 { 151 {
150 if ((GNUNET_OK != GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) || 152 if ((GNUNET_OK !=
151 (NULL == 153 GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) ||
152 (h = 154 (NULL == (h = GNUNET_DISK_file_open (filename,
153 GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 155 GNUNET_DISK_OPEN_READ,
154 GNUNET_DISK_PERM_NONE)))) 156 GNUNET_DISK_PERM_NONE))))
155 { 157 {
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to read directory `%s'\n"), 158 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
159 _ ("Failed to read directory `%s'\n"),
157 filename); 160 filename);
158 ret = 1; 161 ret = 1;
159 continue; 162 continue;
@@ -161,9 +164,9 @@ run (void *cls, char *const *args, const char *cfgfile,
161 len = (size_t) size; 164 len = (size_t) size;
162 data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len); 165 data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len);
163 GNUNET_assert (NULL != data); 166 GNUNET_assert (NULL != data);
164 if (GNUNET_OK != GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL)) 167 if (GNUNET_OK !=
165 fprintf (stdout, _("`%s' is not a GNUnet directory\n"), 168 GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL))
166 filename); 169 fprintf (stdout, _ ("`%s' is not a GNUnet directory\n"), filename);
167 else 170 else
168 printf ("\n"); 171 printf ("\n");
169 GNUNET_DISK_file_unmap (map); 172 GNUNET_DISK_file_unmap (map);
@@ -182,18 +185,23 @@ int
182main (int argc, char *const *argv) 185main (int argc, char *const *argv)
183{ 186{
184 static struct GNUNET_GETOPT_CommandLineOption options[] = { 187 static struct GNUNET_GETOPT_CommandLineOption options[] = {
185 GNUNET_GETOPT_OPTION_END 188 GNUNET_GETOPT_OPTION_END};
186 };
187 189
188 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 190 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
189 return 2; 191 return 2;
190 192
191 ret = (GNUNET_OK == 193 ret = (GNUNET_OK ==
192 GNUNET_PROGRAM_run (argc, argv, "gnunet-directory [OPTIONS] FILENAME", 194 GNUNET_PROGRAM_run (argc,
193 gettext_noop 195 argv,
194 ("Display contents of a GNUnet directory"), 196 "gnunet-directory [OPTIONS] FILENAME",
195 options, &run, NULL)) ? ret : 1; 197 gettext_noop (
196 GNUNET_free ((void*) argv); 198 "Display contents of a GNUnet directory"),
199 options,
200 &run,
201 NULL))
202 ? ret
203 : 1;
204 GNUNET_free ((void *) argv);
197 return ret; 205 return ret;
198} 206}
199 207