Skip to content

Commit 3d08df9

Browse files
authored
Avoid including unistd.h and replace write(STDERR) with fputs(stderr) (swiftlang#40177)
1 parent 3eba144 commit 3d08df9

File tree

4 files changed

+5
-9
lines changed

4 files changed

+5
-9
lines changed

stdlib/public/LLVMSupport/ErrorHandling.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
#include "llvm/ADT/StringRef.h"
1616
#include <cassert>
1717
#include <cstdlib>
18+
#include <cstdio>
1819

1920
#if defined(_MSC_VER)
2021
# include <io.h>
2122
# include <fcntl.h>
22-
#else
23-
# include <stdio.h>
24-
# include <unistd.h>
2523
#endif
2624

2725
#include <stdarg.h>
@@ -49,7 +47,8 @@ void error(const char *fmt, ...) {
4947
#define STDERR_FILENO 2
5048
_write(STDERR_FILENO, buffer, strlen(buffer));
5149
#else
52-
write(STDERR_FILENO, buffer, strlen(buffer));
50+
fputs(buffer, stderr);
51+
fflush(stderr);
5352
#endif
5453
}
5554
}

stdlib/public/runtime/Errors.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include <string.h>
2626
#if defined(_WIN32)
2727
#include <io.h>
28-
#else
29-
#include <unistd.h>
3028
#endif
3129
#include <stdarg.h>
3230

@@ -312,7 +310,8 @@ reportNow(uint32_t flags, const char *message)
312310
#define STDERR_FILENO 2
313311
_write(STDERR_FILENO, message, strlen(message));
314312
#else
315-
write(STDERR_FILENO, message, strlen(message));
313+
fputs(message, stderr);
314+
fflush(stderr);
316315
#endif
317316
#if SWIFT_STDLIB_HAS_ASL
318317
asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", message);

stdlib/public/stubs/Random.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#else
2626
#include <errno.h>
2727
#include <fcntl.h>
28-
#include <unistd.h>
2928
#endif
3029

3130
#if __has_include(<sys/random.h>)

stdlib/public/stubs/Stubs.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <errno.h>
3333
#endif
3434
#include <sys/resource.h>
35-
#include <unistd.h>
3635
#endif
3736
#include <climits>
3837
#include <clocale>

0 commit comments

Comments
 (0)