The idea for this came from another thread in the C++ forum that wanted to duplicate the _getdelim() function that is supported by GNU compilers g++. I made one major change in that this version does not allocate new memory every time it is called, which is grossly inefficient. Instead, this function only allocates new memory if the pointer to pointer passed to _getdelim() is NULL. If not NULL then it assumes the calling program has allocated the memory. The function might expand the size of the line buffer if the number of characters read exceeds the length of the line buffer.
I also removed the goto statements that are in the original GNU function and the ancient K&R style function parameter declarations.
This code snippet uses only standard C functions -- nothing compiler-specific, so it most likely will compile with any 32-bit or 64-bit compiler.