/*
This file is part of GNUnet.
- Copyright (C) 2001--2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2001--2013 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
-
/**
* @file util/disk.c
* @brief disk IO convenience methods
* @author Christian Grothoff
* @author Nils Durner
*/
-
#include "platform.h"
-#include "gnunet_util_lib.h"
#include "disk.h"
+#include "gnunet_strings_lib.h"
+#include "gnunet_disk_lib.h"
#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
GNUNET_DISK_mkdtemp (const char *t)
{
char *fn;
+ mode_t omask;
+ omask = umask (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH);
fn = mktemp_name (t);
if (fn != mkdtemp (fn))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkdtemp", fn);
GNUNET_free (fn);
+ umask (omask);
return NULL;
}
+ umask (omask);
return fn;
}
{
int fd;
char *fn;
+ mode_t omask;
+ omask = umask (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH);
fn = mktemp_name (t);
if (-1 == (fd = mkstemp (fn)))
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn);
GNUNET_free (fn);
+ umask (omask);
return NULL;
}
+ umask (omask);
if (0 != CLOSE (fd))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "close", fn);
return fn;
* with the same name).
*
* @param fil filename to test
- * @param is_readable GNUNET_YES to additionally check if @a fil is readable;
+ * @param is_readable #GNUNET_YES to additionally check if @a fil is readable;
* #GNUNET_NO to disable this check
* @return #GNUNET_YES if yes, #GNUNET_NO if not; #GNUNET_SYSERR if it
* does not exist or stat'ed
/**
- * Create the directory structure for storing
- * a file.
+ * Create the directory structure for storing a file.
*
* @param filename name of a file in the directory
* @returns #GNUNET_OK on success,
char *rdir;
size_t len;
int ret;
+ int eno;
rdir = GNUNET_STRINGS_filename_expand (filename);
- if (rdir == NULL)
+ if (NULL == rdir)
+ {
+ errno = EINVAL;
return GNUNET_SYSERR;
+ }
len = strlen (rdir);
while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
len--;
rdir[len] = '\0';
+ /* The empty path is invalid and in this case refers to / */
+ if (0 == len)
+ {
+ GNUNET_free (rdir);
+ rdir = GNUNET_strdup ("/");
+ }
ret = GNUNET_DISK_directory_create (rdir);
- if ((ret == GNUNET_OK) && (0 != ACCESS (rdir, W_OK)))
+ if ((GNUNET_OK == ret) && (0 != ACCESS (rdir, W_OK)))
ret = GNUNET_NO;
+ eno = errno;
GNUNET_free (rdir);
+ errno = eno;
return ret;
}
* @return number of bytes written on success, #GNUNET_SYSERR on error
*/
ssize_t
-GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n,
+GNUNET_DISK_fn_write (const char *fn,
+ const void *buffer,
+ size_t n,
enum GNUNET_DISK_AccessPermissions mode)
{
struct GNUNET_DISK_FileHandle *fh;