Code

Merge remote-tracking branch 'github/pr/387'
[collectd.git] / src / utils_tail.h
1 /**
2  * collectd - src/utils_tail.h
3  * Copyright (C) 2007-2008  C-Ware, Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  *
18  * Author:
19  *   Luke Heberling <lukeh at c-ware.com>
20  *
21  * DESCRIPTION
22  *   Facilitates reading information that is appended to a file, taking into
23  *   account that the file may be rotated and a new file created under the
24  *   same name.
25  **/
27 #ifndef UTILS_TAIL_H
28 #define UTILS_TAIL_H 1
30 struct cu_tail_s;
31 typedef struct cu_tail_s cu_tail_t;
33 typedef int tailfunc_t(void *data, char *buf, int buflen);
35 /*
36  * NAME
37  *   cu_tail_create
38  *
39  * DESCRIPTION
40  *   Allocates a new tail object..
41  *
42  * PARAMETERS
43  *   `file'       The name of the file to be tailed.
44  */
45 cu_tail_t *cu_tail_create (const char *file);
47 /*
48  * cu_tail_destroy
49  *
50  * Takes a tail object returned by `cu_tail_create' and destroys it, freeing
51  * all internal memory.
52  *
53  * Returns 0 when successful and non-zero otherwise.
54  */
55 int cu_tail_destroy (cu_tail_t *obj);
57 /*
58  * cu_tail_readline
59  *
60  * Reads from the file until `buflen' characters are read, a newline
61  * character is read, or an eof condition is encountered. `buf' is
62  * always null-terminated on successful return and isn't touched when non-zero
63  * is returned.
64  *
65  * You can check if the EOF condition is reached by looking at the buffer: If
66  * the length of the string stored in the buffer is zero, EOF occurred.
67  * Otherwise at least the newline character will be in the buffer.
68  *
69  * Returns 0 when successful and non-zero otherwise.
70  */
71 int cu_tail_readline (cu_tail_t *obj, char *buf, int buflen);
73 /*
74  * cu_tail_readline
75  *
76  * Reads from the file until eof condition or an error is encountered.
77  *
78  * Returns 0 when successful and non-zero otherwise.
79  */
80 int cu_tail_read (cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback,
81                 void *data);
83 #endif /* UTILS_TAIL_H */