selftest: Add helper scripts for accessing the testenv namespace
[Samba.git] / ctdb / common / line.h
blob6b67f1e92e1b01359ce33a7223649f68948dc7f3
1 /*
2 Line based I/O over fds
4 Copyright (C) Amitay Isaacs 2018
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.
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.
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/>.
20 #ifndef __CTDB_LINE_H__
21 #define __CTDB_LINE_H__
23 #include <talloc.h>
25 /**
26 * @file line.h
28 * @brief Line based I/O over pipes and sockets
31 /**
32 * @brief The callback routine called to process a line
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
38 typedef int (*line_process_fn_t)(char *line, void *private_data);
40 /**
41 * @brief Read a line (terminated by \n or \0)
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.
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
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);
62 #endif /* __CTDB_LINE_H__ */