aboutsummaryrefslogtreecommitdiff
path: root/lstrlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lstrlib.c')
-rw-r--r--lstrlib.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 25569085..3da669d7 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.188 2014/03/21 13:52:33 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.189 2014/03/21 14:26:44 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -975,7 +975,7 @@ static int getendian (lua_State *L, int arg) {
975 if (*endian == 'n') /* native? */ 975 if (*endian == 'n') /* native? */
976 return nativeendian.little; 976 return nativeendian.little;
977 luaL_argcheck(L, *endian == 'l' || *endian == 'b', arg, 977 luaL_argcheck(L, *endian == 'l' || *endian == 'b', arg,
978 "endianess must be 'l'/'b'/'n'"); 978 "endianness must be 'l'/'b'/'n'");
979 return (*endian == 'l'); 979 return (*endian == 'l');
980} 980}
981 981
@@ -1075,9 +1075,9 @@ static int unpackint_l (lua_State *L) {
1075} 1075}
1076 1076
1077 1077
1078static void correctendianess (lua_State *L, char *b, int size, int endianarg) { 1078static void correctendianness (lua_State *L, char *b, int size, int endianarg) {
1079 int endian = getendian(L, endianarg); 1079 int endian = getendian(L, endianarg);
1080 if (endian != nativeendian.little) { /* not native endianess? */ 1080 if (endian != nativeendian.little) { /* not native endianness? */
1081 int i = 0; 1081 int i = 0;
1082 while (i < --size) { 1082 while (i < --size) {
1083 char temp = b[i]; 1083 char temp = b[i];
@@ -1113,7 +1113,7 @@ static int packfloat_l (lua_State *L) {
1113 d = (double)n; 1113 d = (double)n;
1114 pn = (char*)&d; 1114 pn = (char*)&d;
1115 } 1115 }
1116 correctendianess(L, pn, size, 3); 1116 correctendianness(L, pn, size, 3);
1117 lua_pushlstring(L, pn, size); 1117 lua_pushlstring(L, pn, size);
1118 return 1; 1118 return 1;
1119} 1119}
@@ -1129,19 +1129,19 @@ static int unpackfloat_l (lua_State *L) {
1129 "string too short"); 1129 "string too short");
1130 if (size == sizeof(lua_Number)) { 1130 if (size == sizeof(lua_Number)) {
1131 memcpy(&res, s + pos - 1, size); 1131 memcpy(&res, s + pos - 1, size);
1132 correctendianess(L, (char*)&res, size, 4); 1132 correctendianness(L, (char*)&res, size, 4);
1133 } 1133 }
1134 else if (size == sizeof(float)) { 1134 else if (size == sizeof(float)) {
1135 float f; 1135 float f;
1136 memcpy(&f, s + pos - 1, size); 1136 memcpy(&f, s + pos - 1, size);
1137 correctendianess(L, (char*)&f, size, 4); 1137 correctendianness(L, (char*)&f, size, 4);
1138 res = (lua_Number)f; 1138 res = (lua_Number)f;
1139 } 1139 }
1140 else { /* native lua_Number may be neither float nor double */ 1140 else { /* native lua_Number may be neither float nor double */
1141 double d; 1141 double d;
1142 lua_assert(size == sizeof(double)); 1142 lua_assert(size == sizeof(double));
1143 memcpy(&d, s + pos - 1, size); 1143 memcpy(&d, s + pos - 1, size);
1144 correctendianess(L, (char*)&d, size, 4); 1144 correctendianness(L, (char*)&d, size, 4);
1145 res = (lua_Number)d; 1145 res = (lua_Number)d;
1146 } 1146 }
1147 lua_pushnumber(L, res); 1147 lua_pushnumber(L, res);