mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
OpenBSD 7.8 snapshots hide the type information for FILE. Therefore, the types for the standard stdio streams should (regrettably) be OpaquePointer, due to the well-discussed issue of losing type information for forward-declared C types. We explicitly drop to void * in the LibcOverlayShims for backwards compatibility, since OpenBSD 7.8 is not yet released.
142 lines
3.7 KiB
C++
142 lines
3.7 KiB
C++
//===--- LibcOverlayShims.h - Static inline shims for POSIX functions. --*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Provide small wrappers for POSIX functionality that can't be used
|
|
// directly from Swift due to varargs or other issues.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_STDLIB_SHIMS_LIBCOVERLAYSHIMS_H
|
|
#define SWIFT_STDLIB_SHIMS_LIBCOVERLAYSHIMS_H
|
|
|
|
#include "Visibility.h"
|
|
|
|
#if defined(__OpenBSD__)
|
|
#include <stdio.h>
|
|
#endif
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
#include <errno.h>
|
|
#include <io.h>
|
|
typedef int mode_t;
|
|
#else
|
|
#include <semaphore.h>
|
|
#include <sys/ioctl.h>
|
|
#include <sys/types.h>
|
|
#endif
|
|
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
|
|
#if __has_feature(nullability)
|
|
#pragma clang assume_nonnull begin
|
|
#endif
|
|
|
|
// File control <fcntl.h>
|
|
#if !defined(_WIN32) || defined(__CYGWIN__)
|
|
static inline int _swift_stdlib_fcntl(int fd, int cmd, int value) {
|
|
return fcntl(fd, cmd, value);
|
|
}
|
|
|
|
static inline int _swift_stdlib_fcntlPtr(int fd, int cmd, void* ptr) {
|
|
return fcntl(fd, cmd, ptr);
|
|
}
|
|
#endif
|
|
|
|
// Environment
|
|
#if SWIFT_STDLIB_HAS_ENVIRON
|
|
#if defined(__FreeBSD__) || defined(__OpenBSD__)
|
|
static inline char * _Nullable * _Null_unspecified _swift_stdlib_getEnviron() {
|
|
extern char **environ;
|
|
return environ;
|
|
}
|
|
#elif defined(__APPLE__)
|
|
static inline char * _Nullable * _Null_unspecified _swift_stdlib_getEnviron() {
|
|
extern char * _Nullable **_NSGetEnviron(void);
|
|
return *_NSGetEnviron();
|
|
}
|
|
#endif
|
|
#endif // SWIFT_STDLIB_HAS_ENVIRON
|
|
|
|
// System error numbers <errno.h>
|
|
static inline int _swift_stdlib_getErrno() {
|
|
return errno;
|
|
}
|
|
|
|
static inline void _swift_stdlib_setErrno(int value) {
|
|
errno = value;
|
|
}
|
|
|
|
// Semaphores <semaphore.h>
|
|
#if (!defined(_WIN32) && !defined(__wasi__)) || defined(__CYGWIN__)
|
|
static inline sem_t *_stdlib_sem_open2(const char *name, int oflag) {
|
|
return sem_open(name, oflag);
|
|
}
|
|
|
|
static inline sem_t *_stdlib_sem_open4(const char *name, int oflag,
|
|
mode_t mode, unsigned int value) {
|
|
return sem_open(name, oflag, mode, value);
|
|
}
|
|
|
|
#endif // !(defined(_WIN32) && !defined(__CYGWIN__))
|
|
|
|
// I/O control <ioctl.h>
|
|
#if !defined(_WIN32) || defined(__CYGWIN__)
|
|
static inline int _swift_stdlib_ioctl(int fd, unsigned long int request, int value) {
|
|
return ioctl(fd, request, value);
|
|
}
|
|
|
|
static inline int _swift_stdlib_ioctlPtr(int fd, unsigned long int request, void* ptr) {
|
|
return ioctl(fd, request, ptr);
|
|
}
|
|
#endif
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
// Windows
|
|
static inline int _swift_stdlib_open(const char *path, int oflag, mode_t mode) {
|
|
int fh;
|
|
errno_t err = _sopen_s(&fh, path, oflag, _SH_DENYNO, mode);
|
|
__assume(err == 0 || fh == -1);
|
|
return fh;
|
|
}
|
|
|
|
#else
|
|
// not Windows
|
|
int static inline _swift_stdlib_open(const char *path, int oflag, mode_t mode) {
|
|
return open(path, oflag, mode);
|
|
}
|
|
|
|
int static inline _swift_stdlib_openat(int fd, const char *path, int oflag,
|
|
mode_t mode) {
|
|
return openat(fd, path, oflag, mode);
|
|
}
|
|
#endif
|
|
|
|
#if defined(__OpenBSD__)
|
|
static inline void *_swift_stdlib_stdin(void) {
|
|
return stdin;
|
|
}
|
|
|
|
static inline void *_swift_stdlib_stdout(void) {
|
|
return stdout;
|
|
}
|
|
|
|
static inline void *_swift_stdlib_stderr(void) {
|
|
return stderr;
|
|
}
|
|
#endif
|
|
|
|
#if __has_feature(nullability)
|
|
#pragma clang assume_nonnull end
|
|
#endif
|
|
|
|
#endif // SWIFT_STDLIB_SHIMS_LIBCOVERLAYSHIMS_H
|