xenocara/driver/xf86-video-intel/libobj/getline.c
matthieu d031df2719 Update to xf86-video-intel 2.99.916
Fixes a display bug seenby ajacoutot@, ok jsg@ and kettenis@.
newer X.Org (2.99.917 or master) version cause corruption on older
machines (X40, i965), probably caused by a bug in our kernel,
under investigation by kettenis@.
2015-04-12 19:41:54 +00:00

52 lines
770 B
C

#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;
}