28 #define NORETURN __declspec(noreturn) 30 #define NORETURN __attribute__((noreturn)) 37 #if defined(__cplusplus) && __cplusplus >= 201703L 38 #define NINJA_FALLTHROUGH [[fallthrough]] 39 #elif defined(__cplusplus) && __cplusplus >= 201103L && defined(__clang__) 40 #define NINJA_FALLTHROUGH [[clang::fallthrough]] 41 #elif defined(__cplusplus) && __cplusplus >= 201103L && defined(__GNUC__) && \ 43 #define NINJA_FALLTHROUGH [[gnu::fallthrough]] 44 #elif defined(__GNUC__) && __GNUC__ >= 7 // gcc 7 45 #define NINJA_FALLTHROUGH __attribute__ ((fallthrough)) 46 #else // C++11 on gcc 6, and all other cases 47 #define NINJA_FALLTHROUGH 51 void Warning(
const char* msg, ...);
54 void Error(
const char* msg, ...);
74 int ReadFile(
const std::string& path, std::string* contents, std::string* err);
82 const std::vector<const char*>& words);
102 std::string
ElideMiddle(
const std::string& str,
size_t width);
105 bool Truncate(
const std::string& path,
size_t size, std::string* err);
108 #define snprintf _snprintf 109 #define fileno _fileno 110 #define unlink _unlink 112 #define strtoull _strtoui64 113 #define getcwd _getcwd 114 #define PATH_MAX _MAX_PATH 119 std::string GetLastErrorString();
122 NORETURN void Win32Fatal(
const char*
function,
const char* hint = NULL);
125 #endif // NINJA_UTIL_H_ void GetWin32EscapedString(const std::string &input, std::string *result)
const char * SpellcheckStringV(const std::string &text, const std::vector< const char *> &words)
Given a misspelled string and a list of correct spellings, returns the closest match or NULL if there...
const char * SpellcheckString(const char *text,...)
Like SpellcheckStringV, but takes a NULL-terminated list.
void Error(const char *msg,...)
Log an error message.
NORETURN void Fatal(const char *msg,...)
Log a fatal message and exit.
bool Truncate(const std::string &path, size_t size, std::string *err)
Truncates a file to the given size.
void Warning(const char *msg,...)
Log a warning message.
std::string StripAnsiEscapeCodes(const std::string &in)
Removes all Ansi escape codes (http://www.termsys.demon.co.uk/vtansi.htm).
std::string ElideMiddle(const std::string &str, size_t width)
Elide the given string str with '...' in the middle if the length exceeds width.
void GetShellEscapedString(const std::string &input, std::string *result)
Appends |input| to |*result|, escaping according to the whims of either Bash, or Win32's CommandLineT...
unsigned long long uint64_t
void SetCloseOnExec(int fd)
Mark a file descriptor to not be inherited on exec()s.
int ReadFile(const std::string &path, std::string *contents, std::string *err)
Read a file to a string (in text mode: with CRLF conversion on Windows).
bool CanonicalizePath(std::string *path, uint64_t *slash_bits, std::string *err)
Canonicalize a path like "foo/../bar.h" into just "bar.h".