lib: Give lib/util/util_file.c its own header file
[jra/samba-autobuild/.git] / lib / util / util_file.h
1 /*
2  * Unix SMB/CIFS implementation.
3  * SMB parameters and setup
4  * Copyright (C) Andrew Tridgell 1992-1998 Modified by Jeremy Allison 1995.
5  *
6  * Added afdgets() Jelmer Vernooij 2005
7  *
8  * This program is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License as published by the Free
10  * Software Foundation; either version 3 of the License, or (at your option)
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
16  * more details.
17  *
18  * You should have received a copy of the GNU General Public License along with
19  * this program; if not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #ifndef __LIB_UTIL_UTIL_FILE_H__
23 #define __LIB_UTIL_UTIL_FILE_H__
24
25 #include "replace.h"
26 #include <talloc.h>
27
28 /**
29  * Read one line (data until next newline or eof) and allocate it
30  */
31 _PUBLIC_ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint);
32
33 char *fgets_slash(TALLOC_CTX *mem_ctx, char *s2, size_t maxlen, FILE *f);
34
35 /**
36 load a file into memory from a fd.
37 **/
38 _PUBLIC_ char *fd_load(int fd, size_t *size, size_t maxsize, TALLOC_CTX *mem_ctx);
39
40 /**
41 load a file into memory
42 **/
43 _PUBLIC_ char *file_load(const char *fname, size_t *size, size_t maxsize, TALLOC_CTX *mem_ctx);
44
45 /**
46 load a file into memory and return an array of pointers to lines in the file
47 must be freed with talloc_free().
48 **/
49 _PUBLIC_ char **file_lines_load(const char *fname, int *numlines, size_t maxsize, TALLOC_CTX *mem_ctx);
50
51 /**
52 load a fd into memory and return an array of pointers to lines in the file
53 must be freed with talloc_free(). If convert is true calls unix_to_dos on
54 the list.
55 **/
56 _PUBLIC_ char **fd_lines_load(int fd, int *numlines, size_t maxsize, TALLOC_CTX *mem_ctx);
57
58 char **file_lines_parse(const char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx);
59
60 _PUBLIC_ bool file_save_mode(const char *fname, const void *packet,
61                              size_t length, mode_t mode);
62
63 /**
64   save a lump of data into a file. Mostly used for debugging
65 */
66 _PUBLIC_ bool file_save(const char *fname, const void *packet, size_t length);
67 _PUBLIC_ int vfdprintf(int fd, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
68 _PUBLIC_ int fdprintf(int fd, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
69
70 /*
71   compare two files, return true if the two files have the same content
72  */
73 bool file_compare(const char *path1, const char *path2);
74
75 /*
76   load from a pipe into memory.
77  */
78 char *file_ploadv(char * const argl[], size_t *size);
79
80 #endif