ctdb-common: Process the whole config file even if an error occurs
[vlendec/samba-autobuild/.git] / ctdb / common / line.h
1 /*
2    Line based I/O over fds
3
4    Copyright (C) Amitay Isaacs  2018
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef __CTDB_LINE_H__
21 #define __CTDB_LINE_H__
22
23 #include <talloc.h>
24
25 /**
26  * @file line.h
27  *
28  * @brief Line based I/O over pipes and sockets
29  */
30
31 /**
32  * @brief The callback routine called to process a line
33  *
34  * @param[in]  line The line read
35  * @param[in]  private_data Private data for callback
36  * @return 0 to continue processing lines, non-zero to stop reading
37  */
38 typedef int (*line_process_fn_t)(char *line, void *private_data);
39
40 /**
41  * @brief Read a line (terminated by \n or \0)
42  *
43  * If there is any read error on fd, then errno will be returned.
44  * If callback function returns a non-zero value, then that value will be
45  * returned.
46  *
47  * @param[in]  fd The file descriptor
48  * @param[in]  length The expected length of a line (this is only a hint)
49  * @param[in]  mem_ctx Talloc memory context
50  * @param[in]  callback Callback function called when a line is read
51  * @param[in]  private_data Private data for callback
52  * @param[out] num_lines Number of lines read so far
53  * @return 0 on on success, errno on failure
54  */
55 int line_read(int fd,
56               size_t length,
57               TALLOC_CTX *mem_ctx,
58               line_process_fn_t callback,
59               void *private_data,
60               int *num_lines);
61
62 #endif /* __CTDB_LINE_H__ */