ia64/xen-unstable

annotate extras/mini-os/include/lib.h @ 16838:945820bfedb6

minios: POSIX fixes
Fixes some functions which are POSIX. Also make them ifndef HAVE_LIBC.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jan 22 14:20:22 2008 +0000 (2008-01-22)
parents 10101bc8181f
children 01e178f7ec6d
rev   line source
kaf24@5675 1 /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*-
kaf24@5675 2 ****************************************************************************
kaf24@5675 3 * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
kaf24@5675 4 ****************************************************************************
kaf24@5675 5 *
kaf24@5675 6 * File: lib.h
kaf24@5675 7 * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
kaf24@5675 8 * Changes:
kaf24@5675 9 *
kaf24@5675 10 * Date: Aug 2003
kaf24@5675 11 *
kaf24@5675 12 * Environment: Xen Minimal OS
kaf24@5675 13 * Description: Random useful library functions, contains some freebsd stuff
kaf24@5675 14 *
kaf24@5675 15 ****************************************************************************
kaf24@5675 16 * $Id: h-insert.h,v 1.4 2002/11/08 16:03:55 rn Exp $
kaf24@5675 17 ****************************************************************************
kaf24@5675 18 *
kaf24@5675 19 *-
kaf24@5675 20 * Copyright (c) 1991, 1993
kaf24@5675 21 * The Regents of the University of California. All rights reserved.
kaf24@5675 22 *
kaf24@5675 23 * Redistribution and use in source and binary forms, with or without
kaf24@5675 24 * modification, are permitted provided that the following conditions
kaf24@5675 25 * are met:
kaf24@5675 26 * 1. Redistributions of source code must retain the above copyright
kaf24@5675 27 * notice, this list of conditions and the following disclaimer.
kaf24@5675 28 * 2. Redistributions in binary form must reproduce the above copyright
kaf24@5675 29 * notice, this list of conditions and the following disclaimer in the
kaf24@5675 30 * documentation and/or other materials provided with the distribution.
kaf24@5675 31 * 3. All advertising materials mentioning features or use of this software
kaf24@5675 32 * must display the following acknowledgement:
kaf24@5675 33 * This product includes software developed by the University of
kaf24@5675 34 * California, Berkeley and its contributors.
kaf24@5675 35 * 4. Neither the name of the University nor the names of its contributors
kaf24@5675 36 * may be used to endorse or promote products derived from this software
kaf24@5675 37 * without specific prior written permission.
kaf24@5675 38 *
kaf24@5675 39 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
kaf24@5675 40 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
kaf24@5675 41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
kaf24@5675 42 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
kaf24@5675 43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
kaf24@5675 44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
kaf24@5675 45 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
kaf24@5675 46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
kaf24@5675 47 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
kaf24@5675 48 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
kaf24@5675 49 * SUCH DAMAGE.
kaf24@5675 50 *
kaf24@5675 51 * @(#)stdarg.h 8.1 (Berkeley) 6/10/93
kaf24@5675 52 * $FreeBSD: src/sys/i386/include/stdarg.h,v 1.10 1999/08/28 00:44:26 peter Exp $
kaf24@5675 53 */
kaf24@5675 54
kaf24@5675 55 #ifndef _LIB_H_
kaf24@5675 56 #define _LIB_H_
kaf24@5675 57
kaf24@5675 58 #include <stdarg.h>
kaf24@9932 59 #include <stddef.h>
kaf24@9298 60 #include <console.h>
kaf24@9208 61
keir@16838 62 #ifdef HAVE_LIBC
keir@16838 63 #include <stdio.h>
keir@16838 64 #else
kaf24@5675 65 /* printing */
kaf24@6714 66 #define _p(_x) ((void *)(unsigned long)(_x))
kaf24@6714 67 int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
kaf24@6714 68 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
kaf24@6714 69 int snprintf(char * buf, size_t size, const char *fmt, ...);
kaf24@6714 70 int scnprintf(char * buf, size_t size, const char *fmt, ...);
kaf24@6714 71 int vsprintf(char *buf, const char *fmt, va_list args);
kaf24@6714 72 int sprintf(char * buf, const char *fmt, ...);
kaf24@6714 73 int vsscanf(const char * buf, const char * fmt, va_list args);
kaf24@6714 74 int sscanf(const char * buf, const char * fmt, ...);
keir@16838 75 #endif
kaf24@6714 76
kaf24@6714 77 long simple_strtol(const char *cp,char **endp,unsigned int base);
kaf24@6714 78 unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base);
kaf24@6714 79 long long simple_strtoll(const char *cp,char **endp,unsigned int base);
kaf24@6714 80 unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base);
kaf24@6714 81
keir@16838 82 #ifdef HAVE_LIBC
keir@16838 83 #include <string.h>
keir@16838 84 #else
kaf24@5675 85 /* string and memory manipulation */
kaf24@5675 86 int memcmp(const void *cs, const void *ct, size_t count);
kaf24@5675 87 void *memcpy(void *dest, const void *src, size_t count);
kaf24@5675 88 int strncmp(const char *cs, const char *ct, size_t count);
kaf24@5675 89 int strcmp(const char *cs, const char *ct);
kaf24@5675 90 char *strcpy(char *dest, const char *src);
kaf24@5675 91 char *strncpy(char *dest, const char *src, size_t count);
kaf24@5675 92 void *memset(void *s,int c, size_t count);
kaf24@5675 93 size_t strnlen(const char *s, size_t count);
kaf24@5675 94 size_t strlen(const char *s);
kaf24@5675 95 char *strchr(const char *s, int c);
keir@16439 96 char *strrchr(const char *s, int c);
kaf24@5675 97 char *strstr(const char *s1, const char *s2);
kaf24@6714 98 char * strcat(char * dest, const char * src);
kfraser@10652 99 char *strdup(const char *s);
keir@16838 100 #endif
kaf24@6714 101
keir@16838 102 #define RAND_MIX 2654435769U
keir@16838 103
keir@16838 104 int rand(void);
kaf24@6714 105
kaf24@6714 106 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
kaf24@6714 107
kaf24@6714 108 struct kvec {
kaf24@6714 109 void *iov_base;
kaf24@6714 110 size_t iov_len;
kaf24@6714 111 };
kaf24@6714 112
kfraser@10652 113 #define ASSERT(x) \
kfraser@10652 114 do { \
kfraser@10652 115 if (!(x)) { \
kfraser@10652 116 printk("ASSERTION FAILED: %s at %s:%d.\n", \
kfraser@10652 117 # x , \
kfraser@10652 118 __FILE__, \
kfraser@10652 119 __LINE__); \
kfraser@10652 120 BUG(); \
kfraser@10652 121 } \
kfraser@10652 122 } while(0)
kaf24@5675 123
keir@16733 124 #define BUG_ON(x) ASSERT(!(x))
keir@16733 125
kfraser@10652 126 /* Consistency check as much as possible. */
kfraser@10652 127 void sanity_check(void);
kaf24@5675 128
kaf24@5675 129 #endif /* _LIB_H_ */