diff options
| author | 2022-10-22 05:59:55 +0200 | |
|---|---|---|
| committer | 2022-10-22 05:59:55 +0200 | |
| commit | f7781d3f64e2451383aab27293c96af53ba65145 (patch) | |
| tree | 10fe77c9131e4c0e0abfcba37288b0c5466b492e /xs.h | |
| parent | Backport from xs. (diff) | |
| download | snac2-f7781d3f64e2451383aab27293c96af53ba65145.tar.gz snac2-f7781d3f64e2451383aab27293c96af53ba65145.tar.xz snac2-f7781d3f64e2451383aab27293c96af53ba65145.zip | |
Backport from xs.
Diffstat (limited to 'xs.h')
| -rw-r--r-- | xs.h | 20 |
1 files changed, 17 insertions, 3 deletions
| @@ -34,9 +34,7 @@ typedef char d_char; | |||
| 34 | /* auto-destroyable strings */ | 34 | /* auto-destroyable strings */ |
| 35 | #define xs __attribute__ ((__cleanup__ (_xs_destroy))) d_char | 35 | #define xs __attribute__ ((__cleanup__ (_xs_destroy))) d_char |
| 36 | 36 | ||
| 37 | #define _XS_BLK_SIZE 16 | 37 | int _xs_blk_size(int sz); |
| 38 | #define _xs_blk_size(sz) ((((sz) + _XS_BLK_SIZE) / _XS_BLK_SIZE) * _XS_BLK_SIZE) | ||
| 39 | |||
| 40 | void _xs_destroy(char **var); | 38 | void _xs_destroy(char **var); |
| 41 | #define xs_debug() raise(SIGTRAP) | 39 | #define xs_debug() raise(SIGTRAP) |
| 42 | xstype xs_type(const char *data); | 40 | xstype xs_type(const char *data); |
| @@ -97,6 +95,22 @@ void _xs_destroy(char **var) | |||
| 97 | free(*var); | 95 | free(*var); |
| 98 | } | 96 | } |
| 99 | 97 | ||
| 98 | |||
| 99 | int _xs_blk_size(int sz) | ||
| 100 | /* calculates the block size */ | ||
| 101 | { | ||
| 102 | int blk_size = 4096; | ||
| 103 | |||
| 104 | if (sz < 256) | ||
| 105 | blk_size = 32; | ||
| 106 | else | ||
| 107 | if (sz < 4096) | ||
| 108 | blk_size = 256; | ||
| 109 | |||
| 110 | return ((((sz) + blk_size) / blk_size) * blk_size); | ||
| 111 | } | ||
| 112 | |||
| 113 | |||
| 100 | xstype xs_type(const char *data) | 114 | xstype xs_type(const char *data) |
| 101 | /* return the type of data */ | 115 | /* return the type of data */ |
| 102 | { | 116 | { |