** Pack integer 'n' with 'size' bytes and 'islittle' endianness. ** The final 'if' handles the case when 'size' is larger than ** the size of a Lua integer, correcting the extra sign-extension ** bytes if necessary (by default they would be zeros). */
| 1300 | ** bytes if necessary (by default they would be zeros). |
| 1301 | */ |
| 1302 | static void packint (luaL_Buffer *b, lua_Unsigned n, |
| 1303 | int islittle, int size, int neg) { |
| 1304 | char *buff = luaL_prepbuffsize(b, size); |
| 1305 | int i; |
| 1306 | buff[islittle ? 0 : size - 1] = (char)(n & MC); /* first byte */ |
| 1307 | for (i = 1; i < size; i++) { |
| 1308 | n >>= NB; |
| 1309 | buff[islittle ? i : size - 1 - i] = (char)(n & MC); |
| 1310 | } |
| 1311 | if (neg && size > SZINT) { /* negative number need sign extension? */ |
| 1312 | for (i = SZINT; i < size; i++) /* correct extra bytes */ |
| 1313 | buff[islittle ? i : size - 1 - i] = (char)MC; |
| 1314 | } |
| 1315 | luaL_addsize(b, size); /* add result to buffer */ |
| 1316 | } |
| 1317 | |
| 1318 | |
| 1319 | /* |
no test coverage detected