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

static bool ExistsOnPath ( const QCString & fileName)
static

Definition at line 409 of file portable.cpp.

410{
411 FileInfo fi1(fileName.str());
412 if (fi1.exists()) return true;
413
414 QCString paths = Portable::getenv("PATH");
415 char listSep = Portable::pathListSeparator()[0];
416 char pathSep = Portable::pathSeparator()[0];
417 int strt = 0;
418 int idx;
419 while ((idx = paths.find(listSep,strt)) != -1)
420 {
421 QCString locFile(paths.mid(strt,idx-strt));
422 locFile += pathSep;
423 locFile += fileName;
424 FileInfo fi(locFile.str());
425 if (fi.exists()) return true;
426 strt = idx + 1;
427 }
428 // to be sure the last path component is checked as well
429 QCString locFile(paths.mid(strt));
430 if (!locFile.isEmpty())
431 {
432 locFile += pathSep;
433 locFile += fileName;
434 FileInfo fi(locFile.str());
435 if (fi.exists()) return true;
436 }
437 return false;
438}
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:226
const std::string & str() const
Definition qcstring.h:537
QCString pathSeparator()
Definition portable.cpp:391
QCString pathListSeparator()
Definition portable.cpp:400
QCString getenv(const QCString &variable)
Definition portable.cpp:338

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 277 of file portable.cpp.

278{
279 if(environ != nullptr)
280 {
281 unsigned int i = 0;
282 char* current = environ[i];
283
284 while(current != nullptr) // parse all strings contained by environ til the last element (nullptr)
285 {
286 std::string env_var(current); // load current environment variable string
287 size_t pos = env_var.find("=");
288 if(pos != std::string::npos) // only parse the variable, if it is a valid environment variable...
289 { // ...which has to contain an equal sign as delimiter by definition
290 std::string name = env_var.substr(0,pos); // the string til the equal sign contains the name
291 std::string value = env_var.substr(pos + 1); // the string from the equal sign contains the value
292 proc_env[name] = std::move(value); // save the value by the name as its key in the classes map
293 }
294 i++;
295 current = environ[i];
296 }
297 }
298
299 environmentLoaded = true;
300}
static bool environmentLoaded
Definition portable.cpp:38
static std::map< std::string, std::string > proc_env
Definition portable.cpp:39
char ** environ

References environ, environmentLoaded, and proc_env.

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

◆ portable_memmem()

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

Definition at line 589 of file portable.cpp.

591{
592 const char *const last_possible = haystack + haystack_len - needle_len;
593
594 if (needle_len == 0)
595 // The first occurrence of the empty string should to occur at the beginning of the string.
596 {
597 return haystack;
598 }
599
600 // Sanity check
601 if (haystack_len < needle_len)
602 {
603 return nullptr;
604 }
605
606 for (const char *begin = haystack; begin <= last_possible; ++begin)
607 {
608 if (begin[0] == needle[0] && !memcmp(&begin[1], needle + 1, needle_len - 1))
609 {
610 return begin;
611 }
612 }
613
614 return nullptr;
615}
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 38 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