pkgsrc-wip/stardict-tools/files/getline.c
Aleksey Cheusov b61ea58140 Import stardict-tools-3.0.1 as wip/stardict-tools.
StarDict is a Cross-Platform and international dictionary written in
Gtk2. It has powerful features such as "Glob-style pattern matching",
"Scan seletion word", "Fuzzy search", "Net dict", "Full text
translation" etc.

stardict-tools package provides dictionary conversion tools.
2009-09-13 18:25:06 +00:00

28 lines
447 B
C

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
ssize_t getline (char **lineptr, size_t *n, FILE *stream)
{
size_t len;
char *str;
if (!n || !lineptr)
return EINVAL;
str = fgetln (stream, &len);
if (!str)
return (size_t) -1;
*n = len;
*lineptr = realloc (*lineptr, len+1);
if (! *lineptr)
return (size_t) -1;
memcpy (*lineptr, str, len);
(*lineptr) [len] = 0;
return len;
}