diff --git a/bin/commands.cpp b/bin/commands.cpp index 83093a8..b255934 100644 --- a/bin/commands.cpp +++ b/bin/commands.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -239,4 +240,4 @@ namespace Debug { } -} \ No newline at end of file +} diff --git a/bin/debugger.cpp b/bin/debugger.cpp index 390164b..84137d7 100644 --- a/bin/debugger.cpp +++ b/bin/debugger.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include diff --git a/bin/intern.cpp b/bin/intern.cpp index 2a65947..c334ad6 100644 --- a/bin/intern.cpp +++ b/bin/intern.cpp @@ -1,5 +1,6 @@ #include "intern.h" #include +#include namespace { diff --git a/bin/lexer.rl b/bin/lexer.rl index 45e8510..3f3ac45 100644 --- a/bin/lexer.rl +++ b/bin/lexer.rl @@ -31,6 +31,7 @@ #include #include +#include #include #include "debugger.h" @@ -368,7 +369,7 @@ bool ParseLine(const char *iter, Command *command) //ParseTrace(stdout, "--> "); command->action = cmdNull; - int length = strlen(iter); + int length = std::strlen(iter); const char *p = iter; const char *pe = iter + length; const char *eof = pe; @@ -431,4 +432,4 @@ bool ParseLine(const char *iter, Command *command) } -} // namespace \ No newline at end of file +} // namespace diff --git a/bin/loadtrap.rl b/bin/loadtrap.rl index 143dd62..e1af9d1 100644 --- a/bin/loadtrap.rl +++ b/bin/loadtrap.rl @@ -28,6 +28,86 @@ #include #include +#include +#include + +namespace _loadtrap_rl { +#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050 + #define _GETDELIM_GROWBY 128 /* amount to grow line buffer by */ + #define _GETDELIM_MINLEN 4 /* minimum line buffer size */ + + ssize_t getdelim(char ** lineptr, size_t * n, int delimiter, FILE * stream) { + char *buf, *pos; + int c; + ssize_t bytes; + + if (lineptr == NULL || n == NULL) { + errno = EINVAL; + return -1; + } + if (stream == NULL) { + errno = EBADF; + return -1; + } + + /* resize (or allocate) the line buffer if necessary */ + buf = *lineptr; + if (buf == NULL || *n < _GETDELIM_MINLEN) { + buf = (char*)realloc(*lineptr, _GETDELIM_GROWBY); + if (buf == NULL) { + /* ENOMEM */ + return -1; + } + *n = _GETDELIM_GROWBY; + *lineptr = buf; + } + + /* read characters until delimiter is found, end of file is reached, or an + error occurs. */ + bytes = 0; + pos = buf; + while ((c = getc(stream)) != EOF) { + if (bytes + 1 >= SSIZE_MAX) { + errno = EOVERFLOW; + return -1; + } + bytes++; + if (bytes >= *n - 1) { + buf = (char*)realloc(*lineptr, *n + _GETDELIM_GROWBY); + if (buf == NULL) { + /* ENOMEM */ + return -1; + } + *n += _GETDELIM_GROWBY; + pos = buf + bytes - 1; + *lineptr = buf; + } + + *pos++ = (char) c; + if (c == delimiter) { + break; + } + } + + if (ferror(stream) || (feof(stream) && (bytes == 0))) { + /* EOF, or an error from getc(). */ + return -1; + } + + *pos = '\0'; + return bytes; + } +#endif + + + ssize_t getline(char ** lineptr, size_t * n, FILE * stream) { +#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050 + return getdelim(lineptr, n, '\n', stream); +#else + return ::getline(lineptr, n, stream); +#endif + } +} namespace { // private... %%{ @@ -155,7 +235,7 @@ namespace Debug { char *line; ssize_t length; - length = getline(&lineBuffer, &lineSize, fp); + length = _loadtrap_rl::getline(&lineBuffer, &lineSize, fp); if (!length) continue; //? if (length < 0) break; // eof or error. diff --git a/bin/parser.lemon b/bin/parser.lemon index 6c6b19f..582f533 100644 --- a/bin/parser.lemon +++ b/bin/parser.lemon @@ -8,6 +8,7 @@ #include #include #include +#include #include "debugger.h" #include diff --git a/bin/template.cpp b/bin/template.cpp index 9792156..f8a0c56 100644 --- a/bin/template.cpp +++ b/bin/template.cpp @@ -3,6 +3,8 @@ #include "debugger_internal.h" #include "loader.h" // Flags. +#include + #include diff --git a/bin/template_loader.rl b/bin/template_loader.rl index 7edd15e..efd9665 100644 --- a/bin/template_loader.rl +++ b/bin/template_loader.rl @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -251,4 +252,4 @@ bool LoadTemplateFile(const std::string &filename, std::unordered_map #include #include + #include #include "template.h" diff --git a/mpw/environment.rl b/mpw/environment.rl index 5d79bac..ddc04dc 100644 --- a/mpw/environment.rl +++ b/mpw/environment.rl @@ -29,6 +29,86 @@ #include #include +#include +#include + +namespace _env_rl { +#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050 + #define _GETDELIM_GROWBY 128 /* amount to grow line buffer by */ + #define _GETDELIM_MINLEN 4 /* minimum line buffer size */ + + ssize_t getdelim(char ** lineptr, size_t * n, int delimiter, FILE * stream) { + char *buf, *pos; + int c; + ssize_t bytes; + + if (lineptr == NULL || n == NULL) { + errno = EINVAL; + return -1; + } + if (stream == NULL) { + errno = EBADF; + return -1; + } + + /* resize (or allocate) the line buffer if necessary */ + buf = *lineptr; + if (buf == NULL || *n < _GETDELIM_MINLEN) { + buf = (char*)realloc(*lineptr, _GETDELIM_GROWBY); + if (buf == NULL) { + /* ENOMEM */ + return -1; + } + *n = _GETDELIM_GROWBY; + *lineptr = buf; + } + + /* read characters until delimiter is found, end of file is reached, or an + error occurs. */ + bytes = 0; + pos = buf; + while ((c = getc(stream)) != EOF) { + if (bytes + 1 >= SSIZE_MAX) { + errno = EOVERFLOW; + return -1; + } + bytes++; + if (bytes >= *n - 1) { + buf = (char*)realloc(*lineptr, *n + _GETDELIM_GROWBY); + if (buf == NULL) { + /* ENOMEM */ + return -1; + } + *n += _GETDELIM_GROWBY; + pos = buf + bytes - 1; + *lineptr = buf; + } + + *pos++ = (char) c; + if (c == delimiter) { + break; + } + } + + if (ferror(stream) || (feof(stream) && (bytes == 0))) { + /* EOF, or an error from getc(). */ + return -1; + } + + *pos = '\0'; + return bytes; + } +#endif + + + ssize_t getline(char ** lineptr, size_t * n, FILE * stream) { +#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050 + return getdelim(lineptr, n, '\n', stream); +#else + return ::getline(lineptr, n, stream); +#endif + } +} namespace MPW { @@ -308,7 +388,7 @@ namespace MPW { char *line; ssize_t length; - length = getline(&lineBuffer, &lineSize, fp); + length = _env_rl::getline(&lineBuffer, &lineSize, fp); if (!length) continue; //? if (length < 0) break; // eof or error. diff --git a/mpw/mpw.cpp b/mpw/mpw.cpp index 11c4e1a..37bd031 100644 --- a/mpw/mpw.cpp +++ b/mpw/mpw.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include diff --git a/toolbox/loader.cpp b/toolbox/loader.cpp index 533fe51..50b8694 100644 --- a/toolbox/loader.cpp +++ b/toolbox/loader.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include @@ -552,4 +553,4 @@ namespace Loader { -} \ No newline at end of file +} diff --git a/toolbox/mm.cpp b/toolbox/mm.cpp index abe9c8f..36ca526 100644 --- a/toolbox/mm.cpp +++ b/toolbox/mm.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include diff --git a/toolbox/os_fileinfo.cpp b/toolbox/os_fileinfo.cpp index badddab..ce9a999 100644 --- a/toolbox/os_fileinfo.cpp +++ b/toolbox/os_fileinfo.cpp @@ -59,7 +59,9 @@ using ToolBox::Log; using MacOS::macos_error_from_errno; - +#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050 +#define st_birthtime st_mtime +#endif namespace { @@ -348,4 +350,4 @@ namespace OS { -} \ No newline at end of file +} diff --git a/toolbox/os_hfs_dispatch.cpp b/toolbox/os_hfs_dispatch.cpp index 2ad360f..5743008 100644 --- a/toolbox/os_hfs_dispatch.cpp +++ b/toolbox/os_hfs_dispatch.cpp @@ -25,13 +25,14 @@ */ #include - #include +#include #include #include #include #include #include #include +#include #include #include @@ -54,6 +55,10 @@ #include "stackframe.h" #include "fs_spec.h" +#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050 +#define st_birthtime st_mtime +#endif + using ToolBox::Log; using MacOS::macos_error_from_errno; diff --git a/toolbox/os_highlevel.cpp b/toolbox/os_highlevel.cpp index e08b2a2..0aed0b1 100644 --- a/toolbox/os_highlevel.cpp +++ b/toolbox/os_highlevel.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,7 @@ #include #include #include +#include #include diff --git a/toolbox/os_internal.cpp b/toolbox/os_internal.cpp index 507b14e..e60bf44 100644 --- a/toolbox/os_internal.cpp +++ b/toolbox/os_internal.cpp @@ -32,6 +32,9 @@ #include #include +#include +#include +#include #include #include @@ -115,7 +118,7 @@ namespace OS { namespace Internal { if (rv1 == 1 && rv2 == 2) { #if BYTE_ORDER == BIG_ENDIAN - ftype = (ftype >> 8) | (ftype << 8) + ftype = (ftype >> 8) | (ftype << 8); #endif char tmp[8] = { @@ -187,7 +190,7 @@ namespace OS { namespace Internal { // convert pdos types... - if (::memcmp(buffer + 4, "pdos", 4) == 0) + if (std::memcmp(buffer + 4, "pdos", 4) == 0) { // mpw expects 'xx ' where // xx are the ascii-encode hex value of the file type. diff --git a/toolbox/os_internal.h b/toolbox/os_internal.h index b8e12fe..ce46bc0 100644 --- a/toolbox/os_internal.h +++ b/toolbox/os_internal.h @@ -3,6 +3,7 @@ #include #include +#include namespace OS { namespace Internal { diff --git a/toolbox/realpath.c b/toolbox/realpath.c index d104fc6..42e6bae 100644 --- a/toolbox/realpath.c +++ b/toolbox/realpath.c @@ -30,7 +30,6 @@ static char sccsid[] = "@(#)realpath.c 8.1 (Berkeley) 2/16/94"; #endif /* LIBC_SCCS and not lint */ #include -__FBSDID("$FreeBSD$"); //#include "namespace.h" #include diff --git a/toolbox/rm.cpp b/toolbox/rm.cpp index 389bf46..39cc58b 100644 --- a/toolbox/rm.cpp +++ b/toolbox/rm.cpp @@ -25,10 +25,13 @@ */ #include +#include #include #include #include +#include + #include #include "rm.h" diff --git a/toolbox/sane.cpp b/toolbox/sane.cpp index 7a4ada0..ad692ed 100644 --- a/toolbox/sane.cpp +++ b/toolbox/sane.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include "stackframe.h" @@ -133,13 +134,13 @@ using std::to_string; complex &operator=(long double ld) { - switch(fpclassify(ld)) + switch(std::fpclassify(ld)) { case FP_NAN: _data = NaN; break; case FP_INFINITE: - if (signbit(ld)) + if (std::signbit(ld)) { _data = -INT64_MAX; } @@ -159,13 +160,13 @@ using std::to_string; complex &operator=(double d) { - switch(fpclassify(d)) + switch(std::fpclassify(d)) { case FP_NAN: _data = NaN; break; case FP_INFINITE: - if (signbit(d)) + if (std::signbit(d)) { _data = -INT64_MAX; } @@ -720,18 +721,18 @@ using std::to_string; } - inline int classify(float x) { return fpclassify(x); } - inline int classify(double x) { return fpclassify(x); } - inline int classify(extended x) { return fpclassify(x); } + inline int classify(float x) { return std::fpclassify(x); } + inline int classify(double x) { return std::fpclassify(x); } + inline int classify(extended x) { return std::fpclassify(x); } inline int classify(complex c) { if (c.isnan()) return FP_NAN; if ((uint64_t)c == (uint64_t)0) return FP_ZERO; return FP_NORMAL; } - inline int sign(float x) { return signbit(x); } - inline int sign(double x) { return signbit(x); } - inline int sign(extended x) { return signbit(x); } + inline int sign(float x) { return std::signbit(x); } + inline int sign(double x) { return std::signbit(x); } + inline int sign(extended x) { return std::signbit(x); } inline int sign(complex c) { if (c.isnan()) return 0; return ((int64_t)c < (int64_t)0) ? 1 : 0; @@ -1161,4 +1162,4 @@ struct decimal { } -} \ No newline at end of file +}