/*
This file is part of GNUnet.
- (C) 2003, 2004, 2006, 2009 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2003, 2004, 2006, 2009 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
if (data_len > 0)
{
gfdc->data = GNUNET_malloc (data_len);
- memcpy (gfdc->data, data, data_len);
+ GNUNET_memcpy (gfdc->data, data, data_len);
}
return 1;
}
* @param data pointer to the beginning of the directory
* @param offset offset of data in the directory
* @param dep function to call on each entry
- * @param dep_cls closure for dep
- * @return GNUNET_OK if this could be a block in a directory,
- * GNUNET_NO if this could be part of a directory (but not 100% OK)
- * GNUNET_SYSERR if 'data' does not represent a directory
+ * @param dep_cls closure for @a dep
+ * @return #GNUNET_OK if this could be a block in a directory,
+ * #GNUNET_NO if this could be part of a directory (but not 100% OK)
+ * #GNUNET_SYSERR if @a data does not represent a directory
*/
int
-GNUNET_FS_directory_list_contents (size_t size, const void *data,
+GNUNET_FS_directory_list_contents (size_t size,
+ const void *data,
uint64_t offset,
GNUNET_FS_DirectoryEntryProcessor dep,
void *dep_cls)
if ((offset == 0) &&
((size < 8 + sizeof (uint32_t)) ||
- (0 != memcmp (cdata, GNUNET_FS_DIRECTORY_MAGIC, 8))))
+ (0 != memcmp (cdata,
+ GNUNET_FS_DIRECTORY_MAGIC,
+ 8))))
return GNUNET_SYSERR;
pos = offset;
if (offset == 0)
{
- memcpy (&mdSize, &cdata[8], sizeof (uint32_t));
+ GNUNET_memcpy (&mdSize,
+ &cdata[8],
+ sizeof (uint32_t));
mdSize = ntohl (mdSize);
if (mdSize > size - 8 - sizeof (uint32_t))
{
GNUNET_break (0);
return GNUNET_SYSERR; /* malformed ! */
}
- dep (dep_cls, NULL, NULL, md, 0, NULL);
+ dep (dep_cls,
+ NULL,
+ NULL,
+ md,
+ 0,
+ NULL);
GNUNET_CONTAINER_meta_data_destroy (md);
pos = 8 + sizeof (uint32_t) + mdSize;
}
uri = GNUNET_FS_uri_parse (&cdata[pos], &emsg);
pos = epos + 1;
- if (uri == NULL)
+ if (NULL == uri)
{
GNUNET_free (emsg);
pos--; /* go back to '\0' to force going to next alignment */
return GNUNET_NO; /* illegal in directory! */
}
- memcpy (&mdSize, &cdata[pos], sizeof (uint32_t));
+ GNUNET_memcpy (&mdSize,
+ &cdata[pos],
+ sizeof (uint32_t));
mdSize = ntohl (mdSize);
pos += sizeof (uint32_t);
if (pos + mdSize > size)
return GNUNET_NO; /* malformed - or partial download */
}
- md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos], mdSize);
- if (md == NULL)
+ md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos],
+ mdSize);
+ if (NULL == md)
{
GNUNET_FS_uri_destroy (uri);
GNUNET_break (0);
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
full_data.size = 0;
full_data.data = NULL;
- GNUNET_CONTAINER_meta_data_iterate (md, &find_full_data, &full_data);
- if (dep != NULL)
+ GNUNET_CONTAINER_meta_data_iterate (md,
+ &find_full_data,
+ &full_data);
+ if (NULL != dep)
{
- dep (dep_cls, filename, uri, md, full_data.size, full_data.data);
+ dep (dep_cls,
+ filename,
+ uri,
+ md,
+ full_data.size,
+ full_data.data);
}
GNUNET_free_non_null (full_data.data);
GNUNET_free_non_null (filename);
e = GNUNET_malloc (sizeof (struct BuilderEntry) + slen + mds +
sizeof (uint32_t));
ser = (char *) &e[1];
- memcpy (ser, uris, slen);
+ GNUNET_memcpy (ser, uris, slen);
GNUNET_free (uris);
sptr = &ser[slen + sizeof (uint32_t)];
ret =
else
mds = ret;
big = htonl (mds);
- memcpy (&ser[slen], &big, sizeof (uint32_t));
+ GNUNET_memcpy (&ser[slen], &big, sizeof (uint32_t));
e->len = slen + sizeof (uint32_t) + mds;
e->next = bld->head;
bld->head = e;
* @param bld directory to finish
* @param rsize set to the number of bytes needed
* @param rdata set to the encoded directory
- * @return GNUNET_OK on success
+ * @return #GNUNET_OK on success
*/
int
GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
- size_t * rsize, void **rdata)
+ size_t * rsize,
+ void **rdata)
{
char *data;
char *sptr;
bes = NULL;
if (0 < bld->count)
{
- sizes = GNUNET_malloc (bld->count * sizeof (size_t));
- perm = GNUNET_malloc (bld->count * sizeof (unsigned int));
- bes = GNUNET_malloc (bld->count * sizeof (struct BuilderEntry *));
+ sizes = GNUNET_new_array (bld->count,
+ size_t);
+ perm = GNUNET_new_array (bld->count,
+ unsigned int);
+ bes = GNUNET_new_array (bld->count,
+ struct BuilderEntry *);
pos = bld->head;
for (i = 0; i < bld->count; i++)
{
data = GNUNET_malloc_large (size);
if (data == NULL)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+ "malloc");
*rsize = 0;
*rdata = NULL;
GNUNET_free_non_null (sizes);
return GNUNET_SYSERR;
}
*rdata = data;
- memcpy (data, GNUNET_DIRECTORY_MAGIC, strlen (GNUNET_DIRECTORY_MAGIC));
+ GNUNET_memcpy (data,
+ GNUNET_DIRECTORY_MAGIC,
+ strlen (GNUNET_DIRECTORY_MAGIC));
off = strlen (GNUNET_DIRECTORY_MAGIC);
sptr = &data[off + sizeof (uint32_t)];
ret =
- GNUNET_CONTAINER_meta_data_serialize (bld->meta, &sptr,
+ GNUNET_CONTAINER_meta_data_serialize (bld->meta,
+ &sptr,
size - off - sizeof (uint32_t),
GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
GNUNET_assert (ret != -1);
big = htonl (ret);
- memcpy (&data[off], &big, sizeof (uint32_t));
+ GNUNET_memcpy (&data[off],
+ &big,
+ sizeof (uint32_t));
off += sizeof (uint32_t) + ret;
for (j = 0; j < bld->count; j++)
{
psize = off;
off += sizes[i];
off = do_align (psize, off);
- memcpy (&data[off - sizes[i]], &(bes[i])[1], sizes[i]);
+ GNUNET_memcpy (&data[off - sizes[i]], &(bes[i])[1], sizes[i]);
GNUNET_free (bes[i]);
}
GNUNET_free_non_null (sizes);