GNUnet  0.11.x
Macros | Functions
BIO library

Buffered binary disk IO (with endianess conversion) More...

Macros

#define GNUNET_BIO_read_float(h, f)
 Read a float. More...
 
#define GNUNET_BIO_read_double(h, f)
 Read a double. More...
 
#define GNUNET_BIO_read_int32(h, i)
 Read an (u)int32_t. More...
 
#define GNUNET_BIO_read_int64(h, i)
 Read an (u)int64_t. More...
 
#define GNUNET_BIO_write_float(h, f)   GNUNET_BIO_write (h, &f, sizeof(float))
 Write a float. More...
 
#define GNUNET_BIO_write_double(h, f)   GNUNET_BIO_write (h, &f, sizeof(double))
 Write a double. More...
 

Functions

struct GNUNET_BIO_ReadHandleGNUNET_BIO_read_open (const char *fn)
 Open a file for reading. More...
 
int GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
 Close an open file. More...
 
int GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
 Read the contents of a binary file into a buffer. More...
 
int GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file, int line, void *result, size_t len)
 Read the contents of a binary file into a buffer. More...
 
int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
 Read 0-terminated string from a file. More...
 
int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what, struct GNUNET_CONTAINER_MetaData **result)
 Read metadata container from a file. More...
 
int GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file, int line, int32_t *i)
 Read an (u)int32_t. More...
 
int GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, const char *file, int line, int64_t *i)
 Read an (u)int64_t. More...
 
struct GNUNET_BIO_WriteHandleGNUNET_BIO_write_open (const char *fn)
 Open a file for writing. More...
 
int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
 Close an open file for writing. More...
 
int GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
 Write a buffer to a file. More...
 
int GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
 Force a buffered writer to flush its buffer. More...
 
int GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s)
 Write a string to a file. More...
 
int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, const struct GNUNET_CONTAINER_MetaData *m)
 Write metadata container to a file. More...
 
int GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i)
 Write an (u)int32_t. More...
 
int GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i)
 Write an (u)int64_t. More...
 

Detailed Description

Buffered binary disk IO (with endianess conversion)

Macro Definition Documentation

◆ GNUNET_BIO_read_float

#define GNUNET_BIO_read_float (   h,
 
)
Value:
(GNUNET_BIO_read_fn (h, __FILE__, __LINE__, \
f, sizeof(float)))
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
int GNUNET_BIO_read_fn(struct GNUNET_BIO_ReadHandle *h, const char *file, int line, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: bio.c:209

Read a float.

Parameters
hhande to open file
faddress of float to read

Definition at line 136 of file gnunet_bio_lib.h.

◆ GNUNET_BIO_read_double

#define GNUNET_BIO_read_double (   h,
 
)
Value:
(GNUNET_BIO_read_fn (h, __FILE__, __LINE__, \
f, sizeof(double)))
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
int GNUNET_BIO_read_fn(struct GNUNET_BIO_ReadHandle *h, const char *file, int line, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: bio.c:209

Read a double.

Parameters
hhande to open file
faddress of double to read

Definition at line 146 of file gnunet_bio_lib.h.

◆ GNUNET_BIO_read_int32

#define GNUNET_BIO_read_int32 (   h,
 
)
Value:
__LINE__, \
(int32_t*) i)
int GNUNET_BIO_read_int32__(struct GNUNET_BIO_ReadHandle *h, const char *file, int line, int32_t *i)
Read an (u)int32_t.
Definition: bio.c:338
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99

Read an (u)int32_t.

Parameters
hhande to open file
iaddress of 32-bit integer to read

Definition at line 170 of file gnunet_bio_lib.h.

Referenced by deserialize_download(), deserialize_fi_node(), deserialize_publish_file(), deserialize_search(), deserialize_search_result(), deserialize_unindex_file(), GNUNET_BIO_read_meta_data(), GNUNET_BIO_read_string(), load_hostlist_file(), load_state(), read_download_request(), and read_update_information_graph().

◆ GNUNET_BIO_read_int64

#define GNUNET_BIO_read_int64 (   h,
 
)
Value:
__LINE__, \
(int64_t*) i)
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
int GNUNET_BIO_read_int64__(struct GNUNET_BIO_ReadHandle *h, const char *file, int line, int64_t *i)
Read an (u)int64_t.
Definition: bio.c:362

Read an (u)int64_t.

Parameters
hhande to open file
iaddress of 64-bit integer to read

Definition at line 195 of file gnunet_bio_lib.h.

Referenced by deserialize_download(), deserialize_fi_node(), deserialize_unindex_file(), load_hostlist_file(), read_download_request(), and read_start_time().

◆ GNUNET_BIO_write_float

#define GNUNET_BIO_write_float (   h,
 
)    GNUNET_BIO_write (h, &f, sizeof(float))

Write a float.

Parameters
hhande to open file
ffloat to write (must be a variable)

Definition at line 278 of file gnunet_bio_lib.h.

◆ GNUNET_BIO_write_double

#define GNUNET_BIO_write_double (   h,
 
)    GNUNET_BIO_write (h, &f, sizeof(double))

Write a double.

Parameters
hhande to open file
fdouble to write (must be a variable)

Definition at line 287 of file gnunet_bio_lib.h.

Function Documentation

◆ GNUNET_BIO_read_open()

struct GNUNET_BIO_ReadHandle* GNUNET_BIO_read_open ( const char *  fn)

Open a file for reading.

Parameters
fnfile name to be opened
Returns
IO handle on success, NULL on error

Definition at line 94 of file bio.c.

References BIO_BUFFER_SIZE, GNUNET_BIO_ReadHandle::buffer, GNUNET_BIO_ReadHandle::fd, GNUNET_DISK_file_open(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_malloc, h, and GNUNET_BIO_ReadHandle::size.

Referenced by deserialize_download_file(), deserialize_publish_file(), deserialize_search_file(), deserialize_search_result(), deserialize_subdownload(), deserialize_unindex_file(), get_read_handle(), load(), load_hostlist_file(), load_state(), read_index_list(), and read_update_information_graph().

95 {
96  struct GNUNET_DISK_FileHandle *fd;
97  struct GNUNET_BIO_ReadHandle *h;
98 
100  if (NULL == fd)
101  return NULL;
102  h = GNUNET_malloc (sizeof(struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE);
103  h->buffer = (char *) &h[1];
104  h->size = BIO_BUFFER_SIZE;
105  h->fd = fd;
106  return h;
107 }
Open the file for reading.
struct GNUNET_DISK_FileHandle * fd
Underlying file abstraction.
Definition: bio.c:58
Nobody is allowed to do anything to the file.
#define BIO_BUFFER_SIZE
Size for I/O buffers.
Definition: bio.c:41
size_t size
Total size of buffer.
Definition: bio.c:78
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static char * fn
Filename of the unique file.
char * buffer
I/O buffer.
Definition: bio.c:68
int fd
File handle on Unix-like systems.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1268
Handle used to access files (and pipes).
#define GNUNET_malloc(size)
Wrapper around malloc.
Handle for buffered reading.
Definition: bio.c:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_close()

int GNUNET_BIO_read_close ( struct GNUNET_BIO_ReadHandle h,
char **  emsg 
)

Close an open file.

Reports if any errors reading from the file were encountered.

Parameters
hfile handle
emsgset to the error message
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 119 of file bio.c.

References GNUNET_BIO_ReadHandle::emsg, GNUNET_BIO_ReadHandle::fd, GNUNET_DISK_file_close(), GNUNET_free, GNUNET_free_non_null, GNUNET_OK, and GNUNET_SYSERR.

Referenced by deserialize_download_file(), deserialize_file_information(), deserialize_publish_file(), deserialize_search_file(), deserialize_search_result(), deserialize_subdownload(), deserialize_unindex_file(), load(), load_hostlist_file(), load_state(), read_index_list(), and read_update_information_graph().

120 {
121  int err;
122 
123  err = (NULL == h->emsg) ? GNUNET_OK : GNUNET_SYSERR;
124  if (emsg != NULL)
125  *emsg = h->emsg;
126  else
129  GNUNET_free (h);
130  return err;
131 }
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1345
struct GNUNET_DISK_FileHandle * fd
Underlying file abstraction.
Definition: bio.c:58
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:63
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read()

int GNUNET_BIO_read ( struct GNUNET_BIO_ReadHandle h,
const char *  what,
void *  result,
size_t  len 
)

Read the contents of a binary file into a buffer.

Parameters
hhandle to an open file
whatdescribes what is being read (for error message creation)
resultthe buffer to write the result to
lenthe number of bytes to read
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 144 of file bio.c.

References _, GNUNET_BIO_ReadHandle::buffer, GNUNET_BIO_ReadHandle::emsg, GNUNET_BIO_ReadHandle::fd, GNUNET_asprintf(), GNUNET_assert, GNUNET_DISK_file_read(), GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, GNUNET_BIO_ReadHandle::have, GNUNET_BIO_ReadHandle::pos, result, ret, and GNUNET_BIO_ReadHandle::size.

Referenced by deserialize_fi_node(), deserialize_publish_file(), deserialize_search(), deserialize_search_result(), deserialize_unindex_file(), GNUNET_BIO_read_fn(), GNUNET_BIO_read_meta_data(), GNUNET_BIO_read_string(), load(), load_state(), read_download_request(), and read_index_list().

148 {
149  char *dst = result;
150  size_t min;
151  size_t pos;
152  ssize_t ret;
153 
154  if (NULL != h->emsg)
155  return GNUNET_SYSERR;
156  pos = 0;
157  do
158  {
159  /* first, use buffer */
160  min = h->have - h->pos;
161  if (min > 0)
162  {
163  if (min > len - pos)
164  min = len - pos;
165  GNUNET_memcpy (&dst[pos], &h->buffer[h->pos], min);
166  h->pos += min;
167  pos += min;
168  }
169  if (pos == len)
170  return GNUNET_OK; /* done! */
171  GNUNET_assert (((off_t) h->have) == h->pos);
172  /* fill buffer */
173  ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size);
174  if (-1 == ret)
175  {
176  GNUNET_asprintf (&h->emsg,
177  _ ("Error reading `%s': %s"),
178  what,
179  strerror (errno));
180  return GNUNET_SYSERR;
181  }
182  if (0 == ret)
183  {
184  GNUNET_asprintf (&h->emsg,
185  _ ("Error reading `%s': %s"),
186  what,
187  _ ("End of file"));
188  return GNUNET_SYSERR;
189  }
190  h->pos = 0;
191  h->have = ret;
192  }
193  while (pos < len); /* should always be true */
194  return GNUNET_OK;
195 }
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:732
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_DISK_FileHandle * fd
Underlying file abstraction.
Definition: bio.c:58
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
size_t size
Total size of buffer.
Definition: bio.c:78
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
size_t have
Number of bytes available in read buffer.
Definition: bio.c:73
static int result
Global testing status.
char * buffer
I/O buffer.
Definition: bio.c:68
off_t pos
Current read offset in buffer.
Definition: bio.c:83
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:63
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_fn()

int GNUNET_BIO_read_fn ( struct GNUNET_BIO_ReadHandle h,
const char *  file,
int  line,
void *  result,
size_t  len 
)

Read the contents of a binary file into a buffer.

Parameters
hhandle to an open file
filename of the source file
lineline number in the source file
resultthe buffer to write the result to
lenthe number of bytes to read
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 209 of file bio.c.

References GNUNET_BIO_read(), GNUNET_snprintf(), and PATH_MAX.

Referenced by GNUNET_BIO_read_int32__(), and GNUNET_BIO_read_int64__().

214 {
215  char what[PATH_MAX + 1024];
216 
217  GNUNET_snprintf (what, sizeof(what), "%s:%d", file, line);
218  return GNUNET_BIO_read (h, what, result, len);
219 }
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: bio.c:144
static char * line
Desired phone line (string to be converted to a hash).
static int result
Global testing status.
#define PATH_MAX
Assumed maximum path length (for source file names).
Definition: bio.c:34
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_string()

int GNUNET_BIO_read_string ( struct GNUNET_BIO_ReadHandle h,
const char *  what,
char **  result,
size_t  max_length 
)

Read 0-terminated string from a file.

Parameters
hhandle to an open file
whatdescribes what is being read (for error message creation)
resultthe buffer to store a pointer to the (allocated) string to (note that *result could be set to NULL as well)
max_lengthmaximum allowed length for the string
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 233 of file bio.c.

References _, buf, GNUNET_BIO_ReadHandle::emsg, GNUNET_asprintf(), GNUNET_BIO_read(), GNUNET_BIO_read_int32, GNUNET_free, GNUNET_free_non_null, GNUNET_malloc, GNUNET_OK, and GNUNET_SYSERR.

Referenced by deserialize_download(), deserialize_fi_node(), deserialize_publish_file(), deserialize_search(), deserialize_search_result(), deserialize_unindex_file(), load_hostlist_file(), load_state(), read_index_list(), and read_update_information_graph().

237 {
238  char *buf;
239  uint32_t big;
240 
241  if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big))
242  {
244  GNUNET_asprintf (&h->emsg, _ ("Error reading length of string `%s'"), what);
245  return GNUNET_SYSERR;
246  }
247  if (0 == big)
248  {
249  *result = NULL;
250  return GNUNET_OK;
251  }
252  if (big > max_length)
253  {
254  GNUNET_asprintf (&h->emsg,
255  _ ("String `%s' longer than allowed (%u > %u)"),
256  what,
257  big,
258  max_length);
259  return GNUNET_SYSERR;
260  }
261  buf = GNUNET_malloc (big);
262  *result = buf;
263  buf[--big] = '\0';
264  if (0 == big)
265  return GNUNET_OK;
266  if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big))
267  {
268  GNUNET_free (buf);
269  *result = NULL;
270  return GNUNET_SYSERR;
271  }
272  return GNUNET_OK;
273 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: bio.c:144
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static char buf[2048]
static int result
Global testing status.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_BIO_read_int32(h, i)
Read an (u)int32_t.
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:63
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_meta_data()

int GNUNET_BIO_read_meta_data ( struct GNUNET_BIO_ReadHandle h,
const char *  what,
struct GNUNET_CONTAINER_MetaData **  result 
)

Read metadata container from a file.

Parameters
hhandle to an open file
whatdescribes what is being read (for error message creation)
resultthe buffer to store a pointer to the (allocated) metadata
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 285 of file bio.c.

References _, buf, GNUNET_BIO_ReadHandle::emsg, GNUNET_asprintf(), GNUNET_BIO_read(), GNUNET_BIO_read_int32, GNUNET_CONTAINER_meta_data_deserialize(), GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_SYSERR, MAX_META_DATA, meta, and GNUNET_BIO_ReadHandle::size.

Referenced by deserialize_download(), deserialize_fi_node(), deserialize_search_result(), and read_update_information_graph().

288 {
289  uint32_t size;
290  char *buf;
292 
293  if (GNUNET_OK != GNUNET_BIO_read_int32 (h, (int32_t *) &size))
294  return GNUNET_SYSERR;
295  if (size == 0)
296  {
297  *result = NULL;
298  return GNUNET_OK;
299  }
300  if (size > MAX_META_DATA)
301  {
302  GNUNET_asprintf (&h->emsg,
303  _ ("Serialized metadata `%s' larger than allowed (%u>%u)"),
304  what,
305  size,
306  MAX_META_DATA);
307  return GNUNET_SYSERR;
308  }
309  buf = GNUNET_malloc (size);
310  if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size))
311  {
312  GNUNET_free (buf);
313  return GNUNET_SYSERR;
314  }
315  meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size);
316  if (NULL == meta)
317  {
318  GNUNET_free (buf);
319  GNUNET_asprintf (&h->emsg, _ ("Metadata `%s' failed to deserialize"), what);
320  return GNUNET_SYSERR;
321  }
322  GNUNET_free (buf);
323  *result = meta;
324  return GNUNET_OK;
325 }
struct GNUNET_CONTAINER_MetaData * GNUNET_CONTAINER_meta_data_deserialize(const char *input, size_t size)
Deserialize meta-data.
#define MAX_META_DATA
Maximum size allowed for meta data written/read from disk.
Definition: bio.c:47
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: bio.c:144
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
Meta data to associate with a file, directory or namespace.
static char buf[2048]
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define GNUNET_BIO_read_int32(h, i)
Read an (u)int32_t.
static struct GNUNET_CONTAINER_MetaData * meta
Meta-data provided via command-line option.
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:63
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_int32__()

int GNUNET_BIO_read_int32__ ( struct GNUNET_BIO_ReadHandle h,
const char *  file,
int  line,
int32_t *  i 
)

Read an (u)int32_t.

Parameters
hhande to open file
filename of the source file
lineline number in the code
iaddress of 32-bit integer to read
Returns
GNUNET_OK on success, GNUNET_SYSERR on error
Parameters
hhande to open file
filename of the source file
lineline number in the source file
iaddress of 32-bit integer to read
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 338 of file bio.c.

References GNUNET_BIO_read_fn(), GNUNET_OK, and GNUNET_SYSERR.

342 {
343  int32_t big;
344 
345  if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof(int32_t)))
346  return GNUNET_SYSERR;
347  *i = ntohl (big);
348  return GNUNET_OK;
349 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static char * line
Desired phone line (string to be converted to a hash).
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
int GNUNET_BIO_read_fn(struct GNUNET_BIO_ReadHandle *h, const char *file, int line, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: bio.c:209
Here is the call graph for this function:

◆ GNUNET_BIO_read_int64__()

int GNUNET_BIO_read_int64__ ( struct GNUNET_BIO_ReadHandle h,
const char *  file,
int  line,
int64_t *  i 
)

Read an (u)int64_t.

Parameters
hhande to open file
filename of the source file
lineline number in the code
iaddress of 64-bit integer to read
Returns
GNUNET_OK on success, GNUNET_SYSERR on error
Parameters
hhande to open file
filename of the source file
lineline number in the source file
iaddress of 64-bit integer to read
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 362 of file bio.c.

References GNUNET_BIO_read_fn(), GNUNET_ntohll(), GNUNET_OK, and GNUNET_SYSERR.

366 {
367  int64_t big;
368 
369  if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof(int64_t)))
370  return GNUNET_SYSERR;
371  *i = GNUNET_ntohll (big);
372  return GNUNET_OK;
373 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static char * line
Desired phone line (string to be converted to a hash).
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
int GNUNET_BIO_read_fn(struct GNUNET_BIO_ReadHandle *h, const char *file, int line, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: bio.c:209
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
Here is the call graph for this function:

◆ GNUNET_BIO_write_open()

struct GNUNET_BIO_WriteHandle* GNUNET_BIO_write_open ( const char *  fn)

Open a file for writing.

Parameters
fnfile name to be opened
Returns
IO handle on success, NULL on error

Definition at line 410 of file bio.c.

References BIO_BUFFER_SIZE, GNUNET_BIO_WriteHandle::buffer, GNUNET_BIO_ReadHandle::fd, GNUNET_BIO_WriteHandle::fd, GNUNET_DISK_file_open(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_TRUNCATE, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_malloc, h, and GNUNET_BIO_WriteHandle::size.

Referenced by get_write_handle(), get_write_handle_in_dir(), GNUNET_FS_download_sync_(), GST_stats_init(), logger_run(), run(), save(), save_hostlist_file(), save_state(), write_index_list(), and write_update_information_graph().

411 {
412  struct GNUNET_DISK_FileHandle *fd;
413  struct GNUNET_BIO_WriteHandle *h;
414 
415  fd =
421  if (NULL == fd)
422  return NULL;
424  h->buffer = (char *) &h[1];
425  h->size = BIO_BUFFER_SIZE;
426  h->fd = fd;
427  return h;
428 }
Create file if it doesn&#39;t exist.
#define BIO_BUFFER_SIZE
Size for I/O buffers.
Definition: bio.c:41
struct GNUNET_DISK_FileHandle * fd
Underlying file handle.
Definition: bio.c:384
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static char * fn
Filename of the unique file.
Truncate file if it exists.
char * buffer
I/O buffer.
Definition: bio.c:389
Handle for buffered writing.
Definition: bio.c:379
Open the file for writing.
size_t size
Total size of buffer.
Definition: bio.c:399
int fd
File handle on Unix-like systems.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1268
Handle used to access files (and pipes).
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_close()

int GNUNET_BIO_write_close ( struct GNUNET_BIO_WriteHandle h)

Close an open file for writing.

Parameters
hfile handle
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise
Parameters
hfile handle
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 438 of file bio.c.

References GNUNET_BIO_WriteHandle::fd, GNUNET_BIO_flush(), GNUNET_DISK_file_close(), GNUNET_free, GNUNET_OK, GNUNET_SYSERR, and ret.

Referenced by GNUNET_FS_download_sync_(), GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_sync_(), GNUNET_FS_search_result_sync_(), GNUNET_FS_search_sync_(), GNUNET_FS_unindex_sync_(), GST_stats_destroy(), save(), save_hostlist_file(), save_state(), shutdown_task(), write_index_list(), and write_update_information_graph().

439 {
440  int ret;
441 
442  ret = GNUNET_SYSERR;
443  if ((NULL != h->fd) && (GNUNET_OK == (ret = GNUNET_BIO_flush (h))))
445  GNUNET_free (h);
446  return ret;
447 }
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1345
int GNUNET_BIO_flush(struct GNUNET_BIO_WriteHandle *h)
Force a buffered writer to flush its buffer.
Definition: bio.c:458
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_DISK_FileHandle * fd
Underlying file handle.
Definition: bio.c:384
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write()

int GNUNET_BIO_write ( struct GNUNET_BIO_WriteHandle h,
const void *  buffer,
size_t  n 
)

Write a buffer to a file.

Parameters
hhandle to open file
bufferthe data to write
nnumber of bytes to write
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 483 of file bio.c.

References GNUNET_BIO_ReadHandle::buffer, GNUNET_BIO_WriteHandle::buffer, GNUNET_BIO_WriteHandle::fd, GNUNET_assert, GNUNET_BIO_flush(), GNUNET_break, GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, GNUNET_BIO_WriteHandle::have, GNUNET_BIO_ReadHandle::pos, and GNUNET_BIO_WriteHandle::size.

Referenced by copy_from_reader(), GNUNET_BIO_write_int32(), GNUNET_BIO_write_int64(), GNUNET_BIO_write_meta_data(), GNUNET_BIO_write_string(), GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_sync_(), GNUNET_FS_search_result_sync_(), GNUNET_FS_search_sync_(), GNUNET_FS_unindex_sync_(), handle_log_msg(), sample_load_task(), save(), write_download_request(), write_index_list(), and write_item().

486 {
487  const char *src = buffer;
488  size_t min;
489  size_t pos;
490 
491  if (NULL == h->fd)
492  return GNUNET_SYSERR;
493  pos = 0;
494  do
495  {
496  /* first, just use buffer */
497  min = h->size - h->have;
498  if (min > n - pos)
499  min = n - pos;
500  GNUNET_memcpy (&h->buffer[h->have], &src[pos], min);
501  pos += min;
502  h->have += min;
503  if (pos == n)
504  return GNUNET_OK; /* done */
505  GNUNET_assert (h->have == h->size);
506  if (GNUNET_OK != GNUNET_BIO_flush (h))
507  return GNUNET_SYSERR; /* error */
508  }
509  while (pos < n); /* should always be true */
510  GNUNET_break (0);
511  return GNUNET_OK;
512 }
int GNUNET_BIO_flush(struct GNUNET_BIO_WriteHandle *h)
Force a buffered writer to flush its buffer.
Definition: bio.c:458
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_DISK_FileHandle * fd
Underlying file handle.
Definition: bio.c:384
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
size_t have
Number of bytes already in buffer.
Definition: bio.c:394
char * buffer
I/O buffer.
Definition: bio.c:389
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
size_t size
Total size of buffer.
Definition: bio.c:399
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_flush()

int GNUNET_BIO_flush ( struct GNUNET_BIO_WriteHandle h)

Force a buffered writer to flush its buffer.

Parameters
hthe writer handle
Returns
GNUNET_OK upon success. Upon failure GNUNET_SYSERR is returned and the file is closed

Definition at line 458 of file bio.c.

References GNUNET_BIO_WriteHandle::buffer, GNUNET_BIO_WriteHandle::fd, GNUNET_DISK_file_close(), GNUNET_DISK_file_write(), GNUNET_OK, GNUNET_SYSERR, GNUNET_BIO_WriteHandle::have, and ret.

Referenced by GNUNET_BIO_write(), and GNUNET_BIO_write_close().

459 {
460  ssize_t ret;
461 
462  ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
463  if (ret != (ssize_t) h->have)
464  {
466  h->fd = NULL;
467  return GNUNET_SYSERR; /* error */
468  }
469  h->have = 0;
470  return GNUNET_OK;
471 }
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1345
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_DISK_FileHandle * fd
Underlying file handle.
Definition: bio.c:384
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:820
size_t have
Number of bytes already in buffer.
Definition: bio.c:394
char * buffer
I/O buffer.
Definition: bio.c:389
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_string()

int GNUNET_BIO_write_string ( struct GNUNET_BIO_WriteHandle h,
const char *  s 
)

Write a string to a file.

Parameters
hhandle to open file
sstring to write (can be NULL)
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 523 of file bio.c.

References GNUNET_BIO_write(), GNUNET_BIO_write_int32(), GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_FS_download_sync_(), GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_sync_(), GNUNET_FS_search_result_sync_(), GNUNET_FS_search_sync_(), GNUNET_FS_unindex_sync_(), save_hostlist_file(), write_index_list(), write_item(), and write_update_information_graph().

524 {
525  uint32_t slen;
526 
527  slen = (uint32_t) ((s == NULL) ? 0 : strlen (s) + 1);
528  if (GNUNET_OK != GNUNET_BIO_write_int32 (h, slen))
529  return GNUNET_SYSERR;
530  if (0 != slen)
531  return GNUNET_BIO_write (h, s, slen - 1);
532  return GNUNET_OK;
533 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, int32_t i)
Write an (u)int32_t.
Definition: bio.c:582
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: bio.c:483
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_meta_data()

int GNUNET_BIO_write_meta_data ( struct GNUNET_BIO_WriteHandle h,
const struct GNUNET_CONTAINER_MetaData m 
)

Write metadata container to a file.

Parameters
hhandle to open file
mmetadata to write
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 544 of file bio.c.

References buf, GNUNET_BIO_write(), GNUNET_BIO_write_int32(), GNUNET_CONTAINER_meta_data_serialize(), GNUNET_CONTAINER_META_DATA_SERIALIZE_PART, GNUNET_free, GNUNET_OK, GNUNET_SYSERR, MAX_META_DATA, and GNUNET_BIO_ReadHandle::size.

Referenced by GNUNET_FS_download_sync_(), GNUNET_FS_file_information_sync_(), GNUNET_FS_search_result_sync_(), and write_update_information_graph().

546 {
547  ssize_t size;
548  char *buf;
549 
550  if (m == NULL)
551  return GNUNET_BIO_write_int32 (h, 0);
552  buf = NULL;
554  m,
555  &buf,
558  if (size == -1)
559  {
560  GNUNET_free (buf);
561  return GNUNET_SYSERR;
562  }
563  if ((GNUNET_OK != GNUNET_BIO_write_int32 (h, (uint32_t) size)) ||
564  (GNUNET_OK != GNUNET_BIO_write (h, buf, size)))
565  {
566  GNUNET_free (buf);
567  return GNUNET_SYSERR;
568  }
569  GNUNET_free (buf);
570  return GNUNET_OK;
571 }
ssize_t GNUNET_CONTAINER_meta_data_serialize(const struct GNUNET_CONTAINER_MetaData *md, char **target, size_t max, enum GNUNET_CONTAINER_MetaDataSerializationOptions opt)
Serialize meta-data to target.
If not enough space is available, it is acceptable to only serialize some of the metadata.
#define MAX_META_DATA
Maximum size allowed for meta data written/read from disk.
Definition: bio.c:47
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static char buf[2048]
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:67
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, int32_t i)
Write an (u)int32_t.
Definition: bio.c:582
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: bio.c:483
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_int32()

int GNUNET_BIO_write_int32 ( struct GNUNET_BIO_WriteHandle h,
int32_t  i 
)

Write an (u)int32_t.

Parameters
hhande to open file
i32-bit integer to write
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 582 of file bio.c.

References GNUNET_BIO_write().

Referenced by GNUNET_BIO_write_meta_data(), GNUNET_BIO_write_string(), GNUNET_FS_download_sync_(), GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_sync_(), GNUNET_FS_search_result_sync_(), GNUNET_FS_search_sync_(), GNUNET_FS_unindex_sync_(), save_hostlist_file(), save_state(), write_download_request(), and write_update_information_graph().

583 {
584  int32_t big;
585 
586  big = htonl (i);
587  return GNUNET_BIO_write (h, &big, sizeof(int32_t));
588 }
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: bio.c:483
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_int64()

int GNUNET_BIO_write_int64 ( struct GNUNET_BIO_WriteHandle h,
int64_t  i 
)

Write an (u)int64_t.

Parameters
hhande to open file
i64-bit integer to write
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 599 of file bio.c.

References GNUNET_BIO_write(), and GNUNET_htonll().

Referenced by GNUNET_FS_download_sync_(), GNUNET_FS_file_information_sync_(), GNUNET_FS_unindex_sync_(), handle_p2p_estimate(), save_hostlist_file(), write_download_request(), and write_start_time().

600 {
601  int64_t big;
602 
603  big = GNUNET_htonll (i);
604  return GNUNET_BIO_write (h, &big, sizeof(int64_t));
605 }
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: bio.c:483
Here is the call graph for this function:
Here is the caller graph for this function: