Files
swift-mirror/stdlib/public/SwiftShims/swift/shims/LibcOverlayShims.h
Egor Zhdan 84a1ffcb33 [Shims] Include SwiftShims headers without ../
This replaces a number of `#include`-s like this:
```
#include "../../../stdlib/public/SwiftShims/Visibility.h"
```
with this:
```
#include "swift/shims/Visibility.h"
```

This is needed to allow SwiftCompilerSources to use C++ headers which include SwiftShims headers. Currently trying to do that results in errors:
```
swift/swift/include/swift/Demangling/../../../stdlib/public/SwiftShims/module.modulemap:1:8: error: redefinition of module 'SwiftShims'
module SwiftShims {
       ^
Builds.noindex/swift/swift/bootstrapping0/lib/swift/shims/module.modulemap:1:8: note: previously defined here
module SwiftShims {
       ^
```
This happens because the headers in both the source dir and the build dir refer to SwiftShims headers by relative path, and both the source root and the build root contain SwiftShims headers (which are equivalent, but since they are located in different dirs, Clang treats them as different modules).
2022-09-14 11:14:50 +01:00

139 lines
3.6 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 *_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(__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) {
return _open(path, oflag, (int)mode);
}
#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 FILE *_swift_stdlib_stdin(void) {
return stdin;
}
static inline FILE *_swift_stdlib_stdout(void) {
return stdout;
}
static inline FILE *_swift_stdlib_stderr(void) {
return stderr;
}
#endif
#if __has_feature(nullability)
#pragma clang assume_nonnull end
#endif
#endif // SWIFT_STDLIB_SHIMS_LIBCOVERLAYSHIMS_H