getline() is POSIX.1-2008, but is unavailable on several platforms,
including MinGW and Solaris 10.
git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@1172
64e312b2-a51f-0410-8e61-
82d0ca0eb02a
HW_LIBRT_TIMERS
# The following checks will replace missing functions from libcompat
-AC_REPLACE_FUNCS([alarm clock_gettime gettimeofday localtime_r strdup strsignal])
-AC_CHECK_DECLS([alarm, clock_gettime, gettimeofday, localtime_r, strdup, strsignal])
+AC_REPLACE_FUNCS([alarm clock_gettime getline gettimeofday localtime_r strdup strsignal])
+AC_CHECK_DECLS([alarm, clock_gettime, getline gettimeofday, localtime_r, strdup, strsignal])
# The following checks are to only detect if the functions exist, but
# not replace them
--- /dev/null
+#include "libcompat.h"
+#include <stdio.h>
+
+#define INITIAL_SIZE 16
+#define DELIMITER '\n'
+
+ssize_t getline(char **lineptr, size_t *n, FILE *stream)
+{
+ ssize_t written = 0;
+ int character;
+
+ if(*lineptr == NULL || *n < INITIAL_SIZE)
+ {
+ free(*lineptr);
+ *lineptr = (char *)malloc(INITIAL_SIZE);
+ *n = INITIAL_SIZE;
+ }
+
+ while( (character = fgetc(stream)) != EOF)
+ {
+ written += 1;
+ if(written >= *n)
+ {
+ *n = *n * 2;
+ *lineptr = realloc(*lineptr, *n);
+ }
+
+ (*lineptr)[written-1] = character;
+
+ if(character == DELIMITER)
+ {
+ break;
+ }
+ }
+
+ (*lineptr)[written] = '\0';
+
+ return written;
+}
#endif
#endif /* HAVE_STDARG_H */
+#if !HAVE_GETLINE
+CK_DLL_EXP ssize_t getline(char **lineptr, size_t *n, FILE *stream);
+#endif
+
/* silence warnings about an empty library */
CK_DLL_EXP void ck_do_nothing(void) CK_ATTRIBUTE_NORETURN;