Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch/i386/libsa/libsa.h

1/*
2 * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 2.0 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25#ifndef __BOOT_LIBSA_H
26#define __BOOT_LIBSA_H
27
28/* Exported API for standalone library */
29
30#include <mach-o/loader.h>
31#include <stdarg.h>
32#include <stddef.h>
33#include <stdbool.h>
34
35/*
36 * ctype stuff (aserebln)
37 */
38static inline int isupper(int c)
39{
40return (c >= 'A' && c <= 'Z');
41}
42
43static inline int islower(int c)
44{
45return (c >= 'a' && c <= 'z');
46}
47
48static inline int isalpha(int c)
49{
50return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
51}
52
53static inline int isascii(int c)
54{
55return ( (c >= 0x20) && (c < 0x7f) );
56}
57
58static inline int isspace(int c)
59{
60return (c == ' ' || c == '\t' || c == '\n' || c == '\12');
61}
62
63static inline int isdigit(int c)
64{
65return (c >= '0' && c <= '9');
66}
67
68static inline int isxdigit(int c)
69{
70return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'));
71}
72
73static inline int ispunct(int c)
74{
75return (c == '.' || c == '-');
76}
77
78/*
79 * string.c
80 */
81#ifndef bcopy
82extern void bcopy(const void * src, void * dst, size_t len);
83#endif
84
85#ifndef bzero
86extern void bzero(void * dst, size_t len);
87extern void __bzero(void * dst, size_t len);
88#else
89#error bzero is defined.
90#endif
91
92extern void*memset(void * dst, int c, size_t n);
93extern void*memcpy(void * dst, const void * src, size_t len);
94extern intmemcmp(const void * p1, const void * p2, size_t len);
95extern intstrcmp(const char * s1, const char * s2);
96extern intstrncmp(const char * s1, const char * s2, size_t n);
97extern char*strcpy(char * s1, const char * s2);
98extern char*stpcpy(char * s1, const char * s2);
99extern char*strncpy(char * s1, const char * s2, size_t n);
100extern char*strpcpy(char * s1, const char * s2, size_t n);
101extern size_tstrlcpy(char * s1, const char * s2, size_t n);
102extern char*strstr(const char *in, const char *str);
103extern intatoi(const char * str);
104extern intptol(const char * str);
105extern size_tstrlen(const char * str);
106extern size_tstrlcat(char *, const char *, size_t);
107extern char*strcat(char * s1, const char * s2);
108extern char*strncat(char * s1, const char * s2, size_t n);
109extern char*strdup(const char *s1);
110
111extern char*strpbrk_c(const char *s, const char *accept);
112extern char*strsep_c(char **stringp, const char *delim);
113extern size_t__strxspn_c(const char *s, const char *map, int parity);
114
115#if STRNCASECMP
116extern int strncasecmp(const char *s1, const char *s2, size_t n);
117#endif
118
119extern char *strchr(const char *str, int c);
120extern char *strbreak(const char *str, char **next, long *len);
121
122extern uint8_t checksum8( void * start, unsigned int length );
123
124/*
125 * error.c
126 */
127extern interrno;
128extern char*strerror(int errnum);
129
130/*
131 * strtol.c
132 */
133extern long strtol(const char *nptr, char **endptr, int base);
134extern unsigned long strtoul(const char *nptr, char **endptr, int base);
135extern unsigned long long strtouq(const char *nptr, char **endptr, int base);
136
137/*
138 * prf.c
139 */
140extern void prf(const char *fmt, va_list ap, int (*putfn_p)(), void *putfn_arg);
141
142/*
143 * printf.c
144 */
145extern int sprintf(char *s, const char *format, ...) __attribute__((format(printf,2,3)));
146extern int snprintf(char *s, size_t size, const char *format, ...) __attribute__((format(printf,3,4)));
147extern int slvprintf(char *buffer, int len, const char *fmt, va_list arg);
148
149/*
150 * zalloc.c
151 */
152#define malloc(size) safe_malloc(size, __FILE__, __LINE__)
153extern voidmalloc_init(char *start, int size, int nodes, void (*malloc_error)(char *, size_t, const char *, int));
154extern void*safe_malloc(size_t size,const char *file, int line);
155extern voidfree(void *start);
156extern void*realloc(void *ptr, size_t size);
157
158/*
159 * getsegbyname.c
160 */
161extern struct segment_command *getsegbynamefromheader(struct mach_header *mhp, char *segname);
162
163/*
164 * interrupts.c
165 */
166#ifdef __i386__
167extern int SetupInterrupts(void);
168static inline void EnableInterrupts(void) { __asm__ volatile ("sti"); }
169static inline void DisableInterrupts(void) { __asm__ volatile ("cli"); }
170extern void ShowInterruptCounters(void);
171#else
172static inline int SetupInterrupts(void) { return 0; }
173static inline void EnableInterrupts(void) { }
174static inline void DisableInterrupts(void) { }
175static inline void ShowInterruptCounters(void) { }
176#endif
177
178#endif /* !__BOOT_LIBSA_H */
179

Archive Download this file

Revision: 2837