1
/*
2
 * Copyright 2008-2011 Various Authors
3
 * Copyright 2005 Timo Hirvonen
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License as
7
 * published by the Free Software Foundation; either version 2 of the
8
 * License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful, but
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
#ifndef _FILE_H
20
#define _FILE_H
21
22
#include <stddef.h> /* size_t */
23
#include <sys/types.h> /* ssize_t */
24
25
ssize_t read_all(int fd, void *buf, size_t count);
26
ssize_t write_all(int fd, const void *buf, size_t count);
27
28
/* @filename  file to mmap for reading
29
 * @size      returned size of the file or -1 if failed
30
 *
31
 * returns buffer or NULL if empty file or failed
32
 */
33
char *mmap_file(const char *filename, int *size);
34
35
void buffer_for_each_line(const char *buf, int size,
36
		int (*cb)(void *data, const char *line),
37
		void *data);
38
void buffer_for_each_line_reverse(const char *buf, int size,
39
		int (*cb)(void *data, const char *line),
40
		void *data);
41
int file_for_each_line(const char *filename,
42
		int (*cb)(void *data, const char *line),
43
		void *data);
44
45
#endif