direct-io.hg

view extras/mini-os/lib/string.c @ 7987:17b98e15bf78

Fix __gpfn_to_mfn() to work correctly when not executed
in the queried domain's context.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Nov 23 13:58:44 2005 +0100 (2005-11-23)
parents 06d84bf87159
children b049fb947f2a
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 }
111 char * strcat(char * dest, const char * src)
112 {
113 char *tmp = dest;
115 while (*dest)
116 dest++;
118 while ((*dest++ = *src++) != '\0');
120 return tmp;
121 }
123 size_t strlen(const char * s)
124 {
125 const char *sc;
127 for (sc = s; *sc != '\0'; ++sc)
128 /* nothing */;
129 return sc - s;
130 }
132 char * strchr(const char * s, int c)
133 {
134 for(; *s != (char) c; ++s)
135 if (*s == '\0')
136 return NULL;
137 return (char *)s;
138 }
140 char * strstr(const char * s1,const char * s2)
141 {
142 int l1, l2;
144 l2 = strlen(s2);
145 if (!l2)
146 return (char *) s1;
147 l1 = strlen(s1);
148 while (l1 >= l2) {
149 l1--;
150 if (!memcmp(s1,s2,l2))
151 return (char *) s1;
152 s1++;
153 }
154 return NULL;
155 }