version 1.1.1.1, 2012/02/21 16:23:02
|
version 1.1.1.3, 2013/07/22 10:46:11
|
Line 1
|
Line 1
|
/* |
/* |
* Copyright (c) 2009-2010 Todd C. Miller <Todd.Miller@courtesan.com> | * Copyright (c) 2009-2010, 2012-2013 Todd C. Miller <Todd.Miller@courtesan.com> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
Line 16
|
Line 16
|
|
|
#include <config.h> |
#include <config.h> |
|
|
|
#ifndef HAVE_GETLINE |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
|
|
#include <stdio.h> |
#include <stdio.h> |
Line 52 getline(char **bufp, size_t *bufsizep, FILE *fp)
|
Line 54 getline(char **bufp, size_t *bufsizep, FILE *fp)
|
buf = fgetln(fp, &len); |
buf = fgetln(fp, &len); |
if (buf) { |
if (buf) { |
bufsize = *bufp ? *bufsizep : 0; |
bufsize = *bufp ? *bufsizep : 0; |
if (bufsize < len + 1) { | if (bufsize == 0 || bufsize - 1 < len) { |
bufsize = len + 1; |
bufsize = len + 1; |
cp = *bufp ? realloc(*bufp, bufsize) : malloc(bufsize); |
cp = *bufp ? realloc(*bufp, bufsize) : malloc(bufsize); |
if (cp == NULL) |
if (cp == NULL) |
Line 101 getline(char **bufp, size_t *bufsizep, FILE *fp)
|
Line 103 getline(char **bufp, size_t *bufsizep, FILE *fp)
|
*bufsizep = bufsize; |
*bufsizep = bufsize; |
return len; |
return len; |
} |
} |
#endif | #endif /* HAVE_FGETLN */ |
| #endif /* HAVE_GETLINE */ |