Skip to content

Commit 9cc07c7

Browse files
committed
[test][stdlib] Define stdio stubs for OpenBSD.
These are macros on OpenBSD, which don't get imported to an equivalent symbol in Swift.
1 parent 409603c commit 9cc07c7

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

stdlib/public/Platform/Platform.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ public func snprintf(ptr: UnsafeMutablePointer<Int8>, _ len: Int, _ format: Unsa
142142
return vsnprintf(ptr, len, format, va_args)
143143
}
144144
}
145+
#elseif os(OpenBSD)
146+
public var stdin: UnsafeMutablePointer<FILE> { return _swift_stdlib_stdin() }
147+
public var stdout: UnsafeMutablePointer<FILE> { return _swift_stdlib_stdout() }
148+
public var stderr: UnsafeMutablePointer<FILE> { return _swift_stdlib_stderr() }
145149
#elseif os(Windows)
146150
public var stdin: UnsafeMutablePointer<FILE> { return __acrt_iob_func(0) }
147151
public var stdout: UnsafeMutablePointer<FILE> { return __acrt_iob_func(1) }

stdlib/public/SwiftShims/LibcOverlayShims.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
#include "Visibility.h"
2222

23+
#if defined(__OpenBSD__)
24+
#include <stdio.h>
25+
#endif
2326
#if defined(_WIN32) && !defined(__CYGWIN__)
2427
#include <errno.h>
2528
#include <io.h>
@@ -112,6 +115,20 @@ int static inline _swift_stdlib_openat(int fd, const char *path, int oflag,
112115
}
113116
#endif
114117

118+
#if defined(__OpenBSD__)
119+
static inline FILE *_swift_stdlib_stdin(void) {
120+
return stdin;
121+
}
122+
123+
static inline FILE *_swift_stdlib_stdout(void) {
124+
return stdout;
125+
}
126+
127+
static inline FILE *_swift_stdlib_stderr(void) {
128+
return stderr;
129+
}
130+
#endif
131+
115132
#if __has_feature(nullability)
116133
#pragma clang assume_nonnull end
117134
#endif

0 commit comments

Comments
 (0)