Skip to content

Fixes to build v2.3.0 on Windows with MinGW-w64 #611

@brechtsanders

Description

@brechtsanders

I just built libgd 2.3.0 on Windows using MinGW-w64 (using MSYS2 shell).
To do this 2 fixes were needed to address these issues:

  • missing posix_memalign()
  • missing getline()

Using these fixes I was able to build the library:

patch -ulbf src/gd_topal.c << EOF
@@ -1529,4 +1529,8 @@
 {
+#ifdef _WIN32
+       return _aligned_malloc(size, 16);
+#else
        void *p;
        return posix_memalign(&p, 16, size) == 0 ? p : NULL;
+#endif
 }
EOF
mv src/annotate.c src/annotate.c.bak
cat > src/annotate.c << EOF
#ifdef _WIN32
#include <stdio.h>
#include <stdlib.h>
#define GETLINE_BUFLEN 128
size_t getline(char** lineptr, size_t* n, FILE* stream)
{
  char* bufptr;
  char* p;
  size_t size;
  int c;
  if (!lineptr || !n || !stream)
    return -1;
  bufptr = *lineptr;
  size = *n;
  c = fgetc(stream);
  if (c == EOF)
    return -1;
  if (!bufptr) {
    if ((bufptr = (char*)malloc(GETLINE_BUFLEN)) == NULL)
      return -1;
    size = GETLINE_BUFLEN;
  }
  p = bufptr;
  while (c != EOF) {
    if ((p - bufptr) > (size - 1)) {
      size = size + GETLINE_BUFLEN;
      if ((bufptr = (char*)realloc(bufptr, size)) == NULL)
        return -1;
    }
    *p++ = c;
    if (c == '\n') {
      break;
    }
    c = fgetc(stream);
  }
  *p++ = 0;
  *lineptr = bufptr;
  *n = size;
  return p - bufptr - 1;
}
#endif
EOF
cat src/annotate.c.bak >> src/annotate.c

Probably there is a better solution for the missing getline() issue.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions