Skip to main content

The portable.cpp File Reference

Included Headers

#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"

Classes Index

classSysTimeKeeper
structTimeData
classAutoTimeKeeper

Functions Index

voidloadEnvironment ()
static boolExistsOnPath (const QCString &fileName)
static const char *portable_memmem (const char *haystack, size_t haystack_len, const char *needle, size_t needle_len)

Variables Index

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

Functions

ExistsOnPath()

bool ExistsOnPath (const QCString & fileName)
static

Definition at line 409 of file portable.cpp.

409static bool ExistsOnPath(const QCString &fileName)
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}

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}

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

589static const char * portable_memmem (const char *haystack, size_t haystack_len,
590 const char *needle, size_t needle_len)
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}

Reference begin.

Referenced by Portable::strnstr.

Variables

environ

char** environ

Definition at line 20 of file portable.cpp.

Referenced by loadEnvironment and Portable::system.

environmentLoaded

bool environmentLoaded = false
static

Definition at line 38 of file portable.cpp.

38static bool environmentLoaded = false;

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

Definition at line 39 of file portable.cpp.

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

Referenced by Portable::getenv, loadEnvironment, Portable::setenv and Portable::unsetenv.


Generated via doxygen2docusaurus by Doxygen 1.14.0.