s3:printing: Allow to run samba-bgqd as a standalone systemd service
[Samba.git] / lib / util / util_file.h
blob8de75da5ed101153bb4796bab840a68450db9010
1 /*
2 * Unix SMB/CIFS implementation.
3 * SMB parameters and setup
4 * Copyright (C) Andrew Tridgell 1992-1998 Modified by Jeremy Allison 1995.
6 * Added afdgets() Jelmer Vernooij 2005
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.
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.
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/>.
22 #ifndef __LIB_UTIL_UTIL_FILE_H__
23 #define __LIB_UTIL_UTIL_FILE_H__
25 #include "replace.h"
26 #include <talloc.h>
28 /**
29 * Read one line (data until next newline or eof) and allocate it
31 _PUBLIC_ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint);
33 char *fgets_slash(TALLOC_CTX *mem_ctx, char *s2, size_t maxlen, FILE *f);
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);
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);
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);
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);
58 char **file_lines_parse(const char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx);
60 _PUBLIC_ bool file_save_mode(const char *fname, const void *packet,
61 size_t length, mode_t mode);
63 /**
64 save a lump of data into a file. Mostly used for debugging
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);
71 compare two files, return true if the two files have the same content
73 bool file_compare(const char *path1, const char *path2);
76 load from a pipe into memory.
78 char *file_ploadv(char * const argl[], size_t *size);
80 FILE *fdopen_keepfd(int fd, const char *mode);
82 #endif