@@ -338,6 +338,7 @@ NP_DECL(int) np_ftrylockfile(void *e);
338
338
339
339
#if !defined(NUITKAPYTHON_EMBED_BUILD ) && !defined(NP_STDIO_ALREADY_LOADED )
340
340
341
+ #ifdef __GNUC__
341
342
#define CAT (a , ...) PRIMITIVE_CAT(a, __VA_ARGS__)
342
343
#define PRIMITIVE_CAT (a , ...) a ## __VA_ARGS__
343
344
@@ -419,7 +420,7 @@ NP_DECL(int) np_ftrylockfile(void *e);
419
420
#define NUM_ARGS1 (_20 ,_19 ,_18 ,_17 ,_16 ,_15 ,_14 ,_13 ,_12 ,_11 ,_10 ,_9 ,_8 ,_7 ,_6 ,_5 ,_4 ,_3 ,_2 ,_1 , n , ...) n
420
421
#define NUM_ARGS0 (...) NUM_ARGS1(__VA_ARGS__,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
421
422
#define NUM_ARGS (...) IF(DEC(NUM_ARGS0(__VA_ARGS__)))(NUM_ARGS0(__VA_ARGS__),IF(IS_PAREN(__VA_ARGS__ ()))(0,1))
422
-
423
+ #endif // __GNUC__
423
424
424
425
// Preprocessor Translation
425
426
#define FILE EFILE
@@ -429,7 +430,7 @@ NP_DECL(int) np_ftrylockfile(void *e);
429
430
extern EFILE * stdin ; /* Standard input stream. */
430
431
extern EFILE * stdout ; /* Standard output stream. */
431
432
extern EFILE * stderr ; /* Standard error output stream. */
432
- #endif
433
+ #endif // __linux
433
434
434
435
/* File Opening and Closing */
435
436
ALWAYS_INLINE NP_DECL (EFILE * ) fopen (const char * file , const char * mode ) {
@@ -439,33 +440,18 @@ ALWAYS_INLINE NP_DECL(EFILE*) _fopen(const char* file, const char* mode) {
439
440
return np_fopen (file , mode );
440
441
}
441
442
442
- #ifdef _WIN32
443
- #ifdef __cplusplus
444
- ALWAYS_INLINE NP_DECL (int ) open (const char * pathname , int flags , int mode = 0 ) {
445
- #else
446
- ALWAYS_INLINE NP_DECL (int ) open (const char * pathname , int flags , int mode ) {
447
- #endif
448
- #else
443
+ #ifdef __GNUC__
449
444
#ifdef __cplusplus
450
445
ALWAYS_INLINE NP_DECL (int ) open (const char * pathname , int flags , mode_t mode = 0 ) {
451
446
#else
452
447
ALWAYS_INLINE NP_DECL (int ) open (const char * pathname , int flags , mode_t mode ) {
453
- #endif
454
448
#endif
455
449
return np_open (pathname , flags , mode );
456
450
}
457
- #ifdef _WIN32
458
- #ifdef __cplusplus
459
- ALWAYS_INLINE NP_DECL (int ) _open (const char * pathname , int flags , int mode = 0 ) {
460
- #else
461
- ALWAYS_INLINE NP_DECL (int ) _open (const char * pathname , int flags , int mode ) {
462
- #endif
463
- #else
464
451
#ifdef __cplusplus
465
452
ALWAYS_INLINE NP_DECL (int ) _open (const char * pathname , int flags , mode_t mode = 0 ) {
466
453
#else
467
454
ALWAYS_INLINE NP_DECL (int ) _open (const char * pathname , int flags , mode_t mode ) {
468
- #endif
469
455
#endif
470
456
return np_open (pathname , flags , mode );
471
457
}
@@ -482,7 +468,29 @@ ALWAYS_INLINE NP_DECL(int) _open(const char *pathname, int flags, mode_t mode) {
482
468
#define open7 (a , b , c , d , e , f , g ) open(a, b, c, d, e, f, g)
483
469
#define open (...) CAT( open, NUM_ARGS( __VA_ARGS__ ) )( __VA_ARGS__ )
484
470
#define _open (...) CAT( open, NUM_ARGS( __VA_ARGS__ ) )( __VA_ARGS__ )
485
- #endif
471
+ #endif // !__cplusplus
472
+ #else // __GNUC__
473
+ ALWAYS_INLINE NP_DECL (int ) open (const char * pathname , int flags , ... /* mode_t mode */ ) {
474
+ va_list args ;
475
+ va_start (args , flags );
476
+ mode_t mode = 0 ;
477
+ if (flags & O_CREAT ) {
478
+ mode = va_arg (args , int );
479
+ }
480
+ va_end (args );
481
+ return np_open (pathname , flags , mode );
482
+ }
483
+ ALWAYS_INLINE NP_DECL (int ) _open (const char * pathname , int flags , ... /* mode_t mode */ ) {
484
+ va_list args ;
485
+ va_start (args , flags );
486
+ mode_t mode = 0 ;
487
+ if (flags & O_CREAT ) {
488
+ mode = va_arg (args , int );
489
+ }
490
+ va_end (args );
491
+ return np_open (pathname , flags , mode );
492
+ }
493
+ #endif // !__GNUC__
486
494
487
495
ALWAYS_INLINE NP_DECL (EFILE * ) fdopen (int fd , const char * mode ) {
488
496
return np_fdopen (fd , mode );
@@ -546,7 +554,7 @@ ALWAYS_INLINE NP_DECL(EFILE*) wfopen(const wchar_t* file, const wchar_t* mode) {
546
554
ALWAYS_INLINE NP_DECL (EFILE * ) _wfopen (const wchar_t * file , const wchar_t * mode ) {
547
555
return np_wfopen (file , mode );
548
556
}
549
- #endif
557
+ #endif // _WIN32
550
558
551
559
ALWAYS_INLINE NP_DECL (EFILE * ) tmpfile () {
552
560
return np_tmpfile ();
0 commit comments