*/
#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;
oflags |= O_TRUNC;
if (flags & GNUNET_DISK_OPEN_CREATE)
{
+ int perm;
+
oflags |= O_CREAT;
va_list arg;
va_start (arg, flags);
- mode = va_arg (arg, int);
+ perm = va_arg (arg, int);
va_end (arg);
+
+ mode = 0;
+ if (perm & GNUNET_DISK_PERM_USER_READ)
+ mode = S_IRUSR;
+ if (perm & GNUNET_DISK_PERM_USER_WRITE)
+ mode |= S_IWUSR;
+ if (perm & GNUNET_DISK_PERM_USER_EXEC)
+ mode |= S_IXUSR;
+ if (perm & GNUNET_DISK_PERM_GROUP_READ)
+ mode = S_IRGRP;
+ if (perm & GNUNET_DISK_PERM_GROUP_WRITE)
+ mode |= S_IWGRP;
+ if (perm & GNUNET_DISK_PERM_GROUP_EXEC)
+ mode |= S_IXGRP;
+ if (perm & GNUNET_DISK_PERM_OTHER_READ)
+ mode = S_IROTH;
+ if (perm & GNUNET_DISK_PERM_OTHER_WRITE)
+ mode |= S_IWOTH;
+ if (perm & GNUNET_DISK_PERM_OTHER_EXEC)
+ mode |= S_IXOTH;
}
if (flags & GNUNET_DISK_OPEN_APPEND)
oflags = O_APPEND;
-s fd = open (expfn, oflag | O_LARGEFILE, perm, mode);
+ fd = open (expfn, oflags | O_LARGEFILE, mode);
if (fd == -1)
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", fn);
}
#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
}