2 * Copyright (C) 2006-2009 Andre Noll <maan@tuebingen.mpg.de>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file util.h exported functions from util.c */
9 int osl_open(const char *path, int flags, mode_t mode);
10 int mmap_full_file(const char *filename, int open_mode, void **map,
11 size_t *size, int *fd_ptr);
12 int osl_munmap(void *start, size_t length);
13 int write_all(int fd, const char *buf, size_t *len);
14 int write_file(const char *filename, const void *buf, size_t size);
15 int truncate_file(const char *filename, off_t size);
18 * A wrapper for mkdir(2).
20 * \param path Name of the directory to create.
21 * \param mode The permissions to use.
25 static inline int osl_mkdir(const char *path, mode_t mode)
27 if (!mkdir(path, mode))
29 return errno == EEXIST? -E_OSL_DIR_EXISTS : -E_OSL_MKDIR;
33 * A wrapper for rename(2).
35 * \param old_path The source path.
36 * \param new_path The destination path.
42 _static_inline_ int osl_rename(const char *old_path, const char *new_path)
44 if (rename(old_path, new_path) < 0)
49 _static_inline_ int osl_stat(const char *path, struct stat *buf)
51 if (stat(path, buf) >= 0)
53 return errno == ENOENT? -E_OSL_NOENT : -E_OSL_STAT;