summaryrefslogtreecommitdiff
path: root/lib/sh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sh')
-rw-r--r--lib/sh/mailstat.c2
-rw-r--r--lib/sh/strftime.c11
-rw-r--r--lib/sh/zcatfd.c6
-rw-r--r--lib/sh/zmapfd.c10
-rw-r--r--lib/sh/zread.c8
5 files changed, 29 insertions, 8 deletions
diff --git a/lib/sh/mailstat.c b/lib/sh/mailstat.c
index 79b431ae..bd5c25fb 100644
--- a/lib/sh/mailstat.c
+++ b/lib/sh/mailstat.c
@@ -60,7 +60,7 @@ mailstat(path, st)
struct stat st_ret, st_tmp;
DIR *dd;
struct dirent *fn;
- char dir[PATH_MAX * 2], file[PATH_MAX * 2];
+ char dir[PATH_MAX * 2], file[PATH_MAX * 2 + 1];
int i, l;
time_t atime, mtime;
diff --git a/lib/sh/strftime.c b/lib/sh/strftime.c
index 0fdcd8c6..08ccb9a3 100644
--- a/lib/sh/strftime.c
+++ b/lib/sh/strftime.c
@@ -62,6 +62,7 @@
#include <stdio.h>
#include <ctype.h>
#include <time.h>
+#include <errno.h>
#if defined(TM_IN_SYS_TIME)
#include <sys/types.h>
@@ -80,6 +81,10 @@
#undef strchr /* avoid AIX weirdness */
+#if !defined (errno)
+extern int errno;
+#endif
+
#if defined (SHELL)
extern char *get_string_value (const char *);
#endif
@@ -172,7 +177,7 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
char *start = s;
auto char tbuf[100];
long off;
- int i, w;
+ int i, w, oerrno;
long y;
static short first = 1;
#ifdef POSIX_SEMANTICS
@@ -217,6 +222,8 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
};
static const char *ampm[] = { "AM", "PM", };
+ oerrno = errno;
+
if (s == NULL || format == NULL || timeptr == NULL || maxsize == 0)
return 0;
@@ -716,6 +723,8 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
out:
if (s < endp && *format == '\0') {
*s = '\0';
+ if (s == start)
+ errno = oerrno;
return (s - start);
} else
return 0;
diff --git a/lib/sh/zcatfd.c b/lib/sh/zcatfd.c
index f9a2322e..aa8199fd 100644
--- a/lib/sh/zcatfd.c
+++ b/lib/sh/zcatfd.c
@@ -34,6 +34,10 @@
extern int errno;
#endif
+#ifndef ZBUFSIZ
+# define ZBUFSIZ 4096
+#endif
+
extern ssize_t zread PARAMS((int, char *, size_t));
extern int zwrite PARAMS((int, char *, ssize_t));
@@ -46,7 +50,7 @@ zcatfd (fd, ofd, fn)
{
ssize_t nr;
int rval;
- char lbuf[1024];
+ char lbuf[ZBUFSIZ];
rval = 0;
while (1)
diff --git a/lib/sh/zmapfd.c b/lib/sh/zmapfd.c
index f3fb8473..f9e9ed71 100644
--- a/lib/sh/zmapfd.c
+++ b/lib/sh/zmapfd.c
@@ -36,6 +36,10 @@
extern int errno;
#endif
+#ifndef ZBUFSIZ
+# define ZBUFSIZ 4096
+#endif
+
extern ssize_t zread PARAMS((int, char *, size_t));
/* Dump contents of file descriptor FD to *OSTR. FN is the filename for
@@ -48,12 +52,12 @@ zmapfd (fd, ostr, fn)
{
ssize_t nr;
int rval;
- char lbuf[512];
+ char lbuf[ZBUFSIZ];
char *result;
int rsize, rind;
rval = 0;
- result = (char *)xmalloc (rsize = 512);
+ result = (char *)xmalloc (rsize = ZBUFSIZ);
rind = 0;
while (1)
@@ -72,7 +76,7 @@ zmapfd (fd, ostr, fn)
return -1;
}
- RESIZE_MALLOCED_BUFFER (result, rind, nr, rsize, 512);
+ RESIZE_MALLOCED_BUFFER (result, rind, nr, rsize, ZBUFSIZ);
memcpy (result+rind, lbuf, nr);
rind += nr;
}
diff --git a/lib/sh/zread.c b/lib/sh/zread.c
index 8dd78102..71a06a76 100644
--- a/lib/sh/zread.c
+++ b/lib/sh/zread.c
@@ -1,6 +1,6 @@
/* zread - read data from file descriptor into buffer with retries */
-/* Copyright (C) 1999-2017 Free Software Foundation, Inc.
+/* Copyright (C) 1999-2020 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -37,6 +37,10 @@ extern int errno;
# define SEEK_CUR 1
#endif
+#ifndef ZBUFSIZ
+# define ZBUFSIZ 4096
+#endif
+
extern int executing_builtin;
extern void check_signals_and_traps (void);
@@ -117,7 +121,7 @@ zreadintr (fd, buf, len)
in read(2). This does some local buffering to avoid many one-character
calls to read(2), like those the `read' builtin performs. */
-static char lbuf[128];
+static char lbuf[ZBUFSIZ];
static size_t lind, lused;
ssize_t