X-Git-Url: http://git.tuebingen.mpg.de/?p=osl.git;a=blobdiff_plain;f=util.h;fp=util.h;h=2e3c66fcf0214e5bb2b098d02cfce5758e5500e4;hp=0000000000000000000000000000000000000000;hb=c1a4bb030717f2d2d209ccd8ab898ab66fa16869;hpb=afee1a06bfa10366c0acb366a2f3b4c09f912cf3 diff --git a/util.h b/util.h new file mode 100644 index 0000000..2e3c66f --- /dev/null +++ b/util.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2006-2008 Andre Noll + * + * Licensed under the GPL v2. For licencing details see COPYING. + */ + +/** \file util.h exported functions from util.c */ + +int osl_open(const char *path, int flags, mode_t mode); +int mmap_full_file(const char *filename, int open_mode, void **map, + size_t *size, int *fd_ptr); +int osl_munmap(void *start, size_t length); +int write_all(int fd, const char *buf, size_t *len); +int write_file(const char *filename, const void *buf, size_t size); +int truncate_file(const char *filename, off_t size); + +/** + * A wrapper for mkdir(2). + * + * \param path Name of the directory to create. + * \param mode The permissions to use. + * + * \return Standard. + */ +static inline int osl_mkdir(const char *path, mode_t mode) +{ + if (!mkdir(path, mode)) + return 1; + return -ERRNO_TO_ERROR(errno); +} + +/** + * A wrapper for rename(2). + * + * \param old_path The source path. + * \param new_path The destination path. + * + * \return Standard. + * + * \sa rename(2). + */ +_static_inline_ int osl_rename(const char *old_path, const char *new_path) +{ + if (rename(old_path, new_path) < 0) + return -ERRNO_TO_ERROR(errno); + return 1; +} + +_static_inline_ int osl_stat(const char *path, struct stat *buf) +{ + if (stat(path, buf) >= 0) + return 1; + return -ERRNO_TO_ERROR(errno); +}