lpack.c (815B)
1 #include <stdarg.h> 2 3 #include "../../inc/scc.h" 4 5 int 6 lpack(unsigned char *dst, char *fmt, ...) 7 { 8 unsigned char *bp; 9 unsigned s; 10 unsigned long l; 11 unsigned long long q; 12 va_list va; 13 14 bp = dst; 15 va_start(va, fmt); 16 while (*fmt) { 17 switch (*fmt++) { 18 case 'c': 19 *bp++ = va_arg(va, unsigned); 20 break; 21 case 's': 22 s = va_arg(va, unsigned); 23 *bp++ = s >> 8; 24 *bp++ = s; 25 break; 26 case 'l': 27 l = va_arg(va, unsigned long); 28 *bp++ = l >> 24; 29 *bp++ = l >> 16; 30 *bp++ = l >> 8; 31 *bp++ = l; 32 break; 33 case 'q': 34 q = va_arg(va, unsigned long long); 35 *bp++ = q >> 56; 36 *bp++ = q >> 48; 37 *bp++ = q >> 40; 38 *bp++ = q >> 32; 39 *bp++ = q >> 24; 40 *bp++ = q >> 16; 41 *bp++ = q >> 8; 42 *bp++ = q; 43 break; 44 default: 45 va_end(va); 46 return -1; 47 } 48 } 49 va_end(va); 50 51 return bp - dst; 52 }