ia64/xen-unstable

view extras/mini-os/include/lib.h @ 19790:01ad2654815a

minios: Use posix_openpt() rather than non-standard openpty().

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 18 10:19:25 2009 +0100 (2009-06-18)
parents 11d8ca329b54
children
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: lib.h
7 * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
8 * Changes:
9 *
10 * Date: Aug 2003
11 *
12 * Environment: Xen Minimal OS
13 * Description: Random useful library functions, contains some freebsd stuff
14 *
15 ****************************************************************************
16 * $Id: h-insert.h,v 1.4 2002/11/08 16:03:55 rn Exp $
17 ****************************************************************************
18 *
19 *-
20 * Copyright (c) 1991, 1993
21 * The Regents of the University of California. All rights reserved.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * This product includes software developed by the University of
34 * California, Berkeley and its contributors.
35 * 4. Neither the name of the University nor the names of its contributors
36 * may be used to endorse or promote products derived from this software
37 * without specific prior written permission.
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
40 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
45 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
48 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49 * SUCH DAMAGE.
50 *
51 * @(#)stdarg.h 8.1 (Berkeley) 6/10/93
52 * $FreeBSD: src/sys/i386/include/stdarg.h,v 1.10 1999/08/28 00:44:26 peter Exp $
53 */
55 #ifndef _LIB_H_
56 #define _LIB_H_
58 #include <stdarg.h>
59 #include <stddef.h>
60 #include <xen/xen.h>
61 #include <xen/event_channel.h>
62 #include "gntmap.h"
64 #ifdef HAVE_LIBC
65 #include <stdio.h>
66 #else
67 /* printing */
68 #define _p(_x) ((void *)(unsigned long)(_x))
69 int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
70 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
71 int snprintf(char * buf, size_t size, const char *fmt, ...);
72 int scnprintf(char * buf, size_t size, const char *fmt, ...);
73 int vsprintf(char *buf, const char *fmt, va_list args);
74 int sprintf(char * buf, const char *fmt, ...);
75 int vsscanf(const char * buf, const char * fmt, va_list args);
76 int sscanf(const char * buf, const char * fmt, ...);
77 #endif
79 long simple_strtol(const char *cp,char **endp,unsigned int base);
80 unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base);
81 long long simple_strtoll(const char *cp,char **endp,unsigned int base);
82 unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base);
84 #ifdef HAVE_LIBC
85 #include <string.h>
86 #else
87 /* string and memory manipulation */
88 int memcmp(const void *cs, const void *ct, size_t count);
89 void *memcpy(void *dest, const void *src, size_t count);
90 int strncmp(const char *cs, const char *ct, size_t count);
91 int strcmp(const char *cs, const char *ct);
92 char *strcpy(char *dest, const char *src);
93 char *strncpy(char *dest, const char *src, size_t count);
94 void *memset(void *s,int c, size_t count);
95 size_t strnlen(const char *s, size_t count);
96 size_t strlen(const char *s);
97 char *strchr(const char *s, int c);
98 char *strrchr(const char *s, int c);
99 char *strstr(const char *s1, const char *s2);
100 char * strcat(char * dest, const char * src);
101 char *strdup(const char *s);
102 #endif
103 #include <mini-os/console.h>
105 #define RAND_MIX 2654435769U
107 int rand(void);
109 #include <mini-os/xenbus.h>
111 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
113 struct kvec {
114 void *iov_base;
115 size_t iov_len;
116 };
118 #define ASSERT(x) \
119 do { \
120 if (!(x)) { \
121 printk("ASSERTION FAILED: %s at %s:%d.\n", \
122 # x , \
123 __FILE__, \
124 __LINE__); \
125 BUG(); \
126 } \
127 } while(0)
129 #define BUG_ON(x) ASSERT(!(x))
131 /* Consistency check as much as possible. */
132 void sanity_check(void);
134 #ifdef HAVE_LIBC
135 enum fd_type {
136 FTYPE_NONE = 0,
137 FTYPE_CONSOLE,
138 FTYPE_FILE,
139 FTYPE_XENBUS,
140 FTYPE_XC,
141 FTYPE_EVTCHN,
142 FTYPE_GNTMAP,
143 FTYPE_SOCKET,
144 FTYPE_TAP,
145 FTYPE_BLK,
146 FTYPE_KBD,
147 FTYPE_FB,
148 };
150 #define MAX_EVTCHN_PORTS 16
152 extern struct file {
153 enum fd_type type;
154 union {
155 struct {
156 /* lwIP fd */
157 int fd;
158 } socket;
159 struct {
160 /* FS import fd */
161 int fd;
162 off_t offset;
163 } file;
164 struct {
165 /* To each event channel FD is associated a series of ports which
166 * wakes select for this FD. */
167 struct {
168 evtchn_port_t port;
169 unsigned long pending;
170 int bound;
171 } ports[MAX_EVTCHN_PORTS];
172 } evtchn;
173 struct gntmap gntmap;
174 struct {
175 struct netfront_dev *dev;
176 } tap;
177 struct {
178 struct blkfront_dev *dev;
179 } blk;
180 struct {
181 struct kbdfront_dev *dev;
182 } kbd;
183 struct {
184 struct fbfront_dev *dev;
185 } fb;
186 struct {
187 struct consfront_dev *dev;
188 } cons;
189 struct {
190 /* To each xenbus FD is associated a queue of watch events for this
191 * FD. */
192 xenbus_event_queue events;
193 } xenbus;
194 };
195 int read; /* maybe available for read */
196 } files[];
198 int alloc_fd(enum fd_type type);
199 void close_all_files(void);
200 extern struct thread *main_thread;
201 void sparse(unsigned long data, size_t size);
202 #endif
204 #endif /* _LIB_H_ */