try an implementation for writePGF_ on macOS

This commit is contained in:
Krasimir Angelov
2023-09-04 17:14:02 +02:00
parent fc23e8b9fe
commit d49ef33054
4 changed files with 76 additions and 8 deletions

View File

@@ -280,7 +280,7 @@ end:
fclose(out);
}
#ifdef _GNU_SOURCE
#if defined(__linux__)
PGF_API
void pgf_write_pgf_cookie
(void *cookie, cookie_io_functions_t *io_funcs,
@@ -308,6 +308,35 @@ void pgf_write_pgf_cookie
if (out != NULL)
fclose(out);
}
#elif defined(__APPLE__)
PGF_API
void pgf_write_pgf_cookie
(void *cookie, int (*writefn)(void *, const char *, int),
int (*closefn)(void *),
PgfDB *db, PgfRevision revision,
PgfText **langs, // null terminated list or null
PgfExn* err)
{
FILE *out = NULL;
PGF_API_BEGIN {
out = funopen(cookie, NULL, writefn, NULL, closefn);
if (!out) {
throw pgf_systemerror(errno, "<cookie>");
}
{
DB_scope scope(db, READER_SCOPE);
ref<PgfPGF> pgf = db->revision2pgf(revision);
PgfWriter wtr(langs, out);
wtr.write_pgf(pgf);
}
} PGF_API_END
if (out != NULL)
fclose(out);
}
#endif
PGF_API

View File

@@ -291,13 +291,21 @@ void pgf_write_pgf(const char* fpath,
PgfText **langs, // null terminated list or null
PgfExn* err);
#ifdef _GNU_SOURCE
#if defined(__linux__)
PGF_API_DECL
void pgf_write_pgf_cookie
(void *cookie, cookie_io_functions_t *io_funcs,
PgfDB *db, PgfRevision revision,
PgfText **langs, // null terminated list or null
PgfExn* err);
#elif defined(__APPLE__)
PGF_API_DECL
void pgf_write_pgf_cookie
(void *cookie, int (*writefn)(void *, const char *, int),
int (*closefn)(void *),
PgfDB *db, PgfRevision revision,
PgfText **langs, // null terminated list or null
PgfExn* err);
#endif
PGF_API_DECL