Skip to content
Permalink
Browse files

leptonica: fix for fstatat issue on 10.9 or lower

  • Loading branch information
stromnov committed Mar 18, 2018
1 parent 1a66163 commit 12d66c539cba67fa03c9559fb86798c7634b7d29
@@ -20,6 +20,13 @@ master_sites http://www.leptonica.com/source/
checksums rmd160 006ced964c7d9125c5b728bf8b717849c7dda21a \
sha256 a00f8fb06829ca6c8262bec8f78a6f985e049786f7c872a37b72fd7051ea087a

# fstatat series:
# - https://github.com/DanBloomberg/leptonica/issues/327
# - https://github.com/DanBloomberg/leptonica/pull/328
# - https://trac.macports.org/ticket/56083
patchfiles patch-conf-fstatat.diff \
patch-fallback-fstatat-stat.diff

depends_build port:pkgconfig

depends_lib port:tiff \
@@ -30,6 +37,8 @@ depends_lib port:tiff \
port:giflib \
port:webp

use_autoreconf yes

configure.args --disable-silent-rules

# ${prefix}/bin/fileinfo
@@ -0,0 +1,134 @@
--- README.html.old 2018-02-15 18:46:13.000000000 +0100
+++ README.html 2018-03-18 01:21:37.000000000 +0100
@@ -499,7 +499,18 @@ that you are using the static makefiles
If you're building with the autoconf programs, these two functions are
automatically enabled if available.

-3. Typedefs
+3. Runtime functions not available on all platforms
+
+ Some functions are not available on all systems. One example of such a
+ function is fstatat(). If possible, such functions will be replaced by
+ wrappers, stubs or behavioral equivalent functions. By default, such
+ functions are disabled; enable them by setting #define HAVE_FUNC 1 (in
+ environ.h).
+
+ If you're building with the autoconf or cmake programs, these functions are
+ automatically enabled if available.
+
+4. Typedefs

A deficiency of C is that no standard has been universally
adopted for typedefs of the built-in types. As a result,
@@ -542,7 +553,7 @@ that you are using the static makefiles
necessary we use the typedefs in stdint.h to specify the pointer
size (either 4 or 8 byte).

-4. Compile-time control over stderr output (see environ.h)
+5. Compile-time control over stderr output (see environ.h)

Leptonica provides both compile-time and run-time control over
messages and debug output (thanks to Dave Bryan). Both compile-time
@@ -553,7 +564,7 @@ that you are using the static makefiles
NO_CONSOLE_IO is defined on the compile line. For production code
where no output is to go to stderr, compile with -DNO_CONSOLE_IO.

-5. In-memory raster format (Pix)
+6. In-memory raster format (Pix)

Unlike many other open source packages, Leptonica uses packed
data for images with all bit/pixel (bpp) depths, allowing us
@@ -574,7 +585,7 @@ that you are using the static makefiles
and a DPix is provided for 2D arrays of doubles. Converters
between these and the Pix are given.

-6. Conversion between Pix and other in-memory raster formats
+7. Conversion between Pix and other in-memory raster formats

. If you use Leptonica with other imaging libraries, you will need
functions to convert between the Pix and other image data
@@ -583,7 +594,7 @@ that you are using the static makefiles
ordering and byte ordering on raster lines. See the file pix.h
for the specification of image data in the pix.

-7. Custom memory management
+8. Custom memory management

Leptonica allows you to use custom memory management (allocator,
deallocator). For Pix, which tend to be large, the alloc/dealloc
Only in leptonica-1.75.3: README.html.orig
--- cmake/Configure.cmake.old 2017-11-03 19:35:52.000000000 +0100
+++ cmake/Configure.cmake 2018-03-18 01:21:37.000000000 +0100
@@ -73,6 +73,7 @@ check_includes(include_files_list)

set(functions_list
fmemopen
+ fstatat
)
check_functions(functions_list)

--- configure.ac.old 2018-02-13 00:08:33.000000000 +0100
+++ configure.ac 2018-03-18 01:21:37.000000000 +0100
@@ -223,6 +223,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM()],

# Checks for library functions.
AC_CHECK_FUNCS([fmemopen])
+AC_CHECK_FUNC([fstatat])

AC_CONFIG_FILES([Makefile src/endianness.h src/Makefile prog/Makefile lept.pc])
AC_OUTPUT
--- cppan.yml.old 2017-03-10 20:57:34.000000000 +0100
+++ cppan.yml 2018-03-18 01:21:37.000000000 +0100
@@ -6,7 +6,9 @@ files:
include_directories:
public: src

-check_function_exists: fmemopen
+check_function_exists:
+ - fmemopen
+ - fstatat

check_include_exists:
- dlfcn.h
--- src/environ.h.old 2018-01-16 00:30:21.000000000 +0100
+++ src/environ.h 2018-03-18 01:21:37.000000000 +0100
@@ -127,6 +127,15 @@ typedef uintptr_t l_uintptr_t;
#define HAVE_FMEMOPEN 1
#endif /* ! HAVE_CONFIG_H etc. */

+/*
+ * fstatat() is defined by POSIX, but some systems do not support it.
+ * One example is older macOS systems (pre-10.10).
+ * Play it safe and set the default value to 0.
+ */
+#if !defined(HAVE_CONFIG_H)
+#define HAVE_FSTATAT 0
+#endif /* ! HAVE_CONFIG_H */
+

/*--------------------------------------------------------------------*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
--- src/makefile.static.old 2018-02-13 02:40:04.000000000 +0100
+++ src/makefile.static 2018-03-18 01:21:37.000000000 +0100
@@ -49,6 +49,11 @@
# The default is not to use, because they only work on linux.
# To use these, #define HAVE_FMEMOPEN to 1 in environ.h.
#
+# Customization for POSIX-compliant function fstatat().
+# The default is not to use, because some systems do not
+# support it.
+# To use this, #define HAVE_FSTATAT to 1 in environ.h.
+#
# Customization for Cygwin:
# (1) Use the appropriate $CC
#
--- sw.cpp.old 2017-11-20 18:50:09.000000000 +0100
+++ sw.cpp 2018-03-18 01:21:37.000000000 +0100
@@ -56,6 +56,7 @@ void check(Checker &c)
{
auto &s = c.addSet("leptonica");
s.checkFunctionExists("fmemopen");
+ s.checkFunctionExists("fstatat");
s.checkIncludeExists("dlfcn.h");
s.checkIncludeExists("inttypes.h");
s.checkIncludeExists("memory.h");
@@ -0,0 +1,27 @@
--- src/sarray1.c.old 2018-01-31 16:57:06.000000000 +0100
+++ src/sarray1.c 2018-03-18 01:22:45.000000000 +0100
@@ -1855,7 +1855,7 @@ l_int32 len;
SARRAY *safiles;
DIR *pdir;
struct dirent *pdirentry;
-int dfd;
+int dfd, stat_ret;
struct stat st;

PROCNAME("getFilenamesInDirectory");
@@ -1871,9 +1871,14 @@ struct stat st;
safiles = sarrayCreate(0);
dfd = dirfd(pdir);
while ((pdirentry = readdir(pdir))) {
+#if HAVE_FSTATAT
+ stat_ret = fstatat(dfd, pdirentry->d_name, &st, 0);
+#else
+ stat_ret = stat(pdirentry->d_name, &st);
+#endif

/* It's nice to ignore directories. */
- if ((0 == fstatat(dfd, pdirentry->d_name, &st, 0))
+ if ((0 == stat_ret)
&& S_ISDIR(st.st_mode)) {
continue;
}

0 comments on commit 12d66c5

Please sign in to comment.
You can’t perform that action at this time.