summaryrefslogtreecommitdiff
path: root/lib/sh/strftime.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sh/strftime.c')
-rw-r--r--lib/sh/strftime.c11
1 files changed, 10 insertions, 1 deletions
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;