Skip to content

Commit f7a3440

Browse files
anematodePikaCat-OuO
authored andcommitted
Fix compilation on BSD/macOS
No functional change
1 parent 9133698 commit f7a3440

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

src/shm.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <utility>
3737
#include <variant>
3838

39-
#if !defined(_WIN32) && !defined(__ANDROID__)
39+
#if defined(__linux__) && !defined(__ANDROID__)
4040
#include "shm_linux.h"
4141
#endif
4242

@@ -60,7 +60,7 @@
6060
#define NOMINMAX
6161
#endif
6262
#include <windows.h>
63-
#else
63+
#elif defined(__linux__)
6464
#include <cstring>
6565
#include <fcntl.h>
6666
#include <pthread.h>
@@ -407,7 +407,7 @@ class SharedMemoryBackend {
407407
std::string last_error_message;
408408
};
409409

410-
#elif !defined(__ANDROID__)
410+
#elif defined(__linux__) && !defined(__ANDROID__)
411411

412412
template<typename T>
413413
class SharedMemoryBackend {
@@ -538,7 +538,7 @@ struct SystemWideSharedConstant {
538538
std::snprintf(buf, sizeof(buf), "Local\\sf_%zu$%zu$%zu", content_hash, executable_hash, discriminator);
539539
std::string shm_name = buf;
540540

541-
#if !defined(_WIN32)
541+
#if defined(__linux__) && !defined(__ANDROID__)
542542
// POSIX shared memory names must start with a slash
543543
shm_name = "/sf_" + createHashString(shm_name);
544544

src/shm_linux.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#ifndef SHM_LINUX_H_INCLUDED
2020
#define SHM_LINUX_H_INCLUDED
2121

22+
#if !defined(__linux__) || defined(__ANDROID__)
23+
#error shm_linux.h should not be included on this platform.
24+
#endif
25+
2226
#include <atomic>
2327
#include <cassert>
2428
#include <cerrno>
@@ -40,15 +44,8 @@
4044
#include <sys/mman.h>
4145
#include <sys/stat.h>
4246
#include <unistd.h>
43-
44-
#if defined(__NetBSD__) || defined(__DragonFly__) || defined(__linux__)
45-
#include <limits.h>
46-
#define SF_MAX_SEM_NAME_LEN NAME_MAX
47-
#elif defined(__APPLE__)
48-
#define SF_MAX_SEM_NAME_LEN 31
49-
#else
50-
#define SF_MAX_SEM_NAME_LEN 255
51-
#endif
47+
#include <limits.h>
48+
#define SF_MAX_SEM_NAME_LEN NAME_MAX
5249

5350
#include "misc.h"
5451

0 commit comments

Comments
 (0)