Skip to content

Commit 5aadd9e

Browse files
committed
Fix linux build by working around some gcc issues.
1 parent ca500f1 commit 5aadd9e

File tree

5 files changed

+335
-187
lines changed

5 files changed

+335
-187
lines changed

Embedded/np_embed.c

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,11 @@ NP_DECL(EFILE*) np_fopen(const char* file, const char* mode) {
184184
return e;
185185
}
186186

187-
NP_DECL(int) np_open(const char *file, int flags, va_list args) {
188187
#ifdef _WIN32
189-
int mode = 0;
188+
NP_DECL(int) np_open(const char *file, int flags, int mode)) {
190189
#else
191-
mode_t mode = 0;
190+
NP_DECL(int) np_open(const char *file, int flags, mode_t mode) {
192191
#endif
193-
if (flags & O_CREAT) {
194-
mode = va_arg(args, int);
195-
}
196-
197192
char absolute_path[PATH_MAX] = {};
198193
np_get_absolute_path(file, absolute_path, PATH_MAX);
199194
char execfolder[PATH_MAX] = {}, executable[PATH_MAX];
@@ -259,12 +254,7 @@ NP_DECL(EFILE*) np_wfopen(const wchar_t *wfile, const wchar_t *mode) {
259254
return e;
260255
}
261256

262-
NP_DECL(int) np_wopen(const wchar_t *wfile, int flags, va_list args) {
263-
int mode = 0;
264-
if (flags & O_CREAT) {
265-
mode = va_arg(args, int);
266-
}
267-
257+
NP_DECL(int) np_wopen(const wchar_t *wfile, int flags, int mode) {
268258
char file[PATH_MAX] = {};
269259
wcstombs((char*)&file, wfile, PATH_MAX);
270260

@@ -336,6 +326,18 @@ NP_DECL(int) np_close(int fd) {
336326
return 0;
337327
}
338328

329+
NP_DECL(EFILE*) np_tmpfile() {
330+
FILE* f = tmpfile();
331+
if (f == NULL)
332+
return NULL;
333+
334+
EFILE* e = (EFILE*)malloc(sizeof *e);
335+
e->handle_type = EHANDLE_NATIVE;
336+
e->f = f;
337+
338+
return e;
339+
}
340+
339341
NP_DECL(bool) np_feof(void* e) {
340342
if (NP_FOREIGN_PTR) {
341343
return feof((FILE*)e);
@@ -434,7 +436,7 @@ NP_DECL(ssize_t) np_pread(int fd, void *buf, size_t count, off_t offset) {
434436
return count;
435437
}
436438

437-
NP_DECL(int) np_fgetpos(void* e, epos_t* pos) {
439+
NP_DECL(int) np_fgetpos(void* e, fpos_t* pos) {
438440
if (NP_FOREIGN_PTR) {
439441
return fgetpos((FILE*)e, pos);
440442
}
@@ -448,7 +450,14 @@ NP_DECL(int) np_fgetpos(void* e, epos_t* pos) {
448450
return 1;
449451
}
450452

451-
*pos = (epos_t)(((EFILE*)e)->end - ((EFILE*)e)->pos);
453+
#ifdef __linux__
454+
fpos_t temp = {};
455+
temp.__pos = ((EFILE*)e)->end - ((EFILE*)e)->pos;
456+
memcpy(pos, &temp, sizeof(fpos_t));
457+
#else
458+
*pos = (fpos_t)(((EFILE*)e)->end - ((EFILE*)e)->pos);
459+
#endif
460+
452461
return 0;
453462

454463
}
@@ -575,12 +584,20 @@ NP_DECL(int) np_fseeko64(void *e, int64_t offset, int origin) {
575584
return np_fseek_priv(e, offset, origin);
576585
}
577586

578-
NP_DECL(int) np_fscanf(void *e, const char *format, va_list args) {
587+
NP_DECL(int) np_fscanf(void *e, const char *format, ...) {
579588
if (NP_FOREIGN_PTR) {
580-
return vfscanf(((FILE*)e), format, args);
589+
va_list args;
590+
va_start(args, format);
591+
int result = vfscanf(((FILE*)e), format, args);
592+
va_end(args);
593+
return result;
581594
}
582595
if (((EFILE*)e)->handle_type != EHANDLE_VIRTUAL) {
583-
return vfscanf(((EFILE*)e)->f, format, args);
596+
va_list args;
597+
va_start(args, format);
598+
int result = vfscanf(((EFILE*)e)->f, format, args);
599+
va_end(args);
600+
return result;
584601
}
585602
return 0;
586603
}
@@ -622,6 +639,15 @@ NP_DECL(int) np_fprintf(void *e, const char *format, ...) {
622639
}
623640
return 0;
624641
}
642+
NP_DECL(int) np_vfprintf(void *e, const char *format, va_list args) {
643+
if (NP_FOREIGN_PTR) {
644+
return vfprintf((FILE*)e, format, args);
645+
}
646+
if (((EFILE*)e)->handle_type != EHANDLE_VIRTUAL) {
647+
return vfprintf(((EFILE*)e)->f, format, args);
648+
}
649+
return 0;
650+
}
625651

626652
NP_DECL(size_t) np_fwrite(const void *ptr, size_t size, size_t count, void *e) {
627653
if (NP_FOREIGN_PTR) {

0 commit comments

Comments
 (0)