Skip to content

Commit 47a7c25

Browse files
committed
Don't use wopen macro.
1 parent 80b26a4 commit 47a7c25

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

Embedded/np_embed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ NP_DECL(EFILE*) np_fopen(const char* file, const char* mode) {
185185
}
186186

187187
#ifdef _WIN32
188-
NP_DECL(int) np_open(const char *file, int flags, int mode)) {
188+
NP_DECL(int) np_open(const char *file, int flags, int mode) {
189189
#else
190190
NP_DECL(int) np_open(const char *file, int flags, mode_t mode) {
191191
#endif

Include/np_embed.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,11 @@ ALWAYS_INLINE NP_DECL(int) _open(const char *pathname, int flags, mode_t mode) {
473473
ALWAYS_INLINE NP_DECL(int) open(const char *pathname, int flags, ... /* mode_t mode */ ) {
474474
va_list args;
475475
va_start(args, flags);
476+
#ifdef _WIN32
477+
int mode = 0;
478+
#else
476479
mode_t mode = 0;
480+
#endif
477481
if (flags & O_CREAT) {
478482
mode = va_arg(args, int);
479483
}
@@ -483,7 +487,11 @@ ALWAYS_INLINE NP_DECL(int) open(const char *pathname, int flags, ... /* mode_t m
483487
ALWAYS_INLINE NP_DECL(int) _open(const char *pathname, int flags, ... /* mode_t mode */ ) {
484488
va_list args;
485489
va_start(args, flags);
490+
#ifdef _WIN32
491+
int mode = 0;
492+
#else
486493
mode_t mode = 0;
494+
#endif
487495
if (flags & O_CREAT) {
488496
mode = va_arg(args, int);
489497
}
@@ -521,32 +529,26 @@ ALWAYS_INLINE NP_DECL(int) _close(int fd) {
521529
}
522530

523531
#ifdef _WIN32
524-
#ifdef __cplusplus
525-
ALWAYS_INLINE NP_DECL(int) wopen(const wchar_t *pathname, int flags, int mode = 0) {
526-
#else
527-
ALWAYS_INLINE NP_DECL(int) wopen(const wchar_t *pathname, int flags, int mode) {
528-
#endif
529-
return np_wopen(pathname, flags, mode);
532+
ALWAYS_INLINE NP_DECL(int) wopen(const wchar_t *pathname, int flags, ... /* int mode */ ) {
533+
va_list args;
534+
va_start(args, flags);
535+
int mode = 0;
536+
if (flags & O_CREAT) {
537+
mode = va_arg(args, int);
538+
}
539+
va_end(args);
540+
return np_wopen(pathname, flags, mode);
530541
}
531-
#ifdef __cplusplus
532-
ALWAYS_INLINE NP_DECL(int) _wopen(const wchar_t *pathname, int flags, int mode = 0) {
533-
#else
534-
ALWAYS_INLINE NP_DECL(int) _wopen(const wchar_t *pathname, int flags, int mode) {
535-
#endif
536-
return np_wopen(pathname, flags, mode);
542+
ALWAYS_INLINE NP_DECL(int) _wopen(const wchar_t *pathname, int flags, ... /* int mode */ ) {
543+
va_list args;
544+
va_start(args, flags);
545+
int mode = 0;
546+
if (flags & O_CREAT) {
547+
mode = va_arg(args, int);
548+
}
549+
va_end(args);
550+
return np_wopen(pathname, flags, mode);
537551
}
538-
#ifndef __cplusplus
539-
#define wopen0() wopen()
540-
#define wopen1(a) wopen(a)
541-
#define wopen2(a, b) open(a, b, 0)
542-
#define wopen3(a, b, c) open(a, b, c)
543-
#define wopen4(a, b, c, d) wopen(a, b, c, d)
544-
#define wopen5(a, b, c, d, e) wopen(a, b, c, d, e)
545-
#define wopen6(a, b, c, d, e, f) wopen(a, b, c, d, e, f)
546-
#define wopen7(a, b, c, d, e, f, g) wopen(a, b, c, d, e, f, g)
547-
#define wopen(...) CAT( wopen, NUM_ARGS( __VA_ARGS__ ) )( __VA_ARGS__ )
548-
#define _wopen(...) CAT( wopen, NUM_ARGS( __VA_ARGS__ ) )( __VA_ARGS__ )
549-
#endif
550552

551553
ALWAYS_INLINE NP_DECL(EFILE*) wfopen(const wchar_t* file, const wchar_t* mode) {
552554
return np_wfopen(file, mode);

0 commit comments

Comments
 (0)