Update URLs and email addresses.
[osl.git] / util.h
1 /*
2 * Copyright (C) 2006-2009 Andre Noll <maan@tuebingen.mpg.de>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 /** \file util.h exported functions from util.c */
8
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);
16
17 /**
18 * A wrapper for mkdir(2).
19 *
20 * \param path Name of the directory to create.
21 * \param mode The permissions to use.
22 *
23 * \return Standard.
24 */
25 static inline int osl_mkdir(const char *path, mode_t mode)
26 {
27 if (!mkdir(path, mode))
28 return 1;
29 return errno == EEXIST? -E_OSL_DIR_EXISTS : -E_OSL_MKDIR;
30 }
31
32 /**
33 * A wrapper for rename(2).
34 *
35 * \param old_path The source path.
36 * \param new_path The destination path.
37 *
38 * \return Standard.
39 *
40 * \sa rename(2).
41 */
42 _static_inline_ int osl_rename(const char *old_path, const char *new_path)
43 {
44 if (rename(old_path, new_path) < 0)
45 return -E_OSL_RENAME;
46 return 1;
47 }
48
49 _static_inline_ int osl_stat(const char *path, struct stat *buf)
50 {
51 if (stat(path, buf) >= 0)
52 return 1;
53 return errno == ENOENT? -E_OSL_NOENT : -E_OSL_STAT;
54 }