let me know if you found any issue via bruceadi(at)hotmail.com, thanks

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* getline(char** pbuf, size_t* buflen, FILE* stream)
{
if(*buflen <= 1) return NULL;
if(!fgets(*pbuf, *buflen, stream)) return NULL;
size_t len;
while(len = strlen(*pbuf), !feof(stream) && (*pbuf)[len - 1] != '\n')
{
char* pOld = *pbuf;
*pbuf = (char*)realloc(*pbuf, *buflen << 1);
if(NULL == *pbuf)
{
free(pOld);
*buflen = 0;
return *pbuf;
}
fgets(*pbuf + len , *buflen + 1, stream);
*buflen <<= 1;
}
if((*pbuf)[len - 1] == '\n')
{
(*pbuf)[len - 1 ]= 0;
return *pbuf;
}
return *pbuf;
}
int main()
{
size_t len = 32;
char* line = (char*)malloc(len);
while(getline(&line, &len, stdin))
{
puts(line);
}
free(line);
return 0;
}