2 * Copyright (C) 2004-2008 Kay Sievers <kay.sievers@vrfy.org>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 int file_map(const char *filename, char **buf, size_t *bufsize)
37 fd = open(filename, O_RDONLY);
42 if (fstat(fd, &stats) < 0) {
47 *buf = mmap(NULL, stats.st_size, PROT_READ, MAP_SHARED, fd, 0);
48 if (*buf == MAP_FAILED) {
52 *bufsize = stats.st_size;
59 void file_unmap(void *buf, size_t bufsize)
64 /* return number of chars until the next newline, skip escaped newline */
65 size_t buf_get_line(const char *buf, size_t buflen, size_t cur)
70 for (count = cur; count < buflen; count++) {
71 if (!escape && buf[count] == '\n')
74 if (buf[count] == '\\')