|
Ninja
|
#include "util.h"#include <assert.h>#include <errno.h>#include <fcntl.h>#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>#include <sys/time.h>#include <vector>#include "edit_distance.h"#include "metrics.h"
Go to the source code of this file.
Functions | |
| bool | CanonicalizePath (string *path, uint64_t *slash_bits, string *err) |
| Canonicalize a path like "foo/../bar.h" into just "bar.h". More... | |
| bool | CanonicalizePath (char *path, size_t *len, uint64_t *slash_bits, string *err) |
| string | ElideMiddle (const string &str, size_t width) |
| Elide the given string str with '...' in the middle if the length exceeds width. More... | |
| void | Error (const char *msg,...) |
| Log an error message. More... | |
| void | Fatal (const char *msg,...) |
| Log a fatal message and exit. More... | |
| double | GetLoadAverage () |
| int | GetProcessorCount () |
| void | GetShellEscapedString (const string &input, string *result) |
| Appends |input| to |*result|, escaping according to the whims of either Bash, or Win32's CommandLineToArgvW(). More... | |
| void | GetWin32EscapedString (const string &input, string *result) |
| static bool | IsKnownShellSafeCharacter (char ch) |
| static bool | IsKnownWin32SafeCharacter (char ch) |
| bool | islatinalpha (int c) |
| static bool | IsPathSeparator (char c) |
| int | ReadFile (const string &path, string *contents, string *err) |
| Read a file to a string (in text mode: with CRLF conversion on Windows). More... | |
| void | SetCloseOnExec (int fd) |
| Mark a file descriptor to not be inherited on exec()s. More... | |
| const char * | SpellcheckString (const char *text,...) |
| Like SpellcheckStringV, but takes a NULL-terminated list. More... | |
| const char * | SpellcheckStringV (const string &text, const vector< const char *> &words) |
| Given a misspelled string and a list of correct spellings, returns the closest match or NULL if there is no close enough match. More... | |
| static bool | StringNeedsShellEscaping (const string &input) |
| static bool | StringNeedsWin32Escaping (const string &input) |
| string | StripAnsiEscapeCodes (const string &in) |
| Removes all Ansi escape codes (http://www.termsys.demon.co.uk/vtansi.htm). More... | |
| bool | Truncate (const string &path, size_t size, string *err) |
| Truncates a file to the given size. More... | |
| void | Warning (const char *msg,...) |
| Log a warning message. More... | |
| bool CanonicalizePath | ( | string * | path, |
| uint64_t * | slash_bits, | ||
| string * | err | ||
| ) |
Canonicalize a path like "foo/../bar.h" into just "bar.h".
|slash_bits| has bits set starting from lowest for a backslash that was normalized to a forward slash. (only used on Windows)
Definition at line 93 of file util.cc.
References CanonicalizePath(), and METRIC_RECORD.
Referenced by CanonicalizePath(), Cleaner::CleanTargets(), Builder::ExtractDeps(), ImplicitDepLoader::LoadDepFile(), main(), IncludesNormalize::Normalize(), CLParser::Parse(), ManifestParser::ParseDefault(), ManifestParser::ParseEdge(), and TEST().
| bool CanonicalizePath | ( | char * | path, |
| size_t * | len, | ||
| uint64_t * | slash_bits, | ||
| string * | err | ||
| ) |
Definition at line 113 of file util.cc.
References Fatal(), IsPathSeparator(), METRIC_RECORD, and NINJA_FALLTHROUGH.
| string ElideMiddle | ( | const string & | str, |
| size_t | width | ||
| ) |
Elide the given string str with '...' in the middle if the length exceeds width.
Definition at line 587 of file util.cc.
Referenced by LinePrinter::Print(), and TEST().
| void Error | ( | const char * | msg, |
| ... | |||
| ) |
Log an error message.
Definition at line 84 of file util.cc.
Referenced by Cleaner::CleanRule(), Cleaner::CleanRules(), Cleaner::CleanTarget(), Cleaner::CleanTargets(), Builder::Cleanup(), Cleaner::FileExists(), RealDiskInterface::MakeDir(), DiskInterface::MakeDirs(), RealDiskInterface::RemoveFile(), and RealDiskInterface::WriteFile().
| void Fatal | ( | const char * | msg, |
| ... | |||
| ) |
Log a fatal message and exit.
Definition at line 57 of file util.cc.
Referenced by CanonicalizePath(), CheckNinjaVersion(), ScopedTempDir::Cleanup(), ScopedTempDir::CreateAndEnter(), Builder::ExtractDeps(), Subprocess::Finish(), BuildStatus::FormatProgressStatus(), IncludesNormalize::IncludesNormalize(), EdgeEnv::LookupVariable(), main(), MSVCHelperMain(), Subprocess::OnPipeReady(), CLWrapper::Run(), Subprocess::Start(), SubprocessSet::SubprocessSet(), and SubprocessSet::~SubprocessSet().
| double GetLoadAverage | ( | ) |
Definition at line 576 of file util.cc.
Referenced by RealCommandRunner::CanRunMore().
| int GetProcessorCount | ( | ) |
| void GetShellEscapedString | ( | const string & | input, |
| string * | result | ||
| ) |
Appends |input| to |*result|, escaping according to the whims of either Bash, or Win32's CommandLineToArgvW().
Appends the string directly to |result| without modification if we can determine that it contains no problematic characters.
Definition at line 254 of file util.cc.
References StringNeedsShellEscaping().
Referenced by EdgeEnv::MakePathList(), and TEST().
| void GetWin32EscapedString | ( | const string & | input, |
| string * | result | ||
| ) |
Definition at line 281 of file util.cc.
References StringNeedsWin32Escaping().
Referenced by EdgeEnv::MakePathList(), and TEST().
|
inlinestatic |
Definition at line 213 of file util.cc.
Referenced by StringNeedsShellEscaping().
|
inlinestatic |
Definition at line 230 of file util.cc.
Referenced by StringNeedsWin32Escaping().
| bool islatinalpha | ( | int | c | ) |
Definition at line 454 of file util.cc.
Referenced by StripAnsiEscapeCodes().
|
static |
Definition at line 105 of file util.cc.
Referenced by CanonicalizePath().
| int ReadFile | ( | const string & | path, |
| string * | contents, | ||
| string * | err | ||
| ) |
Read a file to a string (in text mode: with CRLF conversion on Windows).
Returns -errno and fills in err on error.
Definition at line 316 of file util.cc.
References ReadFile().
Referenced by main(), MSVCHelperMain(), ReadFile(), and CLWrapper::Run().
| void SetCloseOnExec | ( | int | fd | ) |
Mark a file descriptor to not be inherited on exec()s.
Definition at line 375 of file util.cc.
Referenced by BuildLog::OpenForWrite(), DepsLog::OpenForWrite(), and Subprocess::Start().
| const char* SpellcheckString | ( | const char * | text, |
| ... | |||
| ) |
Like SpellcheckStringV, but takes a NULL-terminated list.
Definition at line 412 of file util.cc.
References SpellcheckStringV().
| const char* SpellcheckStringV | ( | const string & | text, |
| const vector< const char *> & | words | ||
| ) |
Given a misspelled string and a list of correct spellings, returns the closest match or NULL if there is no close enough match.
Definition at line 393 of file util.cc.
References EditDistance().
Referenced by SpellcheckString().
|
inlinestatic |
Definition at line 240 of file util.cc.
References IsKnownShellSafeCharacter().
Referenced by GetShellEscapedString().
|
inlinestatic |
Definition at line 247 of file util.cc.
References IsKnownWin32SafeCharacter().
Referenced by GetWin32EscapedString().
| string StripAnsiEscapeCodes | ( | const string & | in | ) |
Removes all Ansi escape codes (http://www.termsys.demon.co.uk/vtansi.htm).
Definition at line 459 of file util.cc.
References islatinalpha().
Referenced by BuildStatus::BuildEdgeFinished(), and TEST().
| bool Truncate | ( | const string & | path, |
| size_t | size, | ||
| string * | err | ||
| ) |
Truncates a file to the given size.
Definition at line 599 of file util.cc.
Referenced by DepsLog::Load().
| void Warning | ( | const char * | msg, |
| ... | |||
| ) |
Log a warning message.
Definition at line 75 of file util.cc.
Referenced by CheckNinjaVersion(), DepfileParser::Parse(), and ManifestParser::ParseEdge().
1.8.14