diff options
| author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2025-10-15 19:46:13 +0200 |
|---|---|---|
| committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2025-10-15 19:46:13 +0200 |
| commit | 184526f3bf90e2948b1d09b9da58d66814181f4d (patch) | |
| tree | d39614e3e29fb89594d1dc52ef07805bc754c4c7 /sam/util.c | |
| parent | fd41e6cc88f98121db5c64a0693e4169962f6c2c (diff) | |
Import sam and samterm sources
Diffstat (limited to 'sam/util.c')
| -rw-r--r-- | sam/util.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/sam/util.c b/sam/util.c new file mode 100644 index 0000000..b259968 --- /dev/null +++ b/sam/util.c @@ -0,0 +1,54 @@ +#include "sam.h" + +void +cvttorunes(char *p, int n, Rune *r, int *nb, int *nr, int *nulls) +{ + uchar *q; + Rune *s; + int j, w; + + /* + * Always guaranteed that n bytes may be interpreted + * without worrying about partial runes. This may mean + * reading up to UTFmax-1 more bytes than n; the caller + * knows this. If n is a firm limit, the caller should + * set p[n] = 0. + */ + q = (uchar*)p; + s = r; + for(j=0; j<n; j+=w){ + if(*q < Runeself){ + w = 1; + *s = *q++; + }else{ + w = chartorune(s, (char*)q); + q += w; + } + if(*s) + s++; + else if(nulls) + *nulls = TRUE; + } + *nb = (char*)q-p; + *nr = s-r; +} + +void* +fbufalloc(void) +{ + return emalloc(BUFSIZE); +} + +void +fbuffree(void *f) +{ + free(f); +} + +uint +min(uint a, uint b) +{ + if(a < b) + return a; + return b; +} |