ia64/xen-unstable

view extras/mini-os/lib/string.c @ 12244:665a28dffb7d

[XEND] Don't hide the 'type' SXP config item from HVM guests

Should allow network devices to properly initialised in HVM guests.

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Fri Nov 03 11:42:57 2006 +0000 (2006-11-03)
parents 43474e663b3d
children dc9246357cdb
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 #if !defined HAVE_LIBC
23 #include <os.h>
24 #include <types.h>
25 #include <lib.h>
26 #include <xmalloc.h>
28 int memcmp(const void * cs,const void * ct,size_t count)
29 {
30 const unsigned char *su1, *su2;
31 signed char res = 0;
33 for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
34 if ((res = *su1 - *su2) != 0)
35 break;
36 return res;
37 }
39 void * memcpy(void * dest,const void *src,size_t count)
40 {
41 char *tmp = (char *) dest;
42 const char *s = src;
44 while (count--)
45 *tmp++ = *s++;
47 return dest;
48 }
50 int strncmp(const char * cs,const char * ct,size_t count)
51 {
52 register signed char __res = 0;
54 while (count) {
55 if ((__res = *cs - *ct++) != 0 || !*cs++)
56 break;
57 count--;
58 }
60 return __res;
61 }
63 int strcmp(const char * cs,const char * ct)
64 {
65 register signed char __res;
67 while (1) {
68 if ((__res = *cs - *ct++) != 0 || !*cs++)
69 break;
70 }
72 return __res;
73 }
75 char * strcpy(char * dest,const char *src)
76 {
77 char *tmp = dest;
79 while ((*dest++ = *src++) != '\0')
80 /* nothing */;
81 return tmp;
82 }
84 char * strncpy(char * dest,const char *src,size_t count)
85 {
86 char *tmp = dest;
88 while (count-- && (*dest++ = *src++) != '\0')
89 /* nothing */;
91 return tmp;
92 }
94 void * memset(void * s,int c,size_t count)
95 {
96 char *xs = (char *) s;
98 while (count--)
99 *xs++ = c;
101 return s;
102 }
104 size_t strnlen(const char * s, size_t count)
105 {
106 const char *sc;
108 for (sc = s; count-- && *sc != '\0'; ++sc)
109 /* nothing */;
110 return sc - s;
111 }
114 char * strcat(char * dest, const char * src)
115 {
116 char *tmp = dest;
118 while (*dest)
119 dest++;
121 while ((*dest++ = *src++) != '\0');
123 return tmp;
124 }
126 size_t strlen(const char * s)
127 {
128 const char *sc;
130 for (sc = s; *sc != '\0'; ++sc)
131 /* nothing */;
132 return sc - s;
133 }
135 char * strchr(const char * s, int c)
136 {
137 for(; *s != (char) c; ++s)
138 if (*s == '\0')
139 return NULL;
140 return (char *)s;
141 }
143 char * strstr(const char * s1,const char * s2)
144 {
145 int l1, l2;
147 l2 = strlen(s2);
148 if (!l2)
149 return (char *) s1;
150 l1 = strlen(s1);
151 while (l1 >= l2) {
152 l1--;
153 if (!memcmp(s1,s2,l2))
154 return (char *) s1;
155 s1++;
156 }
157 return NULL;
158 }
160 char *strdup(const char *x)
161 {
162 int l = strlen(x);
163 char *res = malloc(l + 1);
164 if (!res) return NULL;
165 memcpy(res, x, l + 1);
166 return res;
167 }
169 #endif