ia64/xen-unstable

view extras/mini-os/lib/string.c @ 4146:f2d61710e4d9

bitkeeper revision 1.1236.25.24 (42366e9aQ71LQ8uCB-Y1IwVNqx5eqA)

Merge djm@kirby.fc.hp.com://home/djm/src/xen/xeno-unstable-ia64.bk
into sportsman.spdomain:/home/djm/xeno-unstable-ia64.bk
author djm@sportsman.spdomain
date Tue Mar 15 05:11:54 2005 +0000 (2005-03-15)
parents aadd0dc51c45
children df1348e72390 cdfa7dd00c44 b2f4823b6ff0
line source
1 /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*-
2 ****************************************************************************
3 * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
4 ****************************************************************************
5 *
6 * File: string.c
7 * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
8 * Changes:
9 *
10 * Date: Aug 2003
11 *
12 * Environment: Xen Minimal OS
13 * Description: Library function for string and memory manipulation
14 * Origin unknown
15 *
16 ****************************************************************************
17 * $Id: c-insert.c,v 1.7 2002/11/08 16:04:34 rn Exp $
18 ****************************************************************************
19 */
21 #include <os.h>
22 #include <types.h>
23 #include <lib.h>
25 int memcmp(const void * cs,const void * ct,size_t count)
26 {
27 const unsigned char *su1, *su2;
28 signed char res = 0;
30 for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
31 if ((res = *su1 - *su2) != 0)
32 break;
33 return res;
34 }
36 void * memcpy(void * dest,const void *src,size_t count)
37 {
38 char *tmp = (char *) dest;
39 const char *s = src;
41 while (count--)
42 *tmp++ = *s++;
44 return dest;
45 }
47 int strncmp(const char * cs,const char * ct,size_t count)
48 {
49 register signed char __res = 0;
51 while (count) {
52 if ((__res = *cs - *ct++) != 0 || !*cs++)
53 break;
54 count--;
55 }
57 return __res;
58 }
60 int strcmp(const char * cs,const char * ct)
61 {
62 register signed char __res;
64 while (1) {
65 if ((__res = *cs - *ct++) != 0 || !*cs++)
66 break;
67 }
69 return __res;
70 }
72 char * strcpy(char * dest,const char *src)
73 {
74 char *tmp = dest;
76 while ((*dest++ = *src++) != '\0')
77 /* nothing */;
78 return tmp;
79 }
81 char * strncpy(char * dest,const char *src,size_t count)
82 {
83 char *tmp = dest;
85 while (count-- && (*dest++ = *src++) != '\0')
86 /* nothing */;
88 return tmp;
89 }
91 void * memset(void * s,int c,size_t count)
92 {
93 char *xs = (char *) s;
95 while (count--)
96 *xs++ = c;
98 return s;
99 }
101 size_t strnlen(const char * s, size_t count)
102 {
103 const char *sc;
105 for (sc = s; count-- && *sc != '\0'; ++sc)
106 /* nothing */;
107 return sc - s;
108 }
110 size_t strlen(const char * s)
111 {
112 const char *sc;
114 for (sc = s; *sc != '\0'; ++sc)
115 /* nothing */;
116 return sc - s;
117 }
119 char * strchr(const char * s, int c)
120 {
121 for(; *s != (char) c; ++s)
122 if (*s == '\0')
123 return NULL;
124 return (char *)s;
125 }
127 char * strstr(const char * s1,const char * s2)
128 {
129 int l1, l2;
131 l2 = strlen(s2);
132 if (!l2)
133 return (char *) s1;
134 l1 = strlen(s1);
135 while (l1 >= l2) {
136 l1--;
137 if (!memcmp(s1,s2,l2))
138 return (char *) s1;
139 s1++;
140 }
141 return NULL;
142 }