ia64/xen-unstable

view extras/mini-os/lib/string.c @ 18811:390ef36eb596

Remove Xen-private definitions from kexec public header.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Nov 19 13:13:39 2008 +0000 (2008-11-19)
parents 74bd94747ca3
children 878e4c128991
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 * strrchr(const char * s, int c)
144 {
145 const char *res = NULL;
146 for(; *s != '\0'; ++s)
147 if (*s == (char) c)
148 res = s;
149 return (char *)res;
150 }
152 char * strstr(const char * s1,const char * s2)
153 {
154 int l1, l2;
156 l2 = strlen(s2);
157 if (!l2)
158 return (char *) s1;
159 l1 = strlen(s1);
160 while (l1 >= l2) {
161 l1--;
162 if (!memcmp(s1,s2,l2))
163 return (char *) s1;
164 s1++;
165 }
166 return NULL;
167 }
169 char *strdup(const char *x)
170 {
171 int l = strlen(x);
172 char *res = malloc(l + 1);
173 if (!res) return NULL;
174 memcpy(res, x, l + 1);
175 return res;
176 }
178 #endif