*/
#include "platform.h"
-#include "io_handle.h"
#include "gnunet_common.h"
#include "gnunet_directories.h"
-#include "gnunet_io_lib.h"
#include "gnunet_disk_lib.h"
#include "gnunet_scheduler_lib.h"
#include "gnunet_strings_lib.h"
int include_sym_links;
} GetFileSizeData;
+struct GNUNET_IO_Handle
+{
+#if MINGW
+ HANDLE h;
+#else
+ int fd;
+#endif
+};
+
static int
getSizeRec (void *ptr, const char *fn)
{
return GNUNET_OK;
}
+/**
+ * Checks whether a handle is invalid
+ * @param h handle to check
+ * @return GNUNET_YES if invalid, GNUNET_NO if valid
+ */
+int
+GNUNET_DISK_handle_invalid (const struct GNUNET_IO_Handle *h)
+{
+#ifdef MINGW
+ return !h || h->h == INVALID_HANDLE_VALUE ? GNUNET_YES : GNUNET_NO;
+#else
+ return !h || h->fd == -1 ? GNUNET_YES : GNUNET_NO;
+#endif
+}
+
+/**
+ * Mark a handle as invalid
+ * @param h file handle
+ */
+static void
+GNUNET_DISK_handle_invalidate (struct GNUNET_IO_Handle *h)
+{
+#ifdef MINGW
+ h->h = INVALID_HANDLE_VALUE;
+#else
+ h->fd = -1;
+#endif
+}
/**
* Move the read/write pointer in a file
* @param fn file name
* @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
+ * @return number of bytes read, GNUNET_SYSERR on failure
*/
int
GNUNET_DISK_fn_read (const char * const fn, void *result, int len)
* @param fn file name
* @param buffer the data to write
* @param n number of bytes to write
- * @return number of bytes written on success, GNUNET_SYSERR on error
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int
GNUNET_DISK_fn_write (const char * const fn, const void *buffer,
| GNUNET_DISK_OPEN_CREATE, mode);
if (!fh)
return GNUNET_SYSERR;
- ret = GNUNET_DISK_file_write (fh, buffer, n);
+ ret = (n == GNUNET_DISK_file_write (fh, buffer, n)) ? GNUNET_OK : GNUNET_SYSERR;
GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(&fh));
return ret;
}
#endif
- GNUNET_IO_handle_invalidate (*h);
+ GNUNET_DISK_handle_invalidate (*h);
free(*h);
*h = NULL;
SetErrnoFromWinError (GetLastError ());
}
- GNUNET_IO_handle_invalidate (*h);
+ GNUNET_DISK_handle_invalidate (*h);
GNUNET_free (*h);
h = NULL;
#else
int ret;
ret = munmap (addr, len) != -1 ? GNUNET_OK : GNUNET_SYSERR;
- GNUNET_IO_handle_invalidate (h);
+ GNUNET_DISK_handle_invalidate (*h);
return ret;
#endif
}