import psensor trunk from private svn
[psensor.git] / src / plib / plib_io.h
1 /*
2     Copyright (C) 2010-2011 wpitchoune@gmail.com
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU 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
20 #ifndef _P_IO_H
21 #define _P_IO_H
22
23 /* Returns '1' if a given 'path' denotates a directory else returns
24    0 */
25 int is_dir(const char *path);
26
27 /* Returns '1' if a given 'path' denotates a file else returns
28    0 */
29 int is_file(const char *path);
30
31 /*  Returns a normalized path */
32 char *path_normalize(const char *dpath);
33
34 /*  Returns the null-terminated entries of a directory */
35 char **dir_list(const char *dpath, int (*filter) (const char *path));
36 void paths_free(char **paths);
37
38 char *path_append(const char *dir, const char *path);
39
40 /*
41    Returns the size of a file.
42    Returns '-1' if the size cannot be retrieved or not a file.
43 */
44 long file_get_size(const char *path);
45
46 /*
47    Returns the content of a file.
48    Returns 'NULL' if the file cannot be read or failed to allocate
49    enough memory.
50    Returns an empty string if the file exists but is empty.
51 */
52 char *file_get_content(const char *path);
53
54 enum file_copy_error {
55         FILE_COPY_ERROR_OPEN_SRC = 1,
56         FILE_COPY_ERROR_OPEN_DST,
57         FILE_COPY_ERROR_READ,
58         FILE_COPY_ERROR_WRITE,
59         FILE_COPY_ERROR_ALLOC_BUFFER
60 };
61
62 void file_copy_print_error(int code, const char *src, const char *dst);
63
64 /*
65   Copy a file.
66
67   Returns '0' if sucessfull, otherwise return the error code.
68 */
69 int file_copy(const char *src, const char *dst);
70
71 #endif