Doxygen
Loading...
Searching...
No Matches
portable.cpp File Reference
#include "portable.h"
#include "qcstring.h"
#include <stdlib.h>
#include <stdio.h>
#include <chrono>
#include <thread>
#include <mutex>
#include <map>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <assert.h>
#include <ctype.h>
#include <string>
#include "fileinfo.h"
#include "message.h"
#include "util.h"
#include "dir.h"
#include "debug.h"
#include "filesystem.hpp"
Include dependency graph for portable.cpp:

Go to the source code of this file.

Classes

class  SysTimeKeeper
struct  SysTimeKeeper::TimeData
class  AutoTimeKeeper

Functions

void loadEnvironment ()
static bool ExistsOnPath (const QCString &fileName)
static const char * portable_memmem (const char *haystack, size_t haystack_len, const char *needle, size_t needle_len)

Variables

char ** environ
static bool environmentLoaded = false
static std::map< std::string, std::string > proc_env = std::map<std::string,std::string>()

Function Documentation

◆ ExistsOnPath()

bool ExistsOnPath ( const QCString & fileName)
static

Definition at line 392 of file portable.cpp.

393{
394 FileInfo fi1(fileName.str());
395 if (fi1.exists()) return true;
396
397 QCString paths = Portable::getenv("PATH");
398 char listSep = Portable::pathListSeparator()[0];
399 char pathSep = Portable::pathSeparator()[0];
400 int strt = 0;
401 int idx;
402 while ((idx = paths.find(listSep,strt)) != -1)
403 {
404 QCString locFile(paths.mid(strt,idx-strt));
405 locFile += pathSep;
406 locFile += fileName;
407 FileInfo fi(locFile.str());
408 if (fi.exists()) return true;
409 strt = idx + 1;
410 }
411 // to be sure the last path component is checked as well
412 QCString locFile(paths.mid(strt));
413 if (!locFile.isEmpty())
414 {
415 locFile += pathSep;
416 locFile += fileName;
417 FileInfo fi(locFile.str());
418 if (fi.exists()) return true;
419 }
420 return false;
421}
Minimal replacement for QFileInfo.
Definition fileinfo.h:23
This is an alternative implementation of QCString.
Definition qcstring.h:101
int find(char c, int index=0, bool cs=TRUE) const
Definition qcstring.cpp:43
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:241
const std::string & str() const
Definition qcstring.h:552
QCString pathSeparator()
Definition portable.cpp:374
QCString pathListSeparator()
Definition portable.cpp:383
QCString getenv(const QCString &variable)
Definition portable.cpp:321

References FileInfo::exists(), QCString::find(), Portable::getenv(), QCString::isEmpty(), QCString::mid(), Portable::pathListSeparator(), Portable::pathSeparator(), and QCString::str().

Referenced by Portable::checkForExecutable(), and Portable::ghostScriptCommand().

◆ loadEnvironment()

void loadEnvironment ( )

Definition at line 260 of file portable.cpp.

261{
262 if(environ != nullptr)
263 {
264 unsigned int i = 0;
265 char* current = environ[i];
266
267 while(current != nullptr) // parse all strings contained by environ til the last element (nullptr)
268 {
269 std::string env_var(current); // load current environment variable string
270 size_t pos = env_var.find("=");
271 if(pos != std::string::npos) // only parse the variable, if it is a valid environment variable...
272 { // ...which has to contain an equal sign as delimiter by definition
273 std::string name = env_var.substr(0,pos); // the string til the equal sign contains the name
274 std::string value = env_var.substr(pos + 1); // the string from the equal sign contains the value
275 proc_env[name] = std::move(value); // save the value by the name as its key in the classes map
276 }
277 i++;
278 current = environ[i];
279 }
280 }
281
282 environmentLoaded = true;
283}
static bool environmentLoaded
Definition portable.cpp:37
static std::map< std::string, std::string > proc_env
Definition portable.cpp:38
char ** environ

References environ, environmentLoaded, and proc_env.

Referenced by Portable::getenv(), and Portable::setenv().

◆ portable_memmem()

const char * portable_memmem ( const char * haystack,
size_t haystack_len,
const char * needle,
size_t needle_len )
static

Definition at line 572 of file portable.cpp.

574{
575 const char *const last_possible = haystack + haystack_len - needle_len;
576
577 if (needle_len == 0)
578 // The first occurrence of the empty string should to occur at the beginning of the string.
579 {
580 return haystack;
581 }
582
583 // Sanity check
584 if (haystack_len < needle_len)
585 {
586 return nullptr;
587 }
588
589 for (const char *begin = haystack; begin <= last_possible; ++begin)
590 {
591 if (begin[0] == needle[0] && !memcmp(&begin[1], needle + 1, needle_len - 1))
592 {
593 return begin;
594 }
595 }
596
597 return nullptr;
598}
DirIterator begin(DirIterator it) noexcept
Definition dir.cpp:170

References begin().

Referenced by Portable::strnstr().

Variable Documentation

◆ environ

char** environ
extern

◆ environmentLoaded

bool environmentLoaded = false
static

Definition at line 37 of file portable.cpp.

Referenced by Portable::getenv(), loadEnvironment(), and Portable::setenv().

◆ proc_env

std::map<std::string,std::string> proc_env = std::map<std::string,std::string>()
static