gcc-4.9 support/c11 fixes

This commit is contained in:
tsupplis 2015-02-17 00:23:12 +00:00
parent 8bfff02114
commit 88bc42d153
21 changed files with 212 additions and 24 deletions

View File

@ -2,6 +2,7 @@
#include <cstdint> #include <cstdint>
#include <ctime> #include <ctime>
#include <cstdio> #include <cstdio>
#include <cstring>
#include <toolbox/os.h> #include <toolbox/os.h>
@ -239,4 +240,4 @@ namespace Debug {
} }
} }

View File

@ -28,6 +28,7 @@
#include <cctype> #include <cctype>
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
#include <algorithm>
#include <signal.h> #include <signal.h>

View File

@ -1,5 +1,6 @@
#include "intern.h" #include "intern.h"
#include <unordered_map> #include <unordered_map>
#include <cstring>
namespace { namespace {

View File

@ -31,6 +31,7 @@
#include <deque> #include <deque>
#include <cstdint> #include <cstdint>
#include <cstring>
#include <stdlib.h> #include <stdlib.h>
#include "debugger.h" #include "debugger.h"
@ -368,7 +369,7 @@ bool ParseLine(const char *iter, Command *command)
//ParseTrace(stdout, "--> "); //ParseTrace(stdout, "--> ");
command->action = cmdNull; command->action = cmdNull;
int length = strlen(iter); int length = std::strlen(iter);
const char *p = iter; const char *p = iter;
const char *pe = iter + length; const char *pe = iter + length;
const char *eof = pe; const char *eof = pe;
@ -431,4 +432,4 @@ bool ParseLine(const char *iter, Command *command)
} }
} // namespace } // namespace

View File

@ -28,6 +28,86 @@
#include <string> #include <string>
#include <cstdio> #include <cstdio>
#include <sys/types.h>
#include <limits.h>
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 { namespace {
// private... // private...
%%{ %%{
@ -155,7 +235,7 @@ namespace Debug {
char *line; char *line;
ssize_t length; ssize_t length;
length = getline(&lineBuffer, &lineSize, fp); length = _loadtrap_rl::getline(&lineBuffer, &lineSize, fp);
if (!length) continue; //? if (!length) continue; //?
if (length < 0) break; // eof or error. if (length < 0) break; // eof or error.

View File

@ -8,6 +8,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <cassert> #include <cassert>
#include <cstddef>
#include "debugger.h" #include "debugger.h"
#include <toolbox/MM.h> #include <toolbox/MM.h>

View File

@ -3,6 +3,8 @@
#include "debugger_internal.h" #include "debugger_internal.h"
#include "loader.h" // Flags. #include "loader.h" // Flags.
#include <algorithm>
#include <toolbox/toolbox.h> #include <toolbox/toolbox.h>

View File

@ -1,5 +1,6 @@
#include <string> #include <string>
#include <cstddef>
#include <unordered_map> #include <unordered_map>
#include <algorithm> #include <algorithm>
#include <numeric> #include <numeric>
@ -251,4 +252,4 @@ bool LoadTemplateFile(const std::string &filename, std::unordered_map<std::strin
return true; return true;
} }
} }

View File

@ -8,6 +8,7 @@
#include <string> #include <string>
#include <stdlib.h> #include <stdlib.h>
#include <cassert> #include <cassert>
#include <cstddef>
#include "template.h" #include "template.h"

View File

@ -29,6 +29,86 @@
#include <cstdio> #include <cstdio>
#include <vector> #include <vector>
#include <sys/types.h>
#include <limits.h>
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 namespace MPW
{ {
@ -308,7 +388,7 @@ namespace MPW {
char *line; char *line;
ssize_t length; ssize_t length;
length = getline(&lineBuffer, &lineSize, fp); length = _env_rl::getline(&lineBuffer, &lineSize, fp);
if (!length) continue; //? if (!length) continue; //?
if (length < 0) break; // eof or error. if (length < 0) break; // eof or error.

View File

@ -30,6 +30,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <cstring>
#include <deque> #include <deque>
#include <unordered_map> #include <unordered_map>

View File

@ -25,6 +25,7 @@
*/ */
#include <string> #include <string>
#include <cstring>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <unordered_map> #include <unordered_map>
@ -552,4 +553,4 @@ namespace Loader {
} }

View File

@ -32,6 +32,7 @@
#include <cpu/fmem.h> #include <cpu/fmem.h>
#include <string> #include <string>
#include <cstring>
#include <deque> #include <deque>
#include <vector> #include <vector>
#include <map> #include <map>

View File

@ -59,7 +59,9 @@ using ToolBox::Log;
using MacOS::macos_error_from_errno; using MacOS::macos_error_from_errno;
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
#define st_birthtime st_mtime
#endif
namespace { namespace {
@ -348,4 +350,4 @@ namespace OS {
} }

View File

@ -25,13 +25,14 @@
*/ */
#include <cerrno> #include <cerrno>
#include <cassert> #include <cassert>
#include <cctype> #include <cctype>
#include <ctime> #include <ctime>
#include <algorithm> #include <algorithm>
#include <chrono> #include <chrono>
#include <deque> #include <deque>
#include <string> #include <string>
#include <cstring>
#include <sys/xattr.h> #include <sys/xattr.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -54,6 +55,10 @@
#include "stackframe.h" #include "stackframe.h"
#include "fs_spec.h" #include "fs_spec.h"
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
#define st_birthtime st_mtime
#endif
using ToolBox::Log; using ToolBox::Log;
using MacOS::macos_error_from_errno; using MacOS::macos_error_from_errno;

View File

@ -31,6 +31,7 @@
#include <chrono> #include <chrono>
#include <deque> #include <deque>
#include <string> #include <string>
#include <cstring>
#include <sys/xattr.h> #include <sys/xattr.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -40,6 +41,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <limits.h>
#include <strings.h> #include <strings.h>

View File

@ -32,6 +32,9 @@
#include <stdexcept> #include <stdexcept>
#include <cerrno> #include <cerrno>
#include <cstring>
#include <algorithm>
#include <memory>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
@ -115,7 +118,7 @@ namespace OS { namespace Internal {
if (rv1 == 1 && rv2 == 2) if (rv1 == 1 && rv2 == 2)
{ {
#if BYTE_ORDER == BIG_ENDIAN #if BYTE_ORDER == BIG_ENDIAN
ftype = (ftype >> 8) | (ftype << 8) ftype = (ftype >> 8) | (ftype << 8);
#endif #endif
char tmp[8] = { char tmp[8] = {
@ -187,7 +190,7 @@ namespace OS { namespace Internal {
// convert pdos types... // convert pdos types...
if (::memcmp(buffer + 4, "pdos", 4) == 0) if (std::memcmp(buffer + 4, "pdos", 4) == 0)
{ {
// mpw expects 'xx ' where // mpw expects 'xx ' where
// xx are the ascii-encode hex value of the file type. // xx are the ascii-encode hex value of the file type.

View File

@ -3,6 +3,7 @@
#include <deque> #include <deque>
#include <string> #include <string>
#include <sys/types.h>
namespace OS { namespace Internal { namespace OS { namespace Internal {

View File

@ -30,7 +30,6 @@
static char sccsid[] = "@(#)realpath.c 8.1 (Berkeley) 2/16/94"; static char sccsid[] = "@(#)realpath.c 8.1 (Berkeley) 2/16/94";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
//#include "namespace.h" //#include "namespace.h"
#include <sys/param.h> #include <sys/param.h>

View File

@ -25,10 +25,13 @@
*/ */
#include <string> #include <string>
#include <cstring>
#include <list> #include <list>
#include <map> #include <map>
#include <unordered_set> #include <unordered_set>
#include <unistd.h>
#include <CoreServices/CoreServices.h> #include <CoreServices/CoreServices.h>
#include "rm.h" #include "rm.h"

View File

@ -34,6 +34,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
#include <cstring>
#include <cmath> #include <cmath>
#include "stackframe.h" #include "stackframe.h"
@ -133,13 +134,13 @@ using std::to_string;
complex &operator=(long double ld) complex &operator=(long double ld)
{ {
switch(fpclassify(ld)) switch(std::fpclassify(ld))
{ {
case FP_NAN: case FP_NAN:
_data = NaN; _data = NaN;
break; break;
case FP_INFINITE: case FP_INFINITE:
if (signbit(ld)) if (std::signbit(ld))
{ {
_data = -INT64_MAX; _data = -INT64_MAX;
} }
@ -159,13 +160,13 @@ using std::to_string;
complex &operator=(double d) complex &operator=(double d)
{ {
switch(fpclassify(d)) switch(std::fpclassify(d))
{ {
case FP_NAN: case FP_NAN:
_data = NaN; _data = NaN;
break; break;
case FP_INFINITE: case FP_INFINITE:
if (signbit(d)) if (std::signbit(d))
{ {
_data = -INT64_MAX; _data = -INT64_MAX;
} }
@ -720,18 +721,18 @@ using std::to_string;
} }
inline int classify(float x) { return fpclassify(x); } inline int classify(float x) { return std::fpclassify(x); }
inline int classify(double x) { return fpclassify(x); } inline int classify(double x) { return std::fpclassify(x); }
inline int classify(extended x) { return fpclassify(x); } inline int classify(extended x) { return std::fpclassify(x); }
inline int classify(complex c) { inline int classify(complex c) {
if (c.isnan()) return FP_NAN; if (c.isnan()) return FP_NAN;
if ((uint64_t)c == (uint64_t)0) return FP_ZERO; if ((uint64_t)c == (uint64_t)0) return FP_ZERO;
return FP_NORMAL; return FP_NORMAL;
} }
inline int sign(float x) { return signbit(x); } inline int sign(float x) { return std::signbit(x); }
inline int sign(double x) { return signbit(x); } inline int sign(double x) { return std::signbit(x); }
inline int sign(extended x) { return signbit(x); } inline int sign(extended x) { return std::signbit(x); }
inline int sign(complex c) { inline int sign(complex c) {
if (c.isnan()) return 0; if (c.isnan()) return 0;
return ((int64_t)c < (int64_t)0) ? 1 : 0; return ((int64_t)c < (int64_t)0) ? 1 : 0;
@ -1161,4 +1162,4 @@ struct decimal {
} }
} }