Add compile and link-time deprecation warnings for fgetln() Although the current implementation in libbsd is probably one of the safest ones around, it still poses some problems when used with many file streams. This function has now a replacement, that is both more standard and portable. Ask users to switch to getline(3) instead.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
diff --git a/include/bsd/stdio.h b/include/bsd/stdio.h
index e1f8fc3..7697425 100644
--- a/include/bsd/stdio.h
+++ b/include/bsd/stdio.h
@@ -44,7 +44,12 @@
__BEGIN_DECLS
const char *fmtcheck(const char *, const char *);
-char *fgetln(FILE *fp, size_t *lenp);
+/* XXX: The function requires cooperation from the system libc to store the
+ * line buffer in the FILE struct itself. */
+char *fgetln(FILE *fp, size_t *lenp)
+ __attribute__((deprecated("This functions cannot be safely ported, "
+ "use getline(3) instead, as it is supported "
+ "by GNU and POSIX.1-2008.")));
/*
* Note: We diverge from the FreeBSD, OpenBSD and DragonFlyBSD declarations,
diff --git a/src/fgetln.c b/src/fgetln.c
index 6de804b..5f646e4 100644
--- a/src/fgetln.c
+++ b/src/fgetln.c
@@ -30,6 +30,8 @@
#include <sys/types.h>
#include <string.h>
+#include "local-link.h"
+
#ifdef HAVE_GETLINE
struct filebuf {
FILE *fp;
@@ -68,6 +70,9 @@ fgetln(FILE *stream, size_t *len)
return fb->buf;
}
}
+libbsd_link_warning(fgetln,
+ "This functions cannot be safely ported, use getline(3) "
+ "instead, as it is supported by GNU and POSIX.1-2008.")
#else
#error "Function fgetln() needs to be ported."
#endif
diff --git a/test/Makefile.am b/test/Makefile.am
index 9086128..6d675e3 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -27,6 +27,7 @@ check_PROGRAMS += proctitle
endif
fgetln_SOURCES = test-stream.c test-stream.h fgetln.c
+fgetln_CFLAGS = -Wno-deprecated-declarations
fparseln_SOURCES = test-stream.c test-stream.h fparseln.c
proctitle_init_SOURCES = proctitle.c