summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2011-04-06 11:03:12 +0200
committerJiri Moskovcak <jmoskovc@redhat.com>2011-04-06 11:03:12 +0200
commite46ab2a95aabe30fc043531fddbda16118e2888d (patch)
tree084b940e0e8159a176e421de340b969a4c1d8c2e /src/lib
parent04cc4f8c63a635bcdbce4d887e7c6b3483e6f141 (diff)
parent2cc15eb689fa8690f652ea6db34cb2d40d0cc2cc (diff)
downloadabrt-e46ab2a95aabe30fc043531fddbda16118e2888d.tar.gz
abrt-e46ab2a95aabe30fc043531fddbda16118e2888d.tar.xz
abrt-e46ab2a95aabe30fc043531fddbda16118e2888d.zip
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/copy_file_recursive.c10
-rw-r--r--src/lib/strbuf.c23
2 files changed, 33 insertions, 0 deletions
diff --git a/src/lib/copy_file_recursive.c b/src/lib/copy_file_recursive.c
index c3f021c7..48108a1d 100644
--- a/src/lib/copy_file_recursive.c
+++ b/src/lib/copy_file_recursive.c
@@ -126,6 +126,16 @@ int copy_file_recursive(const char *source, const char *dest)
if (close(dst_fd) < 0) {
perror_msg("Error writing to '%s'", dest);
retval = -1;
+ } else {
+ /* (Try to) copy atime and mtime */
+ struct timeval atime_mtime[2];
+ atime_mtime[0].tv_sec = source_stat.st_atime;
+ // note: if "st_atim.tv_nsec" doesn't compile, try "st_atimensec":
+ atime_mtime[0].tv_usec = source_stat.st_atim.tv_nsec / 1000;
+ atime_mtime[1].tv_sec = source_stat.st_mtime;
+ atime_mtime[1].tv_usec = source_stat.st_mtim.tv_nsec / 1000;
+ // note: can use utimensat when it is more widely supported:
+ utimes(dest, atime_mtime);
}
goto ret;
}
diff --git a/src/lib/strbuf.c b/src/lib/strbuf.c
index f56815a0..572f11cc 100644
--- a/src/lib/strbuf.c
+++ b/src/lib/strbuf.c
@@ -37,6 +37,29 @@ int suffixcmp(const char *str, const char *suffix)
return strcmp(str + len_minus_suflen, suffix);
}
+/*
+ * Trims whitespace characters both from left and right side of a string.
+ * Modifies the string in-place. Returns the trimmed string.
+ */
+char *strtrim(char *str)
+{
+ if (!str)
+ return NULL;
+
+ // Remove leading spaces.
+ overlapping_strcpy(str, skip_whitespace(str));
+
+ // Remove trailing spaces.
+ int i = strlen(str);
+ while (--i >= 0)
+ {
+ if (!isspace(str[i]))
+ break;
+ }
+ str[++i] = '\0';
+ return str;
+}
+
struct strbuf *strbuf_new(void)
{
struct strbuf *buf = xzalloc(sizeof(*buf));