diff options
author | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-09 13:58:20 +0200 |
---|---|---|
committer | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-09 13:58:20 +0200 |
commit | 249866e3d1e11dc72eaa1305f4bb479ded92ef38 (patch) | |
tree | 7118c5f58e29fe61c100e4d067bb90ba8d52589e /src/byte.c | |
parent | 96cf8dffe4f7b0b910f790066ae622dc429eb522 (diff) |
reorganized file structure
Moved c files into src/.
Corrected VERSION file.
Removed BUILD and FILES.
Diffstat (limited to 'src/byte.c')
-rw-r--r-- | src/byte.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/byte.c b/src/byte.c new file mode 100644 index 0000000..c9d6d23 --- /dev/null +++ b/src/byte.c @@ -0,0 +1,99 @@ +#include "byte.h" + +/** + @file byte.c + @author djb + @brief byte manipulation functions +*/ + +unsigned int byte_chr(char *s,register unsigned int n,int c) +{ + register char ch; + register char *t; + + ch = c; + t = s; + for (;;) { + if (!n) { break; } if (*t == ch) { break; } ++t; --n; + if (!n) { break; } if (*t == ch) { break; } ++t; --n; + if (!n) { break; } if (*t == ch) { break; } ++t; --n; + if (!n) { break; } if (*t == ch) { break; } ++t; --n; + } + return t - s; +} + +void byte_copy(register char *to,register unsigned int n,register char *from) +{ + for (;;) { + if (!n) { return; } *to++ = *from++; --n; + if (!n) { return; } *to++ = *from++; --n; + if (!n) { return; } *to++ = *from++; --n; + if (!n) { return; } *to++ = *from++; --n; + } +} + +void byte_copyr(register char *to,register unsigned int n,register char *from) +{ + to += n; + from += n; + for (;;) { + if (!n) { return; } *--to = *--from; --n; + if (!n) { return; } *--to = *--from; --n; + if (!n) { return; } *--to = *--from; --n; + if (!n) { return; } *--to = *--from; --n; + } +} + +int byte_diff(register char *s,register unsigned int n,register char *t) +{ + for (;;) { + if (!n) { return 0; } if (*s != *t) { break; } ++s; ++t; --n; + if (!n) { return 0; } if (*s != *t) { break; } ++s; ++t; --n; + if (!n) { return 0; } if (*s != *t) { break; } ++s; ++t; --n; + if (!n) { return 0; } if (*s != *t) { break; } ++s; ++t; --n; + } + return ((int)(unsigned int)(unsigned char) *s) + - ((int)(unsigned int)(unsigned char) *t); +} + +unsigned int byte_rchr(char *s,register unsigned int n,int c) +{ + register char ch; + register char *t; + register char *u; + + ch = c; + t = s; + u = 0; + for (;;) { + if (!n) { break; } if (*t == ch) { u = t; } ++t; --n; + if (!n) { break; } if (*t == ch) { u = t; } ++t; --n; + if (!n) { break; } if (*t == ch) { u = t; } ++t; --n; + if (!n) { break; } if (*t == ch) { u = t; } ++t; --n; + } + if (!u) { u = t; } + return u - s; +} + +void byte_zero(char *s,register unsigned int n) +{ + for (;;) { + if (!n) { break; } *s++ = 0; --n; + if (!n) { break; } *s++ = 0; --n; + if (!n) { break; } *s++ = 0; --n; + if (!n) { break; } *s++ = 0; --n; + } +} + +void byte_fill(char *s,register unsigned int n,const int c) +{ + register char ch; + + ch = c; + for (;;) { + if (!n) { break; } *s++ = ch; --n; + if (!n) { break; } *s++ = ch; --n; + if (!n) { break; } *s++ = ch; --n; + if (!n) { break; } *s++ = ch; --n; + } +} |