configure: Provide a poor man's replacement for getline()
uClibc is one such library that doesn't implement getline() Reported-by: Ben Widawsky <benjamin.widawsky@intel.com> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
parent
8587b2fff2
commit
251bcc32ee
|
|
@ -818,6 +818,9 @@ if test "x$debug_msg" = "x"; then
|
||||||
debug_msg=" none"
|
debug_msg=" none"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
AC_CONFIG_LIBOBJ_DIR(libobj)
|
||||||
|
AC_REPLACE_FUNCS(getline)
|
||||||
|
|
||||||
DRIVER_NAME="intel"
|
DRIVER_NAME="intel"
|
||||||
AC_SUBST([DRIVER_NAME])
|
AC_SUBST([DRIVER_NAME])
|
||||||
AC_SUBST([moduledir])
|
AC_SUBST([moduledir])
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
extern int getline(char **line, size_t *len, FILE *file);
|
||||||
|
|
||||||
|
int getline(char **line, size_t *len, FILE *file)
|
||||||
|
{
|
||||||
|
char *ptr, *end;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
if (*line == NULL) {
|
||||||
|
errno = EINVAL;
|
||||||
|
if (*len == 0)
|
||||||
|
*line = malloc(4096);
|
||||||
|
if (*line == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
*len = 4096;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr = *line;
|
||||||
|
end = *line + *len;
|
||||||
|
|
||||||
|
while ((c = fgetc(file)) != EOF) {
|
||||||
|
if (ptr + 1 >= end) {
|
||||||
|
char *newline;
|
||||||
|
int offset;
|
||||||
|
|
||||||
|
newline = realloc(*line, *len + 4096);
|
||||||
|
if (newline == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
offset = ptr - *line;
|
||||||
|
|
||||||
|
*line = newline;
|
||||||
|
*len += 4096;
|
||||||
|
|
||||||
|
ptr = *line + offset;
|
||||||
|
end = *line + *len;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ptr++ = c;
|
||||||
|
if (c == '\n') {
|
||||||
|
*ptr = '\0';
|
||||||
|
return ptr - *line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*ptr = '\0';
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
@ -1222,4 +1222,9 @@ static inline void sigtrap_put(void)
|
||||||
#define RR_Rotate_All (RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_180 | RR_Rotate_270)
|
#define RR_Rotate_All (RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_180 | RR_Rotate_270)
|
||||||
#define RR_Reflect_All (RR_Reflect_X | RR_Reflect_Y)
|
#define RR_Reflect_All (RR_Reflect_X | RR_Reflect_Y)
|
||||||
|
|
||||||
|
#ifndef HAVE_GETLINE
|
||||||
|
#include <stdio.h>
|
||||||
|
extern int getline(char **line, size_t *len, FILE *file);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _SNA_H */
|
#endif /* _SNA_H */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue