~ubuntu-branches/ubuntu/intrepid/xen-3.3/intrepid-updates

« back to all changes in this revision

Viewing changes to tools/vnet/libxutil/sys_string.h

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2008-08-14 10:28:57 UTC
  • Revision ID: james.westby@ubuntu.com-20080814102857-a832fn5gowurz5do
Tags: upstream-3.3.0
ImportĀ upstreamĀ versionĀ 3.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
18
 
 
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__
 
27
 
 
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"
 
34
 
 
35
extern char *strerror(int err);
 
36
 
 
37
#if 0
 
38
static inline int tolower(int c){
 
39
    return (c>='A' && c<='Z' ? (c-'A')+'a' : c);
 
40
}
 
41
#endif
 
42
 
 
43
static inline int isalpha(int c){
 
44
    return (c>='A' && c<='Z') || (c>='a' && c<='z');
 
45
}
 
46
 
 
47
static inline int isdigit(int c){
 
48
   return (c>='0' && c<='9');
 
49
}
 
50
 
 
51
#if 0
 
52
static inline int strcasecmp(const char *s1, const char *s2){
 
53
        int c1, c2;
 
54
 
 
55
        do {
 
56
                c1 = tolower(*s1++);
 
57
                c2 = tolower(*s2++);
 
58
        } while (c1 && c1 == c2);
 
59
        return c1 - c2;
 
60
}
 
61
#endif
 
62
 
 
63
static inline char * strdup(const char *s){
 
64
    int n = (s ? 1+strlen(s) : 0);
 
65
    char *copy = (n ? allocate(n) : NULL);
 
66
    if(copy){
 
67
        strcpy(copy, s);
 
68
    }
 
69
    return copy;
 
70
}
 
71
 
 
72
/*============================================================================*/
 
73
#else
 
74
#include <string.h>
 
75
#include <stdio.h>
 
76
 
 
77
#ifndef _GNU_SOURCE
 
78
static inline size_t strnlen(const char *s, size_t n){
 
79
    int k = 0;
 
80
    if(s){
 
81
        for(k=0; *s && k<n; s++, k++){}
 
82
    }
 
83
    return k;
 
84
}
 
85
#endif
 
86
 
 
87
#endif
 
88
/*============================================================================*/
 
89
 
 
90
extern int convert_atoul(const char *s, unsigned long *v);
 
91
extern int convert_atol(const char *s, long *v);
 
92
extern int path_concat(char *s, char *t, char **val);
 
93
 
 
94
#endif /* !_XUTIL_SYS_STRING_H_ */