X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Fos.hpp;h=91c819fca55f09a516a746d23283bd0ab81766de;hb=e51e22f4dbeb0851521b68eca1ac4f42f57f5d2c;hp=b97f33070ed5387da0fcdce43a4e0f7a31afbedc;hpb=22c30268664781adae88534fe5e91c10eb58e916;p=apitrace diff --git a/common/os.hpp b/common/os.hpp index b97f330..91c819f 100644 --- a/common/os.hpp +++ b/common/os.hpp @@ -30,14 +30,11 @@ #ifndef _OS_HPP_ #define _OS_HPP_ -#include #include #include #include #include -#include - #ifdef _WIN32 #ifndef snprintf #define snprintf _snprintf @@ -45,108 +42,13 @@ #ifndef vsnprintf #define vsnprintf _vsnprintf #endif -#define PATH_SEP '\\' -#else /* !_WIN32 */ -#define PATH_SEP '/' -#endif /* !_WIN32 */ - -#ifndef PATH_MAX -#define PATH_MAX 1024 +#ifndef strcasecmp +#define strcasecmp stricmp #endif +#endif /* !_WIN32 */ namespace os { -void acquireMutex(void); - -void releaseMutex(void); - - -class Path { -protected: - typedef std::vector Buffer; - Buffer buffer; - - Buffer::iterator rfind(char c) { - Buffer::iterator it = buffer.end(); - while (it != buffer.begin()) { - --it; - if (*it == c) { - return it; - } - } - return buffer.end(); - } - -public: - Path() { - buffer.push_back(0); - } - - Path(const char *s) : - buffer(s, s + strlen(s) + 1) - {} - - template - Path(InputIterator first, InputIterator last) : - buffer(first, last) - { - buffer.push_back(0); - } - - char *buf(size_t size) { - buffer.resize(size); - return &buffer[0]; - } - - void trimDirectory(void) { - Buffer::iterator sep = rfind(PATH_SEP); - if (sep != buffer.end()) { - buffer.erase(buffer.begin(), sep + 1); - } - } - - void trimExtension(void) { - Buffer::iterator dot = rfind('.'); - if (dot != buffer.end()) { - buffer.erase(dot, buffer.end()); - } - } - - size_t length(void) const { - size_t size = buffer.size(); - assert(size > 0); - assert(buffer[size - 1] == 0); - return size - 1; - } - - void truncate(size_t length) { - assert(length < buffer.size()); - buffer[length] = 0; - buffer.resize(length + 1); - } - - void truncate(void) { - truncate(strlen(str())); - } - - const char *str(void) const { - assert(buffer[buffer.size() - 1] == 0); - return &buffer[0]; - } - - void join(const Path & other) { - size_t len = length(); - if (len > 0 && buffer[len - 1] != PATH_SEP) { - buffer.insert(buffer.begin() + len++, PATH_SEP); - } - buffer.insert(buffer.begin() + len, other.buffer.begin(), other.buffer.end() - 1); - } - -}; - -Path getProcessName(); -Path getCurrentDir(); - void log(const char *format, ...) #ifdef __GNUC__ __attribute__ ((format (printf, 1, 2))) @@ -171,11 +73,6 @@ void log(const char *format, ...) #endif #endif -/** - * Get the current time in microseconds from an unknown base. - */ -long long getTime(void); - void abort(void); void setExceptionCallback(void (*callback)(void));