Skip to content

Commit 2e0aa52

Browse files
committed
emulated strnlen for macOS before 10.7
1 parent f1b5414 commit 2e0aa52

File tree

5 files changed

+71
-1
lines changed

5 files changed

+71
-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/Object/MachO.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
@@ -21,6 +21,20 @@
2121
#include "llvm/Support/raw_ostream.h"
2222
#include <map>
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
ObjDumper::ObjDumper(ScopedPrinter &Writer) : W(Writer) {}

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

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

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

1933
using namespace llvm;
2034

vendor/backtrace-sys/src/libbacktrace/macho.c

+14
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ POSSIBILITY OF SUCH DAMAGE. */
7676
#include "backtrace.h"
7777
#include "internal.h"
7878

79+
#ifdef __APPLE__
80+
#include <Availability.h>
81+
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1070
82+
static size_t strnlen(const char *s, size_t maxlen) {
83+
size_t l = 0;
84+
while (l < maxlen && *s) {
85+
l++;
86+
s++;
87+
}
88+
return l;
89+
}
90+
#endif
91+
#endif
92+
7993
struct macho_commands_view
8094
{
8195
struct backtrace_view view;

0 commit comments

Comments
 (0)