1 module stb.binding;
2 
3 import core.stdc.stdarg;
4 import core.stdc.stdio : FILE;
5 
6 
7 auto stb_arrhead(T)(T** a)
8 {
9 	return cast(stb__arr*)a - 1;
10 }
11 
12 extern(C) @nogc nothrow:
13 
14 alias time_t = ulong;
15 
16 alias stb_compare_func = int function(void* a, void* b);
17 alias stb_hash_func = int function(void* a, uint seed);
18 alias stb_thread_func = void* function(void*);
19 
20 alias stb_bitset = uint;
21 
22 alias stb_sync = void*;
23 alias stb_mutex = void*;
24 alias stb_thread = void*;
25 alias stb_semaphore = void*;
26 
27 struct stb_ps;
28 struct stb_cfg;
29 struct stb_idict;
30 struct stb_sdict;
31 struct stb_ptrmap;
32 struct stb_matcher;
33 struct stb_spmatrix;
34 struct stb_workqueue;
35 struct stb_threadqueue;
36 
37 struct stb_search
38 {
39 	int minval, maxval, guess;
40 	int mode, step;
41 }
42 
43 struct stb__arr
44 {
45 	int len, limit;
46 	int stb_malloc;
47 	uint signature;
48 }
49 
50 struct stb_perfect
51 {
52 	uint addend;
53 	uint multiplicand;
54 	uint b_mask;
55 	ubyte[16] small_bmap;
56 	ushort* large_bmap;
57 	uint table_mask;
58 	uint* table;
59 }
60 
61 struct stb_dirtree2
62 {
63 	stb_dirtree2** subdirs;
64 	int num_subdir;
65 	float weight;
66 	char* fullpath;
67 	char* relpath;
68 	char** files;
69 }
70 
71 struct stb_dirtree_dir
72 {
73 	char* path;
74 	time_t last_modified;
75 	int num_files;
76 	int flag;
77 }
78 
79 struct stb_dirtree_file
80 {
81 	char* name;
82 	int dir;
83 	long size;
84 	time_t last_modified;
85 	int flag;
86 }
87 
88 struct stb_dirtree
89 {
90 	stb_dirtree_dir* dirs;
91 	stb_dirtree_file* files;
92 	void* string_pool;
93 }
94 
95 struct stb_dupe
96 {
97 	void*** hash_table;
98 	int hash_size;
99 	int size_log2;
100 	int population;
101 	int hash_shift;
102 	stb_hash_func hash;
103 	stb_compare_func eq;
104 	stb_compare_func ineq;
105 	void*** dupes;
106 }
107 
108 struct stbfile
109 {
110 	int function(stbfile*) getbyte;
111 	uint function(stbfile*, void* block, uint len) getdata;
112 
113 	int function(stbfile*, int byte_) putbyte;
114 	uint function(stbfile*, void* block, uint len) putdata;
115 
116 	uint function(stbfile*) size;
117 
118 	uint function(stbfile*) tell;
119 	void function(stbfile*, uint tell, void* block, uint len) backpatch;
120 
121 	void function(stbfile*) close;
122 
123 	FILE* f;
124 	ubyte* buffer;
125 	ubyte* indata, inend;
126 
127 	union
128 	{
129 		int various;
130 		void* ptr;
131 	}
132 }
133 
134 struct stb_arith
135 {
136 	uint range_low;
137 	uint range_high;
138 	uint code, range;
139 	int buffered_u8;
140 	int pending_ffs;
141 	stbfile* output;
142 }
143 
144 struct stb_arith_symstate_item
145 {
146 	ushort cumfreq;
147 	ushort samples;
148 }
149 
150 struct stb_arith_symstate
151 {
152 	int num_sym;
153 	uint pow2;
154 	int countdown;
155 	stb_arith_symstate_item[1] data;
156 }
157 
158 enum //stb_splitpath_flag
159 {
160 	STB_PATH = 1,
161 	STB_FILE = 2,
162 	STB_EXT = 4,
163 	STB_PATH_FILE = STB_PATH + STB_FILE,
164 	STB_FILE_EXT = STB_FILE + STB_EXT,
165 	STB_EXT_NO_PERIOD = 8,
166 }
167 
168 enum
169 {
170 	stb_keep_no,
171 	stb_keep_yes,
172 	stb_keep_if_different,
173 }
174 
175 __gshared extern
176 {
177 	int stb_alloc_chunk_size;
178 	int stb_alloc_count_free;
179 	int stb_alloc_count_alloc;
180 	int stb_alloc_alignment;
181 	int stb_perfect_hash_max_failures;
182 }
183 
184 void stb_wrapper_malloc(void* newp, int sz, char* file, int line);
185 void stb_wrapper_free(void* oldp, char* file, int line);
186 void stb_wrapper_realloc(void* oldp, void* newp, int sz, char* file, int line);
187 void stb_wrapper_calloc(size_t num, size_t sz, char* file, int line);
188 void stb_wrapper_listall(void function(void* ptr, int sz, char* file, int line) func);
189 void stb_wrapper_dump(char* filename);
190 int stb_wrapper_allocsize(void* oldp);
191 void stb_wrapper_check(void* oldp);
192 
193 void* stb_smalloc(size_t sz);
194 void stb_sfree(void* p);
195 void* stb_srealloc(void* p, size_t sz);
196 void* stb_scalloc(size_t n, size_t sz);
197 char* stb_sstrdup(char* s);
198 
199 void stbprint(const(char)* fmt, ...);
200 char* stb_sprintf(const(char)* fmt, ...);
201 char* stb_mprintf(const(char)* fmt, ...);
202 int stb_snprintf(char* s, size_t n, const(char)* fmt, ...);
203 int stb_vsnprintf(char* s, size_t n, const(char)* fmt, va_list v);
204 
205 wchar* stb_from_utf8(wchar* buffer, char* str, int n);
206 char* stb_to_utf8(char* buffer, wchar* str, int n);
207 
208 wchar* stb__from_utf8(char* str);
209 wchar* stb__from_utf8_alt(char* str);
210 char* stb__to_utf8(wchar* str);
211 
212 void stb_fatal(char* fmt, ...);
213 void stb_(char* fmt, ...);
214 void stb_append_to_file(char* file, char* fmt, ...);
215 void stb_log(int active);
216 void stb_log_fileline(int active);
217 void stb_log_name(char* filename);
218 
219 void stb_swap(void* p, void* q, size_t sz);
220 void* stb_copy(void* p, size_t sz);
221 void stb_pointer_array_free(void* p, int len);
222 void** stb_array_block_alloc(int count, int blocksize);
223 
224 int stb__record_fileline(char* f, int n);
225 
226 void* stb__temp(void* b, int b_sz, int want_sz);
227 void stb_tempfree(void* block, void* ptr);
228 
229 void stb_newell_normal(float* normal, int num_vert, float** vert, int normalize);
230 int stb_box_face_vertex_axis_side(int face_number, int vertex_number, int axis);
231 void stb_linear_controller(float* curpos, float target_pos, float acc, float deacc, float dt);
232 
233 int stb_float_eq(float x, float y, float delta, int max_ulps);
234 int stb_is_prime(uint m);
235 uint stb_power_of_two_nearest_prime(int n);
236 
237 float stb_smoothstep(float t);
238 float stb_cubic_bezier_1d(float t, float p0, float p1, float p2, float p3);
239 
240 double stb_linear_remap(double x, double a, double b, double c, double d);
241 
242 int stb_bitcount(uint a);
243 uint stb_bitreverse8(ubyte n);
244 uint stb_bitreverse(uint n);
245 
246 int stb_is_pow2(uint n);
247 int stb_log2_ceil(uint n);
248 int stb_log2_floor(uint n);
249 
250 int stb_lowbit8(uint n);
251 int stb_highbit8(uint n);
252 
253 int function(const(void)* a, const(void)* b) stb_intcmp(int offset);
254 int function(const(void)* a, const(void)* b) stb_qsort_strcmp(int offset);
255 int function(const(void)* a, const(void)* b) stb_qsort_stricmp(int offset);
256 int function(const(void)* a, const(void)* b) stb_floatcmp(int offset);
257 int function(const(void)* a, const(void)* b) stb_doublecmp(int offset);
258 int function(const(void)* a, const(void)* b) stb_charcmp(int offset);
259 
260 int stb_search_binary(stb_search* s, int minv, int maxv, int find_smallest);
261 int stb_search_open(stb_search* s, int minv, int find_smallest);
262 int stb_probe(stb_search* s, int compare, int* result);
263 
264 char* stb_skipwhite(char* s);
265 char* stb_trimwhite(char* s);
266 char* stb_skipnewline(char* s);
267 char* stb_strncpy(char* s, char* t, int n);
268 char* stb_substr(char* t, int n);
269 char* stb_duplower(char* s);
270 void stb_tolower(char* s);
271 char* stb_strchr2(char* s, char p1, char p2);
272 char* stb_strrchr2(char* s, char p1, char p2);
273 char* stb_strtok(char* output, char* src, char* delimit);
274 char* stb_strtok_keep(char* output, char* src, char* delimit);
275 char* stb_strtok_invert(char* output, char* src, char* allowed);
276 char* stb_dupreplace(char* s, char* find, char* replace);
277 void stb_replaceinplace(char* s, char* find, char* replace);
278 char* stb_splitpath(char* output, char* src, int flag);
279 char* stb_splitpathdup(char* src, int flag);
280 char* stb_replacedir(char* output, char* src, char* dir);
281 char* stb_replaceext(char* output, char* src, char* ext);
282 void stb_fixpath(char* path);
283 char* stb_shorten_path_readable(char* path, int max_len);
284 int stb_suffix(char* s, char* t);
285 int stb_suffixi(char* s, char* t);
286 int stb_prefix(char* s, char* t);
287 char* stb_strichr(char* s, char t);
288 char* stb_stristr(char* s, char* t);
289 int stb_prefix_count(char* s, char* t);
290 const(char)* stb_plural(int n);
291 size_t stb_strscpy(char* d, const(char)* s, size_t n);
292 
293 char** stb_tokens(char* src, char* delimit, int* count);
294 char** stb_tokens_nested(char* src, char* delimit, int* count, char* nest_in, char* nest_out);
295 char** stb_tokens_nested_empty(char* src, char* delimit, int* count, char* nest_in, char* nest_out);
296 char** stb_tokens_allowempty(char* src, char* delimit, int* count);
297 char** stb_tokens_stripwhite(char* src, char* delimit, int* count);
298 char** stb_tokens_withdelim(char* src, char* delimit, int* count);
299 char** stb_tokens_quoted(char* src, char* delimit, int* count);
300 
301 void stb_free(void* p);
302 void* stb_malloc_global(size_t size);
303 void* stb_malloc(void* context, size_t size);
304 void* stb_malloc_nofree(void* context, size_t size);
305 void* stb_malloc_leaf(void* context, size_t size);
306 void* stb_malloc_raw(void* context, size_t size);
307 void* stb_realloc(void* ptr, size_t newsize);
308 
309 void stb_reassign(void* new_context, void* ptr);
310 void stb_malloc_validate(void* p, void* parent);
311 
312 void stb_arr_malloc(void** target, void* context);
313 
314 void* stb_arr_malloc_parent(void* p);
315 
316 void stb_arr_free_(void** p);
317 void* stb__arr_copy_(void* p, int elem_size);
318 void stb__arr_setsize_(void** p, int size, int limit );
319 void stb__arr_setlen_(void** p, int size, int newlen );
320 void stb__arr_addlen_(void** p, int size, int addlen );
321 void stb__arr_deleten_(void** p, int size, int loc, int n );
322 void stb__arr_insertn_(void** p, int size, int loc, int n );
323 
324 uint stb_hash(char* str);
325 uint stb_hashptr(void* p);
326 uint stb_hashlen(char* str, int len);
327 uint stb_rehash_improved(uint v);
328 uint stb_hash_fast(void* p, int len);
329 uint stb_hash2(char* str, uint* hash2_ptr);
330 uint stb_hash_number(uint hash);
331 
332 int stb_perfect_create(stb_perfect*, uint*, int n);
333 void stb_perfect_destroy(stb_perfect*);
334 int stb_perfect_hash(stb_perfect*, uint x);
335 
336 int stb_ischar(char s, char* set);
337 
338 int stb_ptrmap_init(stb_ptrmap* h, int count);
339 int stb_ptrmap_memory_usage(stb_ptrmap* h);
340 stb_ptrmap* stb_ptrmap_create();
341 stb_ptrmap* stb_ptrmap_copy(stb_ptrmap* h);
342 void stb_ptrmap_destroy(stb_ptrmap* h);
343 int stb_ptrmap_get_flag(stb_ptrmap* a, void* k, void** v);
344 void* stb_ptrmap_get(stb_ptrmap* a, void* k);
345 int stb_ptrmap_set(stb_ptrmap* a, void* k, void* v);
346 int stb_ptrmap_add(stb_ptrmap* a, void* k, void* v);
347 int stb_ptrmap_update(stb_ptrmap* a, void* k, void* v);
348 int stb_ptrmap_remove(stb_ptrmap* a, void* k, void** v);
349 
350 int stb_idict_init(stb_idict* h, int count);
351 int stb_idict_memory_usage(stb_idict* h);
352 stb_idict* stb_idict_create();
353 stb_idict* stb_idict_copy(stb_idict* h);
354 void stb_idict_destroy(stb_idict* h);
355 int stb_idict_get_flag(stb_idict* a, int k, int* v);
356 int stb_idict_get(stb_idict* a, int k);
357 int stb_idict_set(stb_idict* a, int k, int v);
358 int stb_idict_add(stb_idict* a, int k, int v);
359 int stb_idict_update(stb_idict* a, int k, int v);
360 int stb_idict_remove(stb_idict* a, int k, int* v);
361 
362 void stb_ptrmap_delete(stb_ptrmap* e, void function(void*) free_func);
363 stb_ptrmap* stb_ptrmap_new();
364 
365 stb_idict* stb_idict_new_size(int size);
366 void stb_idict_remove_all(stb_idict* e);
367 
368 stb_spmatrix* stb_sparse_ptr_matrix_new(int val_size);
369 void stb_sparse_ptr_matrix_free(stb_spmatrix* z);
370 void* stb_sparse_ptr_matrix_get(stb_spmatrix* z, void* a, void* b, int create);
371 
372 int stb_sdict_init(stb_sdict* h, int count);
373 int stb_sdict_memory_usage(stb_sdict* h);
374 stb_sdict* stb_sdict_create();
375 stb_sdict* stb_sdict_copy(stb_sdict* h);
376 void stb_sdict_destroy(stb_sdict* h);
377 int stb_sdict_get_flag(stb_sdict* a, char* k, void** v);
378 void* stb_sdict_get(stb_sdict* a, char* k);
379 int stb_sdict_set(stb_sdict* a, char* k, void* v);
380 int stb_sdict_add(stb_sdict* a, char* k, void* v);
381 int stb_sdict_update(stb_sdict* a, char* k, void* v);
382 int stb_sdict_remove(stb_sdict* a, char* k, void** v);
383 
384 stb_sdict* stb_sdict_new(int use_arena);
385 stb_sdict* stb_sdict_copy(stb_sdict*);
386 void stb_sdict_delete(stb_sdict*);
387 void* stb_sdict_change(stb_sdict*, char* str, void* p);
388 int stb_sdict_count(stb_sdict* d);
389 
390 int stb_sdict_internal_limit(stb_sdict* d);
391 char* stb_sdict_internal_key(stb_sdict* d, int n);
392 void* stb_sdict_internal_value(stb_sdict* d, int n);
393 
394 void stb_fput_varlen64(FILE* f, ulong v);
395 ulong stb_fget_varlen64(FILE* f);
396 int stb_size_varlen64(ulong v);
397 
398 void* stb_file(char* filename, size_t* length);
399 void* stb_file_max(char* filename, size_t* length);
400 size_t stb_filelen(FILE* f);
401 int stb_filewrite(char* filename, void* data, size_t length);
402 int stb_filewritestr(char* filename, char* data);
403 char** stb_stringfile(char* filename, int* len);
404 char** stb_stringfile_trimmed(char* name, int* len, char comm);
405 char* stb_fgets(char* buffer, int buflen, FILE* f);
406 char* stb_fgets_malloc(FILE* f);
407 int stb_fexists(char* filename);
408 int stb_fcmp(char* s1, char* s2);
409 int stb_feq(char* s1, char* s2);
410 time_t stb_ftimestamp(char* filename);
411 
412 int stb_fullpath(char* abs, int abs_size, char* rel);
413 FILE* stb_fopen(char* filename, char* mode);
414 int stb_fclose(FILE* f, int keep);
415 
416 int stb_copyfile(char* src, char* dest);
417 
418 void stb_fput_varlen64(FILE* f, ulong v);
419 ulong stb_fget_varlen64(FILE* f);
420 int stb_size_varlen64(ulong v);
421 
422 void stb_fwrite32(FILE* f, uint datum);
423 void stb_fput_varlen(FILE* f, int v);
424 void stb_fput_varlenu(FILE* f, uint v);
425 int stb_fget_varlen(FILE* f);
426 uint stb_fget_varlenu(FILE* f);
427 void stb_fput_ranged(FILE* f, int v, int b, uint n);
428 int stb_fget_ranged(FILE* f, int b, uint n);
429 int stb_size_varlen(int v);
430 int stb_size_varlenu(uint v);
431 int stb_size_ranged(int b, uint n);
432 
433 int stb_fread(void* data, size_t len, size_t count, void* f);
434 int stb_fwrite(void* data, size_t len, size_t count, void* f);
435 
436 char** stb_getopt_param(int* argc, char** argv, char* param);
437 char** stb_getopt(int* argc, char** argv);
438 void stb_getopt_free(char** opts);
439 
440 char** stb_readdir_files(in char* dir);
441 char** stb_readdir_files_mask(in char* dir, in char* wild);
442 char** stb_readdir_subdirs(in char* dir);
443 char** stb_readdir_subdirs_mask(in char* dir, in char* wild);
444 void stb_readdir_free(char** files);
445 char** stb_readdir_recursive(in char* dir, in char* filespec);
446 void stb_delete_directory_recursive(in char* dir);
447 
448 stb_dirtree2* stb_dirtree2_from_files_relative(char* src, char** filelist, int count);
449 stb_dirtree2* stb_dirtree2_from_files(char** filelist, int count);
450 int stb_dir_is_prefix(char* dir, int dirlen, char* file);
451 
452 uint stb_adler32(uint adler32, in void* buffer, uint buflen);
453 uint stb_crc32_block(uint crc32, in void* buffer, uint len);
454 uint stb_crc32(in void* buffer, uint len);
455 
456 void stb_sha1(ref ubyte[20] output, in void* buffer, uint len);
457 int stb_sha1_file(ref ubyte[20] output, in char *file);
458 void stb_sha1_readable(ref char[27] display, ref ubyte[20] sha);
459 
460 void* stb_reg_open(char* mode, char* where);
461 void stb_reg_close(void* reg);
462 int stb_reg_read(void* zreg, char* str, void* data, size_t len);
463 int stb_reg_read_string(void* zreg, char* str, char* data, int len);
464 void stb_reg_write(void* zreg, char* str, void* data, size_t len);
465 void stb_reg_write_string(void* zreg, char* str, char* data);
466 
467 stb_cfg* stb_cfg_open(char* config, char* mode);
468 void stb_cfg_close(stb_cfg* cfg);
469 int stb_cfg_read(stb_cfg* cfg, char* key, void* value, int len);
470 void stb_cfg_write(stb_cfg* cfg, char* key, void* value, int len);
471 int stb_cfg_read_string(stb_cfg* cfg, char* key, char* value, int len);
472 void stb_cfg_write_string(stb_cfg* cfg, char* key, char* value);
473 int stb_cfg_delete(stb_cfg* cfg, char* key);
474 void stb_cfg_set_directory(char* dir);
475 
476 void stb_dirtree_free( stb_dirtree* d );
477 stb_dirtree* stb_dirtree_get( char* dir);
478 stb_dirtree* stb_dirtree_get_dir( char* dir, char* cache_dir);
479 stb_dirtree* stb_dirtree_get_with_file( char* dir, char* cache_file);
480 
481 void stb_dirtree_db_add_dir(stb_dirtree* active, char* path, time_t last);
482 void stb_dirtree_db_add_file(stb_dirtree* active, char* name, int dir, long size, time_t last);
483 void stb_dirtree_db_read(stb_dirtree* target, char* filename, char* dir);
484 void stb_dirtree_db_write(stb_dirtree* target, char* filename, char* dir);
485 
486 int stb_ps_find(stb_ps* ps, void* value);
487 stb_ps* stb_ps_add(stb_ps* ps, void* value);
488 stb_ps* stb_ps_remove(stb_ps* ps, void* value);
489 stb_ps* stb_ps_remove_any(stb_ps* ps, void** value);
490 void stb_ps_delete(stb_ps* ps);
491 int stb_ps_count(stb_ps* ps);
492 
493 stb_ps* stb_ps_copy(stb_ps* ps);
494 int stb_ps_subset(stb_ps* bigger, stb_ps* smaller);
495 int stb_ps_eq(stb_ps* p0, stb_ps* p1);
496 
497 void** stb_ps_getlist(stb_ps* ps, int* count);
498 int stb_ps_writelist(stb_ps* ps, void** list, int size );
499 
500 int stb_ps_enum(stb_ps* ps, void* data, int function(void* value, void* data) func);
501 void** stb_ps_fastlist(stb_ps* ps, int* count);
502 
503 size_t stb_srandLCG(size_t seed);
504 size_t stb_randLCG();
505 double stb_frandLCG();
506 
507 void stb_srand(size_t seed);
508 size_t stb_rand();
509 double stb_frand();
510 void stb_shuffle(void* p, size_t n, size_t sz, size_t seed);
511 void stb_reverse(void* p, size_t n, size_t sz);
512 
513 size_t stb_randLCG_explicit(size_t seed);
514 
515 void stb_dupe_free(stb_dupe* sd);
516 stb_dupe* stb_dupe_create(stb_hash_func hash,
517 	stb_compare_func eq, int size, stb_compare_func ineq);
518 void stb_dupe_add(stb_dupe* sd, void* item);
519 void stb_dupe_finish(stb_dupe* sd);
520 int stb_dupe_numsets(stb_dupe* sd);
521 void** stb_dupe_set(stb_dupe* sd, int num);
522 int stb_dupe_set_count(stb_dupe* sd, int num);
523 
524 stb_bitset* stb_bitset_new(int value, int len);
525 stb_bitset* stb_bitset_union(stb_bitset* p0, stb_bitset* p1, int len);
526 
527 int* stb_bitset_getlist(stb_bitset* out_, int start, int end);
528 
529 int stb_bitset_eq(stb_bitset* p0, stb_bitset* p1, int len);
530 int stb_bitset_disjoint(stb_bitset* p0, stb_bitset* p1, int len);
531 int stb_bitset_disjoint_0(stb_bitset* p0, stb_bitset* p1, int len);
532 int stb_bitset_subset(stb_bitset* bigger, stb_bitset* smaller, int len);
533 int stb_bitset_unioneq_changed(stb_bitset* p0, stb_bitset* p1, int len);
534 
535 int stb_wordwrap(int* pairs, int pair_max, int count, char* str);
536 int* stb_wordwrapalloc(int count, char* str);
537 
538 int stb_wildmatch(char* expr, char* candidate);
539 int stb_wildmatchi(char* expr, char* candidate);
540 int stb_wildfind(char* expr, char* candidate);
541 int stb_wildfindi(char* expr, char* candidate);
542 
543 int stb_regex(char* regex, char* candidate);
544 
545 stb_matcher* stb_regex_matcher(char* regex);
546 int stb_matcher_match(stb_matcher* m, char* str);
547 int stb_matcher_find(stb_matcher* m, char* str);
548 void stb_matcher_free(stb_matcher* f);
549 
550 stb_matcher* stb_lex_matcher();
551 int stb_lex_item(stb_matcher* m, char* str, int result);
552 int stb_lex_item_wild(stb_matcher* matcher, char* regex, int result);
553 int stb_lex(stb_matcher* m, char* str, int* len);
554 
555 uint stb_decompress_length(void* input);
556 uint stb_decompress(void* out_, void* in_, uint len);
557 uint stb_compress(void* out_, void* in_, uint len);
558 void stb_compress_window(int z);
559 void stb_compress_hashsize(uint z);
560 
561 int stb_compress_tofile(char* filename, char* in_, uint len);
562 int stb_compress_intofile(FILE* f, char* input, uint len);
563 char* stb_decompress_fromfile(char* filename, uint* len);
564 
565 int stb_compress_stream_start(FILE* f);
566 void stb_compress_stream_end(int close);
567 void stb_write(char* data, int data_len);
568 
569 uint stb_getc(stbfile* f);
570 int stb_putc(stbfile* f, int ch);
571 uint stb_getdata(stbfile* f, void* buffer, uint len);
572 uint stb_putdata(stbfile* f, void* buffer, uint len);
573 uint stb_tell(stbfile* f);
574 uint stb_size(stbfile* f);
575 void stb_backpatch(stbfile* f, uint tell, void* buffer, uint len);
576 
577 void stb_arith_init_encode(stb_arith* a, stbfile* out_);
578 void stb_arith_init_decode(stb_arith* a, stbfile* in_);
579 stbfile* stb_arith_encode_close(stb_arith* a);
580 stbfile* stb_arith_decode_close(stb_arith* a);
581 
582 void stb_arith_encode(stb_arith* a, uint totalfreq, uint freq, uint cumfreq);
583 void stb_arith_encode_log2(stb_arith* a, uint totalfreq2, uint freq, uint cumfreq);
584 uint stb_arith_decode_value(stb_arith* a, uint totalfreq);
585 void stb_arith_decode_advance(stb_arith* a, uint totalfreq, uint freq, uint cumfreq);
586 uint stb_arith_decode_value_log2(stb_arith* a, uint totalfreq2);
587 void stb_arith_decode_advance_log2(stb_arith* a, uint totalfreq2, uint freq, uint cumfreq);
588 
589 void stb_arith_encode_byte(stb_arith* a, int byte_);
590 int stb_arith_decode_byte(stb_arith* a);
591 
592 void stb_thread_cleanup();
593 
594 int stb_processor_count();
595 
596 void stb_force_uniprocessor();
597 
598 void stb_work_numthreads(int n);
599 
600 int stb_work_maxunits(int n);
601 
602 int stb_work(stb_thread_func f, void* d, /*volatile*/ void** return_code);
603 
604 int stb_work_reach(stb_thread_func f, void* d, /*volatile*/ void** return_code, stb_sync rel);
605 
606 void stb_barrier();
607 
608 stb_workqueue* stb_workq_new(int numthreads, int max_units);
609 stb_workqueue* stb_workq_new_flags(int numthreads, int max_units, int no_add_mutex, int no_remove_mutex);
610 void stb_workq_delete(stb_workqueue* q);
611 void stb_workq_numthreads(stb_workqueue* q, int n);
612 int stb_workq(stb_workqueue* q, stb_thread_func f, void* d, /*volatile*/ void** return_code);
613 int stb_workq_reach(stb_workqueue* q, stb_thread_func f, void* d, /*volatile*/ void** return_code, stb_sync rel);
614 int stb_workq_length(stb_workqueue* q);
615 
616 stb_thread stb_create_thread(stb_thread_func f, void* d);
617 stb_thread stb_create_thread2(stb_thread_func f, void* d, /*volatile*/ void** return_code, stb_semaphore rel);
618 void stb_destroy_thread(stb_thread t);
619 
620 stb_semaphore stb_sem_new(int max_val);
621 stb_semaphore stb_sem_new_extra(int max_val, int start_val);
622 void stb_sem_delete(stb_semaphore s);
623 void stb_sem_waitfor(stb_semaphore s);
624 void stb_sem_release(stb_semaphore s);
625 
626 stb_mutex stb_mutex_new();
627 void stb_mutex_delete(stb_mutex m);
628 void stb_mutex_begin(stb_mutex m);
629 void stb_mutex_end(stb_mutex m);
630 
631 stb_sync stb_sync_new();
632 void stb_sync_delete(stb_sync s);
633 int stb_sync_set_target(stb_sync s, int count);
634 void stb_sync_reach_and_wait(stb_sync s);
635 int stb_sync_reach(stb_sync s);
636 
637 stb_threadqueue* stb_threadq_new(int item_size, int num_items, int many_add, int many_remove);
638 void stb_threadq_delete(stb_threadqueue* tq);
639 int stb_threadq_get(stb_threadqueue* tq, void* output);
640 void stb_threadq_get_block(stb_threadqueue* tq, void* output);
641 int stb_threadq_add(stb_threadqueue* tq, void* input);
642 
643 int stb_threadq_add_block(stb_threadqueue* tq, void* input);
644 
645 void stb_source_path(char* str);