aboutsummaryrefslogtreecommitdiff
path: root/liolib.c
diff options
context:
space:
mode:
Diffstat (limited to 'liolib.c')
-rw-r--r--liolib.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/liolib.c b/liolib.c
index 17522bb2..98ff3d0d 100644
--- a/liolib.c
+++ b/liolib.c
@@ -665,20 +665,16 @@ static int g_write (lua_State *L, FILE *f, int arg) {
665 int status = 1; 665 int status = 1;
666 errno = 0; 666 errno = 0;
667 for (; nargs--; arg++) { 667 for (; nargs--; arg++) {
668 if (lua_type(L, arg) == LUA_TNUMBER) { 668 char buff[LUA_N2SBUFFSZ];
669 /* optimization: could be done exactly as for strings */ 669 const char *s;
670 int len = lua_isinteger(L, arg) 670 size_t len = lua_numbertostrbuff(L, arg, buff); /* try as a number */
671 ? fprintf(f, LUA_INTEGER_FMT, 671 if (len > 0) { /* did conversion work (value was a number)? */
672 (LUAI_UACINT)lua_tointeger(L, arg)) 672 s = buff;
673 : fprintf(f, LUA_NUMBER_FMT, 673 len--;
674 (LUAI_UACNUMBER)lua_tonumber(L, arg));
675 status = status && (len > 0);
676 }
677 else {
678 size_t l;
679 const char *s = luaL_checklstring(L, arg, &l);
680 status = status && (fwrite(s, sizeof(char), l, f) == l);
681 } 674 }
675 else /* must be a string */
676 s = luaL_checklstring(L, arg, &len);
677 status = status && (fwrite(s, sizeof(char), len, f) == len);
682 } 678 }
683 if (l_likely(status)) 679 if (l_likely(status))
684 return 1; /* file handle already on stack top */ 680 return 1; /* file handle already on stack top */