summaryrefslogtreecommitdiff
path: root/src/byte.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/byte.c')
-rw-r--r--src/byte.c119
1 files changed, 62 insertions, 57 deletions
diff --git a/src/byte.c b/src/byte.c
index e027f4d..698c50a 100644
--- a/src/byte.c
+++ b/src/byte.c
@@ -12,60 +12,63 @@ unsigned int byte_chr(char *s, unsigned int n, int c)
char *t = s;
for (;;) {
- // clang-format off
- 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;
- // clang-format on
+ if (!n) {
+ break;
+ }
+ if (*t == ch) {
+ break;
+ }
+ ++t;
+ --n;
}
return t - s;
}
-void byte_copy(void *a, unsigned int n, const void *b)
+void byte_copy(void *to, unsigned int n, const void *from)
{
- char *to = a;
- const char *from = b;
+ char *out = to; // share same address
+ const char *in = from; // one byte
for (;;) {
- // clang-format off
- if (!n) { return; } *to++ = *from++; --n;
- if (!n) { return; } *to++ = *from++; --n;
- if (!n) { return; } *to++ = *from++; --n;
- if (!n) { return; } *to++ = *from++; --n;
- // clang-format on
+ if (!n) {
+ return;
+ }
+ *out++ = *in++;
+ --n;
}
}
-void byte_copyr(void *a, unsigned int n, const void *b)
+void byte_copyr(void *to, unsigned int n, const void *from)
{
- char *to = a + n;
- const char *from = b + n;
+ char *out = to + n;
+ const char *in = from + n;
for (;;) {
- // clang-format off
- if (!n) { return; } *--to = *--from; --n;
- if (!n) { return; } *--to = *--from; --n;
- if (!n) { return; } *--to = *--from; --n;
- if (!n) { return; } *--to = *--from; --n;
- // clang-format on
+ if (!n) {
+ return;
+ }
+ *--out = *--in;
+ --n;
}
}
-int byte_diff(const void *a, unsigned int n, const void *b)
+int byte_diff(const void *s, unsigned int n, const void *t)
{
- const char *s = a;
- const char *t = b;
+ const char *a = s;
+ const char *b = t;
for (;;) {
- // clang-format off
- 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;
- // clang-format on
+ if (!n) {
+ return 0;
+ }
+ if (*a != *b) {
+ break;
+ }
+ ++a;
+ ++b;
+ --n;
}
- return ((int)(unsigned int)(unsigned char)*s) - ((int)(unsigned int)(unsigned char)*t);
+ return ((int)(unsigned int)(unsigned char)*a) - ((int)(unsigned int)(unsigned char)*b);
}
unsigned int byte_rchr(char *s, unsigned int n, int c)
@@ -75,42 +78,44 @@ unsigned int byte_rchr(char *s, unsigned int n, int c)
char *u = 0;
for (;;) {
- // clang-format off
- 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;
- // clang-format on
+ if (!n) {
+ break;
+ }
+ if (*t == ch) {
+ u = t;
+ }
+ ++t;
+ --n;
+ }
+ if (!u) {
+ u = t;
}
- if (!u) u = t;
return u - s;
}
-void byte_zero(void *v, unsigned int n)
+void byte_zero(void *s, unsigned int n)
{
- char *s = v;
+ char *out = s;
for (;;) {
- // clang-format off
- if (!n) { break; } *s++ = 0; --n;
- if (!n) { break; } *s++ = 0; --n;
- if (!n) { break; } *s++ = 0; --n;
- if (!n) { break; } *s++ = 0; --n;
- // clang-format on
+ if (!n) {
+ break;
+ }
+ *out++ = 0;
+ --n;
}
}
-void byte_fill(void *a, unsigned int n, int c)
+void byte_fill(void *to, unsigned int n, int c)
{
- char *s = a;
+ char *s = to;
char ch = c;
for (;;) {
- // clang-format off
- if (!n) { break; } *s++ = ch; --n;
- if (!n) { break; } *s++ = ch; --n;
- if (!n) { break; } *s++ = ch; --n;
- if (!n) { break; } *s++ = ch; --n;
- // clang-format on
+ if (!n) {
+ break;
+ }
+ *s++ = ch;
+ --n;
}
}