git » libfilo » commit 094ed5f

Force the library to be compiled with LFS support.

author Alberto Bertogli
2005-04-27 21:10:46 UTC
committer Alberto Bertogli
2005-04-27 21:10:46 UTC
parent ca69908268e1a66e8d8f229734271f0cf082fcd2

Force the library to be compiled with LFS support.
There is a big problem with libraries and LFS support, which happens if you
compile the library with LFS support and the application without, or the
opposite. In that case the library ABI differs and horrible bugs will happen.

This patch prevents it by compiling the library with LFS support always
enabled, and put a check in the header to prevent applications using it
incorrectly (without LFS). It also updates the manpage to reflect this.

Makefile +4 -1
doc/libfilo.3 +5 -0
libfilo.h +17 -0

diff --git a/Makefile b/Makefile
index 7588e2c..fab1b0e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,9 @@
 
 
-CFLAGS += -Wall -D_XOPEN_SOURCE=500 -O3
+CFLAGS += -Wall -D_XOPEN_SOURCE=500 -O3 \
+	-D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 \
+	-D_LFS_LARGEFILE=1 -D_LFS64_LARGEFILE=1 \
+	-D_FILE_OFFSET_BITS=64 `getconf LFS_CFLAGS 2>/dev/null`
 
 ifdef DEBUG
 	CFLAGS += -g -pg -fprofile-arcs -ftest-coverage
diff --git a/doc/libfilo.3 b/doc/libfilo.3
index b6bfadd..22efd33 100644
--- a/doc/libfilo.3
+++ b/doc/libfilo.3
@@ -130,6 +130,11 @@ instead has the oposite return values: it will return 0 if success, or -1 on
 failure. This behaviour is set to match
 .BR lockf (3).
 
+.SH NOTES
+The library is normally installed with Large File Support, so you should not
+link against applications that are not using it (and in fact there's a check
+in the header to avoid this), since it can cause horrible bugs.
+
 .SH AUTHORS
 .B libfilo
 was written by Alberto Bertogli (albertogli@telpin.com.ar). It has a website,
diff --git a/libfilo.h b/libfilo.h
index 62a5717..fd8620b 100644
--- a/libfilo.h
+++ b/libfilo.h
@@ -13,6 +13,19 @@
 #include <unistd.h>	/* because filo_plockf() uses the same constants as
 			 * lockf() */
 
+/* Check if we're using Large File Support - otherwise refuse to build.
+ * Otherwise, we would allow applications not using LFS to link with the
+ * library (which uses LFS) and that's just begging for problems. There should
+ * be a portable way for the C library to do some of this for us, but until I
+ * find one, this is the best we can do */
+#if (!defined _FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS != 64)
+#error "You must compile your application with Large File Support"
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 
 /* locking modes */
 #define FL_RD_MODE 0
@@ -68,5 +81,9 @@ int filo_trylock(filock_t *fl, off_t start, off_t len, int mode);
 int filo_unlock(filock_t *fl, off_t start, off_t len);
 int filo_plockf(filock_t *fl, int cmd, off_t start, off_t len);
 
+#ifdef __cplusplus
+} /* from extern "C" avobe */
+#endif
+
 #endif