]> Joshua Wise's Git repositories - netwatch.git/blame - lib/minilib.c
Merge branch 'master' of /storage/git/netwatch
[netwatch.git] / lib / minilib.c
CommitLineData
9b8c947b 1#include "console.h"
36ce375d 2#include <minilib.h>
9b8c947b 3
36ce375d 4void memcpy(void *dest, void *src, int bytes)
9b8c947b 5{
36ce375d
JP
6 char * cdest = dest;
7 char * csrc = src;
9b8c947b 8 while (bytes--)
36ce375d 9 *(cdest++) = *(csrc++);
9b8c947b
JW
10}
11
36ce375d 12void memmove(void *dest, void *src, int bytes)
9b8c947b 13{
36ce375d
JP
14 char * cdest = dest;
15 char * csrc = src;
16 if ((cdest > csrc) && (cdest <= (csrc + bytes)))
9b8c947b
JW
17 {
18 /* do it backwards! */
36ce375d
JP
19 cdest += bytes;
20 csrc += bytes;
9b8c947b 21 while (bytes--)
36ce375d 22 *(--cdest) = *(--csrc);
9b8c947b
JW
23 } else
24 while (bytes--)
36ce375d 25 *(cdest++) = *(csrc++);
9b8c947b
JW
26}
27
36ce375d 28int memcmp (const char *a2, const char *a1, int bytes) {
d56898ee 29 while (bytes--)
30 {
31 if (*(a2++) != *(a1++))
32 return 1;
33 }
34 return 0;
35}
36
36ce375d 37int strcmp (const char *a2, const char *a1) {
d56898ee 38 while (1) {
39 if (*a2 != *a1) return 1;
40 if (*a2 == 0) return 0;
41 a1++;
42 a2++;
43 }
44}
45
f2da2cd3 46int strlen(const char *c)
9b8c947b
JW
47{
48 int l = 0;
49 while (*(c++))
50 l++;
51 return l;
52}
53
36ce375d 54void strcpy(char *a2, const char *a1)
31be35cd
JW
55{
56 do {
57 *(a2++) = *a1;
58 } while (*(a1++));
59}
60
f2da2cd3 61void puts(const char *c)
9b8c947b
JW
62{
63 putbytes(c, strlen(c));
64}
65
66static char hexarr[] = "0123456789ABCDEF";
36ce375d 67void tohex(char *s, unsigned long l)
9b8c947b
JW
68{
69 int i;
70 for (i = 0; i < 8; i++)
71 {
31be35cd 72 s[i] = hexarr[l >> 28];
9b8c947b
JW
73 l <<= 4;
74 }
75}
31be35cd
JW
76
77void puthex(unsigned long l)
78{
36ce375d 79 char d[9];
31be35cd
JW
80 d[8] = 0;
81 tohex(d, l);
82 puts(d);
83}
This page took 0.035007 seconds and 4 git commands to generate.