1 /* cairo - a vector graphics library with display and print output
3 * Copyright © 2006 Red Hat, Inc.
4 * Copyright © 2011 Andrea Canciani
6 * Permission to use, copy, modify, distribute, and sell this software
7 * and its documentation for any purpose is hereby granted without
8 * fee, provided that the above copyright notice appear in all copies
9 * and that both that copyright notice and this permission notice
10 * appear in supporting documentation, and that the name of the
11 * copyright holders not be used in advertising or publicity
12 * pertaining to distribution of the software without specific,
13 * written prior permission. The copyright holders make no
14 * representations about the suitability of this software for any
15 * purpose. It is provided "as is" without express or implied
18 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
19 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
23 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
24 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
27 * Authors: Carl Worth <cworth@cworth.org>
28 * Andrea Canciani <ranma42@gmail.com>
31 #include "cairo-missing.h"
34 #include "cairo-malloc-private.h"
36 #define GETLINE_MIN_BUFFER_SIZE 128
38 getline (char **lineptr,
49 if (len < GETLINE_MIN_BUFFER_SIZE) {
50 len = GETLINE_MIN_BUFFER_SIZE;
55 line = (char *) _cairo_malloc (len);
56 if (unlikely (line == NULL))
61 if (offset + 1 == len) {
62 tmpline = (char *) _cairo_realloc_ab (line, len, 2);
63 if (unlikely (tmpline == NULL)) {
83 line[offset++] = '\0';
89 #undef GETLINE_BUFFER_SIZE