about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-02-28 15:59:01 -0500
committerRich Felker <dalias@aerifal.cx>2012-02-28 15:59:01 -0500
commit95b930ad2646bb733ca9330ab3b990570e7ff9c6 (patch)
treec65e2296a970f948502f7431a21f01738f2fda52 /src
parentb1a8e0d45465731a757ef476cf6a5cbd31d166f9 (diff)
downloadmusl-95b930ad2646bb733ca9330ab3b990570e7ff9c6.tar.gz
musl-95b930ad2646bb733ca9330ab3b990570e7ff9c6.tar.xz
musl-95b930ad2646bb733ca9330ab3b990570e7ff9c6.zip
implement wcsftime function
Diffstat (limited to 'src')
-rw-r--r--src/time/wcsftime.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/time/wcsftime.c b/src/time/wcsftime.c
new file mode 100644
index 00000000..7db76922
--- /dev/null
+++ b/src/time/wcsftime.c
@@ -0,0 +1,32 @@
+#include <wchar.h>
+#include <time.h>
+#include <string.h>
+
+size_t wcsftime(wchar_t *wcs, size_t n, const wchar_t *f, const struct tm *tm)
+{
+	size_t k, n0=n;
+	char out[100], in[4];
+	while (*f) {
+		if (!n) return 0;
+		if (*f != '%') {
+			*wcs++ = *f++;
+			n--;
+			continue;
+		}
+		in[2] = in[3] = 0;
+		in[0] = *f++;
+		if (strchr("EO", (in[1]=*f++)))
+			in[2] = *f++;
+		k = strftime(out, sizeof out, in, tm);
+		if (!k) return 0;
+		k = mbsrtowcs(wcs, (const char *[]){out}, n, 0);
+		if (k==(size_t)-1) return 0;
+		wcs += k;
+		n -= k;
+	}
+	if (!n) return 0;
+	*wcs++ = 0;
+	return n0-n;
+}
+
+