aboutsummaryrefslogtreecommitdiff
path: root/src/util/disk.c
diff options
context:
space:
mode:
authorNils Durner <durner@gnunet.org>2009-06-16 20:13:13 +0000
committerNils Durner <durner@gnunet.org>2009-06-16 20:13:13 +0000
commitdc6e9887c24209d0e3dfb6cfb30fbde6ae3b47e9 (patch)
tree08e0d0aaf9d67b2fd259dcfed6def6abc91f34c4 /src/util/disk.c
parent841cf45c29f46825a8e9913c6e45dcff21318f5a (diff)
downloadgnunet-dc6e9887c24209d0e3dfb6cfb30fbde6ae3b47e9.tar.gz
gnunet-dc6e9887c24209d0e3dfb6cfb30fbde6ae3b47e9.zip
GNUNET_IO_handle => GNUNET_DISK_handle
Diffstat (limited to 'src/util/disk.c')
-rw-r--r--src/util/disk.c49
1 files changed, 42 insertions, 7 deletions
diff --git a/src/util/disk.c b/src/util/disk.c
index 2c592dcfa..2722dda71 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -26,10 +26,8 @@
26 */ 26 */
27 27
28#include "platform.h" 28#include "platform.h"
29#include "io_handle.h"
30#include "gnunet_common.h" 29#include "gnunet_common.h"
31#include "gnunet_directories.h" 30#include "gnunet_directories.h"
32#include "gnunet_io_lib.h"
33#include "gnunet_disk_lib.h" 31#include "gnunet_disk_lib.h"
34#include "gnunet_scheduler_lib.h" 32#include "gnunet_scheduler_lib.h"
35#include "gnunet_strings_lib.h" 33#include "gnunet_strings_lib.h"
@@ -76,6 +74,15 @@ typedef struct
76 int include_sym_links; 74 int include_sym_links;
77} GetFileSizeData; 75} GetFileSizeData;
78 76
77struct GNUNET_IO_Handle
78{
79#if MINGW
80 HANDLE h;
81#else
82 int fd;
83#endif
84};
85
79static int 86static int
80getSizeRec (void *ptr, const char *fn) 87getSizeRec (void *ptr, const char *fn)
81{ 88{
@@ -111,6 +118,34 @@ getSizeRec (void *ptr, const char *fn)
111 return GNUNET_OK; 118 return GNUNET_OK;
112} 119}
113 120
121/**
122 * Checks whether a handle is invalid
123 * @param h handle to check
124 * @return GNUNET_YES if invalid, GNUNET_NO if valid
125 */
126int
127GNUNET_DISK_handle_invalid (const struct GNUNET_IO_Handle *h)
128{
129#ifdef MINGW
130 return !h || h->h == INVALID_HANDLE_VALUE ? GNUNET_YES : GNUNET_NO;
131#else
132 return !h || h->fd == -1 ? GNUNET_YES : GNUNET_NO;
133#endif
134}
135
136/**
137 * Mark a handle as invalid
138 * @param h file handle
139 */
140static void
141GNUNET_DISK_handle_invalidate (struct GNUNET_IO_Handle *h)
142{
143#ifdef MINGW
144 h->h = INVALID_HANDLE_VALUE;
145#else
146 h->fd = -1;
147#endif
148}
114 149
115/** 150/**
116 * Move the read/write pointer in a file 151 * Move the read/write pointer in a file
@@ -435,7 +470,7 @@ GNUNET_DISK_file_read (const struct GNUNET_IO_Handle *h, void *result, int len)
435 * @param fn file name 470 * @param fn file name
436 * @param result the buffer to write the result to 471 * @param result the buffer to write the result to
437 * @param len the maximum number of bytes to read 472 * @param len the maximum number of bytes to read
438 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 473 * @return number of bytes read, GNUNET_SYSERR on failure
439 */ 474 */
440int 475int
441GNUNET_DISK_fn_read (const char * const fn, void *result, int len) 476GNUNET_DISK_fn_read (const char * const fn, void *result, int len)
@@ -446,7 +481,7 @@ GNUNET_DISK_fn_read (const char * const fn, void *result, int len)
446 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ); 481 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ);
447 if (!fh) 482 if (!fh)
448 return GNUNET_SYSERR; 483 return GNUNET_SYSERR;
449 ret = (len == GNUNET_DISK_file_read (fh, result, len)) ? GNUNET_OK : GNUNET_SYSERR; 484 ret = GNUNET_DISK_file_read (fh, result, len);
450 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(&fh)); 485 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(&fh));
451 486
452 return ret; 487 return ret;
@@ -1094,7 +1129,7 @@ GNUNET_DISK_file_close (struct GNUNET_IO_Handle **h)
1094 } 1129 }
1095#endif 1130#endif
1096 1131
1097 GNUNET_IO_handle_invalidate (*h); 1132 GNUNET_DISK_handle_invalidate (*h);
1098 free(*h); 1133 free(*h);
1099 *h = NULL; 1134 *h = NULL;
1100 1135
@@ -1272,7 +1307,7 @@ GNUNET_DISK_file_unmap (struct GNUNET_IO_Handle **h, void *addr, size_t len)
1272 SetErrnoFromWinError (GetLastError ()); 1307 SetErrnoFromWinError (GetLastError ());
1273 } 1308 }
1274 1309
1275 GNUNET_IO_handle_invalidate (*h); 1310 GNUNET_DISK_handle_invalidate (*h);
1276 GNUNET_free (*h); 1311 GNUNET_free (*h);
1277 h = NULL; 1312 h = NULL;
1278 1313
@@ -1280,7 +1315,7 @@ GNUNET_DISK_file_unmap (struct GNUNET_IO_Handle **h, void *addr, size_t len)
1280#else 1315#else
1281 int ret; 1316 int ret;
1282 ret = munmap (addr, len) != -1 ? GNUNET_OK : GNUNET_SYSERR; 1317 ret = munmap (addr, len) != -1 ? GNUNET_OK : GNUNET_SYSERR;
1283 GNUNET_IO_handle_invalidate (h); 1318 GNUNET_DISK_handle_invalidate (*h);
1284 return ret; 1319 return ret;
1285#endif 1320#endif
1286} 1321}