PARA_INFO_LOG("afs_database dir %s\n", database_dir);
}
-static int make_database_dir(void)
-{
- int ret;
-
- get_database_dir();
- ret = para_mkdir(database_dir, 0777);
- if (ret >= 0 || ret == -ERRNO_TO_PARA_ERROR(EEXIST))
- return 1;
- return ret;
-}
-
static int open_afs_tables(void)
{
int i, ret;
.size = sizeof(table_mask)};
unsigned num_inputs = lls_num_inputs(lpr);
- ret = make_database_dir();
+ get_database_dir();
+ ret = para_mkdir(database_dir);
if (ret < 0)
return ret;
if (num_inputs > 0) {
}
/**
- * A wrapper for mkdir(2).
+ * Create a directory, don't fail if it already exists.
*
* \param path Name of the directory to create.
- * \param mode The permissions to use.
*
- * \return Standard.
+ * This function passes the fixed mode value 0777 to mkdir(3) (which consults
+ * the file creation mask and restricts this value).
+ *
+ * \return Zero if the directory already existed, one if the directory has been
+ * created, negative error code if the mkdir(3) call failed for any reason
+ * other than EEXIST.
*/
-int para_mkdir(const char *path, mode_t mode)
+int para_mkdir(const char *path)
{
- if (!mkdir(path, mode))
+ if (mkdir(path, 0777) == 0)
return 1;
+ if (errno == EEXIST)
+ return 0;
return -ERRNO_TO_PARA_ERROR(errno);
}
__must_check int mark_fd_blocking(int fd);
int para_mmap(size_t length, int prot, int flags, int fd, void *map);
int para_open(const char *path, int flags, mode_t mode);
-int para_mkdir(const char *path, mode_t mode);
+int para_mkdir(const char *path);
int mmap_full_file(const char *filename, int open_mode, void **map,
size_t *size, int *fd_ptr);
int para_munmap(void *start, size_t length);
char *dot_para = make_message("%s/.paraslash", home);
free(home);
- ret = para_mkdir(dot_para, 0777);
+ ret = para_mkdir(dot_para);
/* warn, but otherwise ignore mkdir error */
- if (ret < 0 && ret != -ERRNO_TO_PARA_ERROR(EEXIST))
+ if (ret < 0)
PARA_WARNING_LOG("Can not create %s: %s\n", dot_para,
para_strerror(-ret));
history_file = make_message("%s/play.history", dot_para);