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