Skip to content

guard unix-y implementation details #29

@AODQ

Description

@AODQ

I've been having compile issues for this on several of my machines, I'm not very confident of this fix other than for my own use, but thought I'd post it here in case either I'm doing something entirely wrong, or this is actually something that belongs in the code.

for reference, the errors:

libschrift/schrift.c:417:1: error: static declaration ofreallocarrayfollows non-static declaration
  417 | reallocarray(void *optr, size_t nmemb, size_t size)
libschrift/schrift.c:32: warning: "_POSIX_C_SOURCE" redefined
   32 | # define _POSIX_C_SOURCE 1
      |
In file included from /usr/include/assert.h:35,
                 from /(blah-blah-blah)/libschrift/schrift.c:17:
/usr/include/features.h:292: note: this is the location of the previous definition
  292 | # define _POSIX_C_SOURCE        200809L

Either way here's the diff I use to fix.

diff --git a/schrift.c b/schrift.c
index eb39376..1109022 100644
--- a/schrift.c
+++ b/schrift.c
@@ -29,7 +29,9 @@
 # define WIN32_LEAN_AND_MEAN 1
 # include <windows.h>
 #else
+#ifndef _POSIX_C_SOURCE
 # define _POSIX_C_SOURCE 1
+#endif
 # include <fcntl.h>
 # include <sys/mman.h>
 # include <sys/stat.h>
@@ -125,7 +127,9 @@ struct SFT_Font

 /* function declarations */
 /* generic utility functions */
+#ifndef __USE_MISC
 static void *reallocarray(void *optr, size_t nmemb, size_t size);
+#endif
 static inline int fast_floor(double x);
 static inline int fast_ceil (double x);
 /* file loading */
@@ -406,6 +410,7 @@ failure:
  * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW */
 #define MUL_NO_OVERFLOW        ((size_t)1 << (sizeof(size_t) * 4))

+#ifndef __USE_MISC
 /* OpenBSD's reallocarray() standard libary function.
  * A wrapper for realloc() that takes two size args like calloc().
  * Useful because it eliminates common integer overflow bugs. */
@@ -419,6 +424,7 @@ reallocarray(void *optr, size_t nmemb, size_t size)
        }
        return realloc(optr, size * nmemb);
 }
+#endif

 /* TODO maybe we should use long here instead of int. */
 static inline int

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions