Imported Upstream version 0.6.2.17
[psensor-pkg-debian.git] / src / lib / p_io.h
1 /*
2  * Copyright (C) 2010-2012 jeanfi@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19 #ifndef _P_IO_H
20 #define _P_IO_H
21
22 /* Returns '1' if a given 'path' denotates a directory else returns
23    0 */
24 int is_dir(const char *path);
25
26 /* Returns '1' if a given 'path' denotates a file else returns
27    0 */
28 int is_file(const char *path);
29
30 /*  Returns a normalized path */
31 char *path_normalize(const char *dpath);
32
33 /*  Returns the null-terminated entries of a directory */
34 char **dir_list(const char *dpath, int (*filter) (const char *path));
35 void paths_free(char **paths);
36
37 char *path_append(const char *dir, const char *path);
38
39 /*
40    Returns the size of a file.
41    Returns '-1' if the size cannot be retrieved or not a file.
42 */
43 long file_get_size(const char *path);
44
45 /*
46    Returns the content of a file.
47    Returns 'NULL' if the file cannot be read or failed to allocate
48    enough memory.
49    Returns an empty string if the file exists but is empty.
50 */
51 char *file_get_content(const char *path);
52
53 enum file_copy_error {
54         FILE_COPY_ERROR_OPEN_SRC = 1,
55         FILE_COPY_ERROR_OPEN_DST,
56         FILE_COPY_ERROR_READ,
57         FILE_COPY_ERROR_WRITE,
58         FILE_COPY_ERROR_ALLOC_BUFFER
59 };
60
61 void file_copy_print_error(int code, const char *src, const char *dst);
62
63 /*
64   Copy a file.
65
66   Returns '0' if sucessfull, otherwise return the error code.
67 */
68 int file_copy(const char *src, const char *dst);
69
70 #endif