X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Finclude%2Fgnunet_disk_lib.h;h=46dd7c4c40ab24bfd503ae40fe1986f0b6bafa17;hb=b0c7119fa2f43fe1b5978651152974359de5a5d2;hp=d0a9dfdb7563b940571ef9783488e24353c951c7;hpb=2fa26e646e1cfdba15d02ce3428ed72e93d73a09;p=oweals%2Fgnunet.git diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h index d0a9dfdb7..46dd7c4c4 100644 --- a/src/include/gnunet_disk_lib.h +++ b/src/include/gnunet_disk_lib.h @@ -25,6 +25,12 @@ #ifndef GNUNET_DISK_LIB_H #define GNUNET_DISK_LIB_H +#if WINDOWS +#define OFF_T uint64_t +#else +#define OFF_T off_t +#endif + /** * Opaque handle used to access files. */ @@ -295,8 +301,8 @@ GNUNET_DISK_file_test (const char *fil); * @param whence specification to which position the offset parameter relates to * @return the new position on success, GNUNET_SYSERR otherwise */ -off_t -GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset, +OFF_T +GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, OFF_T offset, enum GNUNET_DISK_Seek whence); @@ -378,7 +384,7 @@ GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, */ int GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, - off_t *size); + OFF_T *size); /** @@ -389,9 +395,21 @@ GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, * @return handle to the new pipe, NULL on error */ struct GNUNET_DISK_PipeHandle * -GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write); +GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int inherit_write); +/** + * Creates a pipe object from a couple of file descriptors. + * Useful for wrapping existing pipe FDs. + * + * @param blocking creates an asynchronous pipe if set to GNUNET_NO + * @param fd an array of two fd values. One of them may be -1 for read-only or write-only pipes + * + * @return handle to the new pipe, NULL on error + */ +struct GNUNET_DISK_PipeHandle * +GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2]); + /** * Closes an interprocess channel * @param p pipe @@ -443,6 +461,19 @@ 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. + * Guarantees not to block (returns GNUNET_SYSERR and sets errno to EAGAIN + * when no data can be read). + * + * @param h handle to an open file + * @param result the buffer to write the result to + * @param len the maximum number of bytes to read + * @return the number of bytes read on success, GNUNET_SYSERR on failure + */ +ssize_t +GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle * h, + void *result, size_t len); /** * Read the contents of a binary file into a buffer. @@ -469,6 +500,17 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n); +/** + * Write a buffer to a file, blocking, if necessary. + * @param h handle to open file + * @param buffer the data to write + * @param n number of bytes to write + * @return number of bytes written on success, GNUNET_SYSERR on error + */ +ssize_t +GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h, + const void *buffer, size_t n); + /** * Write a buffer to a file. If the file is longer than * the given buffer size, it will be truncated. @@ -559,8 +601,10 @@ GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter, * @param dirName the name of the directory * @param callback the method to call for each file * @param callback_cls closure for callback + * @return GNUNET_YES if directory is not empty and @callback + * will be called later, GNUNET_NO otherwise, GNUNET_SYSERR on error. */ -void +int GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio, const char *dirName, GNUNET_DISK_DirectoryIteratorCallback @@ -624,8 +668,8 @@ GNUNET_DISK_directory_create (const char *dir); * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, - off_t lockEnd, int excl); +GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, OFF_T lockStart, + OFF_T lockEnd, int excl); /** @@ -636,8 +680,8 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart, - off_t unlockEnd); +GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, OFF_T unlockStart, + OFF_T unlockEnd); /**