fehQlibs 26
Qlibs
Loading...
Searching...
No Matches
byte.c
Go to the documentation of this file.
1#include "byte.h"
2
9unsigned int byte_chr(char *s,unsigned int n,int c)
10{
11 char ch = c;
12 char *t = s;
13
14 for (;;) {
15 if (!n) { break; } if (*t == ch) { break; } ++t; --n;
16 }
17 return t - s;
18}
19
20void byte_copy(void *to,unsigned int n,const void *from)
21{
22 char *out = to; // share same address
23 const char *in = from; // one byte
24
25 for (;;) {
26 if (!n) { return; } *out++ = *in++; --n;
27 }
28}
29
30void byte_copyr(void *to,unsigned int n,const void *from)
31{
32 char *out = to + n;
33 const char *in = from + n;
34
35 for (;;) {
36 if (!n) { return; } *--out = *--in; --n;
37 }
38}
39
40int byte_diff(const void *s,unsigned int n,const void *t)
41{
42 const char *a = s;
43 const char *b = t;
44
45 for (;;) {
46 if (!n) { return 0; } if (*a != *b) { break; } ++a; ++b; --n;
47 }
48 return ((int)(unsigned int)(unsigned char) *a)
49 - ((int)(unsigned int)(unsigned char) *b);
50}
51
52unsigned int byte_rchr(char *s,unsigned int n,int c)
53{
54 char ch = c;
55 char *t = s;
56 char *u = 0;
57
58 for (;;) {
59 if (!n) { break; } if (*t == ch) { u = t; } ++t; --n;
60 }
61 if (!u) { u = t; }
62 return u - s;
63}
64
65void byte_zero(void *s,unsigned int n)
66{
67 char *out = s;
68
69 for (;;) {
70 if (!n) { break; } *out++ = 0; --n;
71 }
72}
73
74void byte_fill(void *to,unsigned int n,int c)
75{
76 char *s = to;
77 char ch = c;
78
79 for (;;) {
80 if (!n) { break; } *s++ = ch; --n;
81 }
82}
void byte_fill(void *to, unsigned int n, int c)
Definition: byte.c:74
void byte_zero(void *s, unsigned int n)
Definition: byte.c:65
int byte_diff(const void *s, unsigned int n, const void *t)
Definition: byte.c:40
void byte_copyr(void *to, unsigned int n, const void *from)
Definition: byte.c:30
unsigned int byte_chr(char *s, unsigned int n, int c)
Definition: byte.c:9
unsigned int byte_rchr(char *s, unsigned int n, int c)
Definition: byte.c:52
void byte_copy(void *to, unsigned int n, const void *from)
Definition: byte.c:20