summaryrefslogtreecommitdiffstats
path: root/strftime.c
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-24 14:01:47 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-24 14:01:47 +0000
commitfbce50fa8028b5f2180dd74a3be4683ddc4d2c65 (patch)
tree0b4ad6370e2f1d50b613dfb1afd0dccbd55ccc9c /strftime.c
parent86ff9dda4781c853c80f7ea239f33a021d368726 (diff)
downloadruby-fbce50fa8028b5f2180dd74a3be4683ddc4d2c65.tar.gz
ruby-fbce50fa8028b5f2180dd74a3be4683ddc4d2c65.tar.xz
ruby-fbce50fa8028b5f2180dd74a3be4683ddc4d2c65.zip
* strftime.c (rb_strftime): A width specifier for %t and %n should
work. [ruby-dev:37160] * test/ruby/test_time.rb (test_strftime): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@20340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'strftime.c')
-rw-r--r--strftime.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/strftime.c b/strftime.c
index 2c98164c0..3a88208b1 100644
--- a/strftime.c
+++ b/strftime.c
@@ -270,6 +270,16 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct tm *timept
goto unknown; \
} while (0)
#define NEEDS(n) do if (s + (n) >= endp - 1) goto err; while (0)
+#define FILL_PADDING(i) do { \
+ if (!(flags & BIT_OF(LEFT)) && precision > i) { \
+ NEEDS(precision); \
+ memset(s, padding ? padding : ' ', precision - i); \
+ s += precision - i; \
+ } \
+ else { \
+ NEEDS(i); \
+ } \
+} while (0);
#define FMT(def_pad, def_prec, fmt, val) \
do { \
int l; \
@@ -540,12 +550,12 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct tm *timept
#ifdef SYSV_EXT
case 'n': /* same as \n */
- NEEDS(1);
+ FILL_PADDING(1);
*s++ = '\n';
continue;
case 't': /* same as \t */
- NEEDS(1);
+ FILL_PADDING(1);
*s++ = '\t';
continue;
@@ -741,14 +751,7 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct tm *timept
break;
}
if (i) {
- if (!(flags & BIT_OF(LEFT)) && precision > i) {
- NEEDS(precision);
- memset(s, padding ? padding : ' ', precision - i);
- s += precision - i;
- }
- else {
- NEEDS(i);
- }
+ FILL_PADDING(i);
memcpy(s, tp, i);
switch (flags & (BIT_OF(UPPER)|BIT_OF(LOWER))) {
case BIT_OF(UPPER):