summaryrefslogtreecommitdiff
path: root/e2fsck/logfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'e2fsck/logfile.c')
-rw-r--r--e2fsck/logfile.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/e2fsck/logfile.c b/e2fsck/logfile.c
index 76ae52d1..c48b8eb8 100644
--- a/e2fsck/logfile.c
+++ b/e2fsck/logfile.c
@@ -13,6 +13,9 @@
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include "e2fsck.h"
#include <pwd.h>
@@ -33,19 +36,25 @@ static void alloc_string(struct string *s, int len)
static void append_string(struct string *s, const char *a, int len)
{
+ int needlen;
+
if (!len)
len = strlen(a);
- if (s->end + len >= s->len) {
- char *n = realloc(s, s->len * 2);
+ needlen = s->end + len + 1;
+ if (needlen > s->len) {
+ char *n;
+
+ if (s->len * 2 > needlen)
+ needlen = s->len * 2;
+ n = realloc(s->s, needlen);
if (n) {
s->s = n;
- s->len = s->len * 2;
+ s->len = needlen;
} else {
- len = s->len - s->end - 1;
- if (len <= 0)
- return;
+ /* Don't append if we ran out of memory */
+ return;
}
}
memcpy(s->s + s->end, a, len);
@@ -126,7 +135,11 @@ static void expand_percent_expression(e2fsck_t ctx, char ch,
strcpy(buf, "tytso");
break;
#else
+#ifdef HAVE_GETPWUID_R
getpwuid_r(getuid(), &pw_struct, buf, sizeof(buf), &pw);
+#else
+ pw = getpwuid(getuid());
+#endif
if (pw)
append_string(s, pw->pw_name, 0);
return;