Skip to content

Commit 9618ea6

Browse files
committed
emulated strnlen for macOS before 10.7
1 parent 35cd6d8 commit 9618ea6

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

src/llvm-project/llvm/lib/ObjectYAML/MachOYAML.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121
#include <cstdint>
2222
#include <cstring>
2323

24+
#ifdef __APPLE__
25+
#include <Availability.h>
26+
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1070
27+
static size_t strnlen(const char *s, size_t maxlen) {
28+
size_t l = 0;
29+
while (l < maxlen && *s) {
30+
l++;
31+
s++;
32+
}
33+
return l;
34+
}
35+
#endif
36+
#endif
37+
2438
namespace llvm {
2539

2640
MachOYAML::LoadCommand::~LoadCommand() = default;

src/llvm-project/llvm/tools/llvm-objcopy/MachO/MachOReader.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313
#include "llvm/Support/Errc.h"
1414
#include <memory>
1515

16+
#ifdef __APPLE__
17+
#include <Availability.h>
18+
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1070
19+
static size_t strnlen(const char *s, size_t maxlen) {
20+
size_t l = 0;
21+
while (l < maxlen && *s) {
22+
l++;
23+
s++;
24+
}
25+
return l;
26+
}
27+
#endif
28+
#endif
29+
1630
namespace llvm {
1731
namespace objcopy {
1832
namespace macho {

src/llvm-project/llvm/tools/llvm-readobj/ObjDumper.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@
2020
#include "llvm/Support/raw_ostream.h"
2121
#include <map>
2222

23+
#ifdef __APPLE__
24+
#include <Availability.h>
25+
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1070
26+
static size_t strnlen(const char *s, size_t maxlen) {
27+
size_t l = 0;
28+
while (l < maxlen && *s) {
29+
l++;
30+
s++;
31+
}
32+
return l;
33+
}
34+
#endif
35+
#endif
36+
2337
namespace llvm {
2438

2539
static inline Error createError(const Twine &Msg) {

src/llvm-project/llvm/tools/obj2yaml/macho2yaml.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,21 @@
1515
#include "llvm/Support/ErrorHandling.h"
1616
#include "llvm/Support/LEB128.h"
1717

18-
#include <string.h> // for memcpy
18+
#include <string.h> // for memcpy and strnlen
19+
20+
#ifdef __APPLE__
21+
#include <Availability.h>
22+
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1070
23+
static size_t strnlen(const char *s, size_t maxlen) {
24+
size_t l = 0;
25+
while (l < maxlen && *s) {
26+
l++;
27+
s++;
28+
}
29+
return l;
30+
}
31+
#endif
32+
#endif
1933

2034
using namespace llvm;
2135

0 commit comments

Comments
 (0)