diff options
Diffstat (limited to 'examples/hello_strlcpy/hello.c')
-rw-r--r-- | examples/hello_strlcpy/hello.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/examples/hello_strlcpy/hello.c b/examples/hello_strlcpy/hello.c index b7dd661..177b6b5 100644 --- a/examples/hello_strlcpy/hello.c +++ b/examples/hello_strlcpy/hello.c @@ -5,14 +5,18 @@ size_t strlcpy(char *dst, const char *src, size_t siz); #endif +#ifndef HAVE_FUNC3_GETLINE_STDIO_H +ssize_t getline(char** lineptr, size_t* n, FILE* stream); +#endif + int main (int argc, char ** argv) { - char buf [2000]; + char *buf = NULL; + size_t size = 0; + ssize_t len = 0; char small_buf [10]; - size_t len; - - while (fgets (buf, sizeof (buf), stdin)){ + while (len = getline (&buf, &size, stdin), len != -1){ len = strlen (buf); if (len > 0 && buf [len-1] == '\n') buf [len-1] = 0; |