Ninja
Macros | Functions
util.h File Reference
#include <stdint.h>
#include <stdarg.h>
#include <string>
#include <vector>
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __has_cpp_attribute(x)   0
 
#define NINJA_FALLTHROUGH
 
#define NORETURN
 

Functions

void CanonicalizePath (char *path, size_t *len, uint64_t *slash_bits)
 
void CanonicalizePath (std::string *path, uint64_t *slash_bits)
 Canonicalize a path like "foo/../bar.h" into just "bar.h". More...
 
void Error (const char *msg, va_list ap)
 
void Error (const char *msg,...)
 Log an error message. More...
 
NORETURN void Fatal (const char *msg,...)
 Log a fatal message and exit. More...
 
double GetLoadAverage ()
 
int GetProcessorCount ()
 
void GetShellEscapedString (const std::string &input, std::string *result)
 Appends |input| to |*result|, escaping according to the whims of either Bash, or Win32's CommandLineToArgvW(). More...
 
void GetWin32EscapedString (const std::string &input, std::string *result)
 
std::string GetWorkingDirectory ()
 a wrapper for getcwd() More...
 
void Info (const char *msg, va_list ap)
 
void Info (const char *msg,...)
 Log an informational message. More...
 
bool islatinalpha (int c)
 
int platformAwareUnlink (const char *filename)
 
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). 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 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 is no close enough match. More...
 
std::string StripAnsiEscapeCodes (const std::string &in)
 Removes all Ansi escape codes (http://www.termsys.demon.co.uk/vtansi.htm). More...
 
bool Truncate (const std::string &path, size_t size, std::string *err)
 Truncates a file to the given size. More...
 
void Warning (const char *msg, va_list ap)
 
void Warning (const char *msg,...)
 Log a warning message. More...
 

Macro Definition Documentation

◆ __has_cpp_attribute

#define __has_cpp_attribute (   x)    0

Definition at line 30 of file util.h.

◆ NINJA_FALLTHROUGH

#define NINJA_FALLTHROUGH

Definition at line 48 of file util.h.

◆ NORETURN

#define NORETURN

Definition at line 36 of file util.h.

Function Documentation

◆ CanonicalizePath() [1/2]

void CanonicalizePath ( char *  path,
size_t *  len,
uint64_t slash_bits 
)

Definition at line 141 of file util.cc.

References IsPathSeparator(), and NINJA_FALLTHROUGH.

◆ CanonicalizePath() [2/2]

void CanonicalizePath ( std::string *  path,
uint64_t slash_bits 
)

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)

◆ Error() [1/2]

void Error ( const char *  msg,
va_list  ap 
)

◆ Error() [2/2]

void Error ( const char *  msg,
  ... 
)

Log an error message.

Definition at line 104 of file util.cc.

References Error().

◆ Fatal()

NORETURN void Fatal ( const char *  msg,
  ... 
)

◆ GetLoadAverage()

double GetLoadAverage ( )
Returns
the load average of the machine. A negative value is returned on error.

Definition at line 981 of file util.cc.

Referenced by RealCommandRunner::CanRunMore().

◆ GetProcessorCount()

int GetProcessorCount ( )
Returns
the number of processors on the machine. Useful for an initial guess for how many jobs to run in parallel.
0 on error.

Definition at line 814 of file util.cc.

◆ GetShellEscapedString()

void GetShellEscapedString ( const std::string &  input,
std::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.

◆ GetWin32EscapedString()

void GetWin32EscapedString ( const std::string &  input,
std::string *  result 
)

◆ GetWorkingDirectory()

std::string GetWorkingDirectory ( )

a wrapper for getcwd()

Definition at line 992 of file util.cc.

References Fatal().

◆ Info() [1/2]

void Info ( const char *  msg,
va_list  ap 
)

Definition at line 111 of file util.cc.

Referenced by Info().

◆ Info() [2/2]

void Info ( const char *  msg,
  ... 
)

Log an informational message.

Definition at line 117 of file util.cc.

References Info().

◆ islatinalpha()

bool islatinalpha ( int  c)

Definition at line 566 of file util.cc.

Referenced by StripAnsiEscapeCodes().

◆ platformAwareUnlink()

int platformAwareUnlink ( const char *  filename)

◆ ReadFile()

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).

Returns -errno and fills in err on error.

◆ SetCloseOnExec()

void SetCloseOnExec ( int  fd)

Mark a file descriptor to not be inherited on exec()s.

Definition at line 480 of file util.cc.

Referenced by BuildLog::OpenForWriteIfNeeded(), DepsLog::OpenForWriteIfNeeded(), and Subprocess::Start().

◆ SpellcheckString()

const char* SpellcheckString ( const char *  text,
  ... 
)

Like SpellcheckStringV, but takes a NULL-terminated list.

Definition at line 517 of file util.cc.

References SpellcheckStringV().

◆ SpellcheckStringV()

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 is no close enough match.

◆ StripAnsiEscapeCodes()

std::string StripAnsiEscapeCodes ( const std::string &  in)

Removes all Ansi escape codes (http://www.termsys.demon.co.uk/vtansi.htm).

◆ Truncate()

bool Truncate ( const std::string &  path,
size_t  size,
std::string *  err 
)

Truncates a file to the given size.

◆ Warning() [1/2]

void Warning ( const char *  msg,
va_list  ap 
)

Definition at line 85 of file util.cc.

Referenced by GraphViz::AddTarget(), CheckNinjaVersion(), ManifestParser::ParseEdge(), and Warning().

◆ Warning() [2/2]

void Warning ( const char *  msg,
  ... 
)

Log a warning message.

Definition at line 91 of file util.cc.

References Warning().