]> Joshua Wise's Git repositories - netwatch.git/blame - lib/minilib.c
Wait for completion before we pull the trigger on the pbuf
[netwatch.git] / lib / minilib.c
CommitLineData
9b8c947b 1#include "console.h"
36ce375d 2#include <minilib.h>
9b8c947b 3
42e26afa 4void memcpy(void *dest, const void *src, int bytes)
9b8c947b 5{
ee681ad4
JW
6 char *cdest = dest;
7 const char *csrc = src;
9b8c947b 8 while (bytes--)
36ce375d 9 *(cdest++) = *(csrc++);
9b8c947b
JW
10}
11
6e6d4a8b
JP
12void memset(void *dest, int data, int bytes)
13{
14 unsigned char *cdest = dest;
15 while (bytes--)
16 *(cdest++) = (unsigned char)data;
17}
18
36ce375d 19void memmove(void *dest, void *src, int bytes)
9b8c947b 20{
36ce375d
JP
21 char * cdest = dest;
22 char * csrc = src;
23 if ((cdest > csrc) && (cdest <= (csrc + bytes)))
9b8c947b
JW
24 {
25 /* do it backwards! */
36ce375d
JP
26 cdest += bytes;
27 csrc += bytes;
9b8c947b 28 while (bytes--)
36ce375d 29 *(--cdest) = *(--csrc);
9b8c947b
JW
30 } else
31 while (bytes--)
36ce375d 32 *(cdest++) = *(csrc++);
9b8c947b
JW
33}
34
36ce375d 35int memcmp (const char *a2, const char *a1, int bytes) {
d56898ee 36 while (bytes--)
37 {
38 if (*(a2++) != *(a1++))
39 return 1;
40 }
41 return 0;
42}
43
36ce375d 44int strcmp (const char *a2, const char *a1) {
d56898ee 45 while (1) {
46 if (*a2 != *a1) return 1;
47 if (*a2 == 0) return 0;
48 a1++;
49 a2++;
50 }
51}
52
6f9272bd
JW
53int strncmp (const char *a2, const char *a1, int n) {
54 while (n--) {
55 if (*a2 != *a1) return 1;
56 if (*a2 == 0) return 0;
57 a1++;
58 a2++;
59 }
60 return 0;
61}
62
f2da2cd3 63int strlen(const char *c)
9b8c947b
JW
64{
65 int l = 0;
66 while (*(c++))
67 l++;
68 return l;
69}
70
36ce375d 71void strcpy(char *a2, const char *a1)
31be35cd
JW
72{
73 do {
74 *(a2++) = *a1;
75 } while (*(a1++));
76}
77
9343e933
JW
78void strcat(char *dest, char *src)
79{
80 while (*dest)
81 dest++;
82 while (*src)
83 *(dest++) = *(src++);
84 *(dest++) = *(src++);
85}
86
f2da2cd3 87void puts(const char *c)
9b8c947b
JW
88{
89 putbytes(c, strlen(c));
90}
91
92static char hexarr[] = "0123456789ABCDEF";
36ce375d 93void tohex(char *s, unsigned long l)
9b8c947b
JW
94{
95 int i;
96 for (i = 0; i < 8; i++)
97 {
31be35cd 98 s[i] = hexarr[l >> 28];
9b8c947b
JW
99 l <<= 4;
100 }
101}
31be35cd
JW
102
103void puthex(unsigned long l)
104{
36ce375d 105 char d[9];
31be35cd
JW
106 d[8] = 0;
107 tohex(d, l);
108 puts(d);
109}
644af6b4
JP
110
111unsigned short htons(unsigned short in)
112{
113 return (in >> 8) | (in << 8);
114}
6e6d4a8b
JP
115
116unsigned int htonl(unsigned int in)
117{
118 return ((in & 0xff) << 24) |
119 ((in & 0xff00) << 8) |
120 ((in & 0xff0000UL) >> 8) |
121 ((in & 0xff000000UL) >> 24);
122}
This page took 0.03968 seconds and 4 git commands to generate.