diff options
| author | Karel Klic <kklic@redhat.com> | 2009-11-09 13:55:20 +0100 |
|---|---|---|
| committer | Karel Klic <kklic@redhat.com> | 2009-11-09 13:55:20 +0100 |
| commit | 19f406b4930c931a932dc6930762e8e12e29ce8b (patch) | |
| tree | b08468bf9a010cbce0ecd000a0279222f0d4b4e7 /lib/Utils/xfuncs.cpp | |
| parent | 801ab58f32f2cb7dca3352b721a07c83705a0287 (diff) | |
| parent | 8fa9a6ecd247454ab758efecf818d8067455c778 (diff) | |
| download | abrt-19f406b4930c931a932dc6930762e8e12e29ce8b.tar.gz abrt-19f406b4930c931a932dc6930762e8e12e29ce8b.tar.xz abrt-19f406b4930c931a932dc6930762e8e12e29ce8b.zip | |
merge
Diffstat (limited to 'lib/Utils/xfuncs.cpp')
| -rw-r--r-- | lib/Utils/xfuncs.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/Utils/xfuncs.cpp b/lib/Utils/xfuncs.cpp index d256c19..97c2f76 100644 --- a/lib/Utils/xfuncs.cpp +++ b/lib/Utils/xfuncs.cpp @@ -5,6 +5,22 @@ */ #include "abrtlib.h" +/* Turn on nonblocking I/O on a fd */ +int ndelay_on(int fd) +{ + return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL) | O_NONBLOCK); +} + +int ndelay_off(int fd) +{ + return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL) & ~O_NONBLOCK); +} + +int close_on_exec_on(int fd) +{ + return fcntl(fd, F_SETFD, FD_CLOEXEC); +} + // Die if we can't allocate size bytes of memory. void* xmalloc(size_t size) { @@ -305,3 +321,50 @@ int is_regular_file(struct dirent *dent, const char *dirname) return r == 0 && S_ISREG(statbuf.st_mode); } + +/* Is it "." or ".."? */ +/* abrtlib candidate */ +bool dot_or_dotdot(const char *filename) +{ + if (filename[0] != '.') return false; + if (filename[1] == '\0') return true; + if (filename[1] != '.') return false; + if (filename[2] == '\0') return true; + return false; +} + +/* Find out if the last character of a string matches the one given. + * Don't underrun the buffer if the string length is 0. + */ +char *last_char_is(const char *s, int c) +{ + if (s && *s) { + s += strlen(s) - 1; + if ((unsigned char)*s == c) + return (char*)s; + } + return NULL; +} + +std::string concat_path_file(const char *path, const char *filename) +{ + char *lc; + + while (*filename == '/') + filename++; + lc = last_char_is(path, '/'); + return ssprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename); +} + +bool string_to_bool(const char *s) +{ + if (s[0] == '1' && s[1] == '\0') + return true; + if (strcasecmp(s, "on") == 0) + return true; + if (strcasecmp(s, "yes") == 0) + return true; + if (strcasecmp(s, "true") == 0) + return true; + return false; +} |
