*/
#include "platform.h"
-#include "gnunet_directories.h"
#include "gnunet_util_lib.h"
#include "disk.h"
* Iterate over all files in the given directory and
* accumulate their size.
*
- * @param cls closure of type "struct GetFileSizeData"
+ * @param cls closure of type `struct GetFileSizeData`
* @param fn current filename we are looking at
- * @return GNUNET_SYSERR on serious errors, otherwise GNUNET_OK
+ * @return #GNUNET_SYSERR on serious errors, otherwise #GNUNET_OK
*/
static int
getSizeRec (void *cls, const char *fn)
* Checks whether a handle is invalid
*
* @param h handle to check
- * @return GNUNET_YES if invalid, GNUNET_NO if valid
+ * @return #GNUNET_YES if invalid, #GNUNET_NO if valid
*/
int
GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h)
*
* @param fh open file handle
* @param size where to write size of the file
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
* @param h handle of an open file
* @param offset position to move to
* @param whence specification to which position the offset parameter relates to
- * @return the new position on success, GNUNET_SYSERR otherwise
+ * @return the new position on success, #GNUNET_SYSERR otherwise
*/
off_t
GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset,
* of all sizes of files in the directory)
* @param include_symbolic_links should symbolic links be
* included?
- * @param single_file_mode GNUNET_YES to only get size of one file
- * and return GNUNET_SYSERR for directories.
- * @return GNUNET_SYSERR on error, GNUNET_OK on success
+ * @param single_file_mode #GNUNET_YES to only get size of one file
+ * and return #GNUNET_SYSERR for directories.
+ * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
*/
int
-GNUNET_DISK_file_size (const char *filename, uint64_t * size,
- int include_symbolic_links, int single_file_mode)
+GNUNET_DISK_file_size (const char *filename,
+ uint64_t * size,
+ int include_symbolic_links,
+ int single_file_mode)
{
struct GetFileSizeData gfsd;
int ret;
* (of a file that exists and that is not a directory).
*
* @param fil filename to check
- * @return #GNUNET_YES if yes, GNUNET_NO if not a file, #GNUNET_SYSERR if something
+ * @return #GNUNET_YES if yes, #GNUNET_NO if not a file, #GNUNET_SYSERR if something
* else (will print an error message in that case, too).
*/
int
GNUNET_DISK_directory_create_for_file (const char *filename)
{
char *rdir;
- int len;
+ size_t len;
int ret;
rdir = GNUNET_STRINGS_filename_expand (filename);
*
* @param unused not used
* @param fn directory to remove
- * @return GNUNET_OK
+ * @return #GNUNET_OK
*/
static int
remove_helper (void *unused, const char *fn)
* Remove all files in a directory (rm -rf). Call with
* caution.
*
- *
* @param filename the file to remove
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
GNUNET_DISK_directory_remove (const char *filename)
{
struct stat istat;
+ if (NULL == filename)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (0 != LSTAT (filename, &istat))
return GNUNET_NO; /* file may not exist... */
(void) CHMOD (filename, S_IWUSR | S_IRUSR | S_IXUSR);
* @param fh file handle
* @param unlock_start absolute position from where to unlock
* @param unlock_end absolute position until where to unlock
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlock_start,
* otherwise we're screwed, as selecting on non-overlapped handle
* will block.
*/
- fh->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED));
- fh->oOverlapWrite = GNUNET_malloc (sizeof (OVERLAPPED));
+ fh->oOverlapRead = GNUNET_new (OVERLAPPED);
+ fh->oOverlapWrite = GNUNET_new (OVERLAPPED);
fh->oOverlapRead->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
fh->oOverlapWrite->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
}
p->fd[0]->type = GNUNET_DISK_HANLDE_TYPE_PIPE;
p->fd[1]->type = GNUNET_DISK_HANLDE_TYPE_PIPE;
- p->fd[0]->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED));
- p->fd[0]->oOverlapWrite = GNUNET_malloc (sizeof (OVERLAPPED));
- p->fd[1]->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED));
- p->fd[1]->oOverlapWrite = GNUNET_malloc (sizeof (OVERLAPPED));
+ p->fd[0]->oOverlapRead = GNUNET_new (OVERLAPPED);
+ p->fd[0]->oOverlapWrite = GNUNET_new (OVERLAPPED);
+ p->fd[1]->oOverlapRead = GNUNET_new (OVERLAPPED);
+ p->fd[1]->oOverlapWrite = GNUNET_new (OVERLAPPED);
p->fd[0]->oOverlapRead->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
p->fd[0]->oOverlapWrite->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
if (p->fd[0]->h != INVALID_HANDLE_VALUE)
{
p->fd[0]->type = GNUNET_DISK_HANLDE_TYPE_PIPE;
- p->fd[0]->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED));
- p->fd[0]->oOverlapWrite = GNUNET_malloc (sizeof (OVERLAPPED));
+ p->fd[0]->oOverlapRead = GNUNET_new (OVERLAPPED);
+ p->fd[0]->oOverlapWrite = GNUNET_new (OVERLAPPED);
p->fd[0]->oOverlapRead->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
p->fd[0]->oOverlapWrite->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
}
if (p->fd[1]->h != INVALID_HANDLE_VALUE)
{
p->fd[1]->type = GNUNET_DISK_HANLDE_TYPE_PIPE;
- p->fd[1]->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED));
- p->fd[1]->oOverlapWrite = GNUNET_malloc (sizeof (OVERLAPPED));
+ p->fd[1]->oOverlapRead = GNUNET_new (OVERLAPPED);
+ p->fd[1]->oOverlapWrite = GNUNET_new (OVERLAPPED);
p->fd[1]->oOverlapRead->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
p->fd[1]->oOverlapWrite->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
}
* @param fh GNUnet file descriptor
* @param dst destination buffer
* @param dst_len length of dst
- * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
*/
int
GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
void *dst, size_t dst_len)
{
+ if (NULL == fh)
+ return GNUNET_SYSERR;
#ifdef MINGW
if (dst_len < sizeof (HANDLE))
return GNUNET_SYSERR;