2 #include "lib/stkstring.h"
7 stk_array_len(char **s, uns cnt)
16 stk_array_join(char *x, char **s, uns cnt, uns sep)
31 stk_printf_internal(const char *fmt, ...)
34 char *buf = alloca(len);
40 int l = vsnprintf(buf, len, fmt, args2);
54 stk_vprintf_internal(const char *fmt, va_list args)
57 char *buf = alloca(len);
62 int l = vsnprintf(buf, len, fmt, args2);
76 stk_hexdump_internal(char *dst, const byte *src, uns n)
78 for (uns i=0; i<n; i++)
82 dst += sprintf(dst, "%02x", *src++);
88 stk_fsize_internal(char *buf, u64 x)
91 sprintf(buf, "%dB", (int)x);
93 sprintf(buf, "%.1fK", (double)x/(1<<10));
95 sprintf(buf, "%dK", (int)(x/(1<<10)));
97 sprintf(buf, "%.1fM", (double)x/(1<<20));
99 sprintf(buf, "%dM", (int)(x/(1<<20)));
100 else if (x < (u64)10<<30)
101 sprintf(buf, "%.1fG", (double)x/(1<<30));
102 else if (x != ~(u64)0)
103 sprintf(buf, "%dG", (int)(x/(1<<30)));
105 strcpy(buf, "unknown");
112 char *a = stk_strndup("are!",3);
113 a = stk_strcat(a, " the ");
114 a = stk_strmulticat(a, stk_strdup("Jabberwock, "), "my", NULL);
115 char *arr[] = { a, " son" };
116 a = stk_strarraycat(arr, 2);
117 a = stk_printf("Bew%s!", a);
119 puts(stk_hexdump(a, 3));
120 char *ary[] = { "The", "jaws", "that", "bite" };
121 puts(stk_strjoin(ary, 4, ' '));
122 puts(stk_fsize(1234567));