Ninja
Functions
util.cc File Reference
#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"
Include dependency graph for util.cc:

Go to the source code of this file.

Functions

bool CanonicalizePath (string *path, uint64_t *slash_bits, string *err)
 
bool CanonicalizePath (char *path, size_t *len, uint64_t *slash_bits, string *err)
 
string ElideMiddle (const string &str, size_t width)
 
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)
 
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)
 
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)
 
static bool StringNeedsShellEscaping (const string &input)
 
static bool StringNeedsWin32Escaping (const string &input)
 
string StripAnsiEscapeCodes (const string &in)
 
bool Truncate (const string &path, size_t size, string *err)
 
void Warning (const char *msg,...)
 Log a warning message. More...
 

Function Documentation

◆ CanonicalizePath() [1/2]

bool CanonicalizePath ( string *  path,
uint64_t slash_bits,
string *  err 
)

◆ CanonicalizePath() [2/2]

bool CanonicalizePath ( char *  path,
size_t *  len,
uint64_t slash_bits,
string *  err 
)

Definition at line 115 of file util.cc.

References Fatal(), IsPathSeparator(), METRIC_RECORD, and NINJA_FALLTHROUGH.

◆ ElideMiddle()

string ElideMiddle ( const string &  str,
size_t  width 
)

Definition at line 600 of file util.cc.

Referenced by LinePrinter::Print(), and TEST().

◆ Error()

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

◆ Fatal()

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 589 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 484 of file util.cc.

◆ GetShellEscapedString()

void GetShellEscapedString ( const string &  input,
string *  result 
)

Definition at line 256 of file util.cc.

References StringNeedsShellEscaping().

Referenced by EdgeEnv::MakePathList(), and TEST().

◆ GetWin32EscapedString()

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

Definition at line 283 of file util.cc.

References StringNeedsWin32Escaping().

Referenced by EdgeEnv::MakePathList(), and TEST().

◆ IsKnownShellSafeCharacter()

static bool IsKnownShellSafeCharacter ( char  ch)
inlinestatic

Definition at line 215 of file util.cc.

Referenced by StringNeedsShellEscaping().

◆ IsKnownWin32SafeCharacter()

static bool IsKnownWin32SafeCharacter ( char  ch)
inlinestatic

Definition at line 232 of file util.cc.

Referenced by StringNeedsWin32Escaping().

◆ islatinalpha()

bool islatinalpha ( int  c)

Definition at line 456 of file util.cc.

Referenced by StripAnsiEscapeCodes().

◆ IsPathSeparator()

static bool IsPathSeparator ( char  c)
static

Definition at line 107 of file util.cc.

Referenced by CanonicalizePath().

◆ ReadFile()

int ReadFile ( const string &  path,
string *  contents,
string *  err 
)

Definition at line 318 of file util.cc.

Referenced by main(), MSVCHelperMain(), RealDiskInterface::ReadFile(), and CLWrapper::Run().

◆ SetCloseOnExec()

void SetCloseOnExec ( int  fd)

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

Definition at line 377 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 414 of file util.cc.

References SpellcheckStringV().

◆ SpellcheckStringV()

const char* SpellcheckStringV ( const string &  text,
const vector< const char *> &  words 
)

Definition at line 395 of file util.cc.

References EditDistance().

Referenced by SpellcheckString().

◆ StringNeedsShellEscaping()

static bool StringNeedsShellEscaping ( const string &  input)
inlinestatic

Definition at line 242 of file util.cc.

References IsKnownShellSafeCharacter().

Referenced by GetShellEscapedString().

◆ StringNeedsWin32Escaping()

static bool StringNeedsWin32Escaping ( const string &  input)
inlinestatic

Definition at line 249 of file util.cc.

References IsKnownWin32SafeCharacter().

Referenced by GetWin32EscapedString().

◆ StripAnsiEscapeCodes()

string StripAnsiEscapeCodes ( const string &  in)

Definition at line 461 of file util.cc.

References islatinalpha().

Referenced by BuildStatus::BuildEdgeFinished(), and TEST().

◆ Truncate()

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

Definition at line 618 of file util.cc.

Referenced by DepsLog::Load().

◆ Warning()

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

Log a warning message.

Definition at line 77 of file util.cc.

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