64 bit C getline

getline is a gnu extension.

On moving from 32 bit linux to 64 bit Centos one needs to know that size_t int are no longer the same thing.

ssize_t getline (char **lineptr, size_t *buf_size, FILE *stream)
I.e. buf_size must be a pointer to size_t not a pointer to int.

Compile with

gcc -D_GNU_SOURCE

If _GNU_SOURCE is not used, getline is not included when stdio.h is compiled. Hence the compiler cannot check the arguments passed to getline. However the linker still manages to link the image. Bad things may happen (eg heap corruption) if the arguments used to call getline are not compatible with it.

Even if stdio.h is included with _GNU_SOURCE, the compiler may only issue a warning (warning: passing argument 2 of 'getline' from incompatible pointer type) which is easy to over look.

WBL 25 Aug 2010