ia64/xen-unstable

view tools/libxutil/sys_string.h @ 2621:9402048e2325

bitkeeper revision 1.1159.1.218 (416a8128OiHXHyk_Sy8FsA0YUQcEnA)

Merge freefall.cl.cam.ac.uk:/auto/groups/xeno/users/cl349/BK/xeno.bk-26dom0
into freefall.cl.cam.ac.uk:/local/scratch/cl349/xeno.bk-26dom0
author cl349@freefall.cl.cam.ac.uk
date Mon Oct 11 12:48:40 2004 +0000 (2004-10-11)
parents 0e23f01219c6
children 7f7c68433c4c
line source
1 /*
2 * Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
3 *
4 * This library is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
19 #ifndef _XUTIL_SYS_STRING_H_
20 #define _XUTIL_SYS_STRING_H_
21 /** @file
22 * Replacement for standard string includes.
23 * Works in user or kernel code.
24 */
25 /*============================================================================*/
26 #ifdef __KERNEL__
28 #include <linux/config.h>
29 #include <linux/kernel.h>
30 #include <linux/string.h>
31 #include <linux/types.h>
32 #include <stdarg.h>
33 #include "allocate.h"
35 #if 0
36 static inline int tolower(int c){
37 return (c>='A' && c<='Z' ? (c-'A')+'a' : c);
38 }
39 #endif
41 static inline int isalpha(int c){
42 return (c>='A' && c<='Z') || (c>='a' && c<='z');
43 }
45 static inline int isdigit(int c){
46 return (c>='0' && c<='9');
47 }
49 #if 0
50 static inline int strcasecmp(const char *s1, const char *s2){
51 int c1, c2;
53 do {
54 c1 = tolower(*s1++);
55 c2 = tolower(*s2++);
56 } while (c1 && c1 == c2);
57 return c1 - c2;
58 }
59 #endif
61 static inline char * strdup(const char *s){
62 int n = (s ? 1+strlen(s) : 0);
63 char *copy = (n ? allocate(n) : NULL);
64 if(copy){
65 strcpy(copy, s);
66 }
67 return copy;
68 }
70 /*============================================================================*/
71 #else
72 #include <string.h>
73 #include <stdio.h>
75 #ifndef _GNU_SOURCE
76 static inline size_t strnlen(const char *s, size_t n){
77 int k = 0;
78 if(s){
79 for(k=0; *s && k<n; s++, k++){}
80 }
81 return k;
82 }
83 #endif
85 #endif
86 /*============================================================================*/
88 extern int convert_atoul(const char *s, unsigned long *v);
89 extern int path_concat(char *s, char *t, char **val);
91 #endif /* !_XUTIL_SYS_STRING_H_ */