4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
34 * PURPOSE: Operating System Dependent layer
36 * Provide OS dependent data structures & functions with
37 * a canonical DAT interface. Designed to be portable
38 * and hide OS specific quirks of common functions.
40 * $Id: dat_osd.h,v 1.14 2003/07/31 14:04:19 jlentini Exp $
46 #pragma ident "%Z%%M% %I% %E% SMI"
73 #define dat_os_assert(expr) assert(expr)
75 typedef int DAT_OS_DBG_TYPE_VAL
;
79 DAT_OS_DBG_TYPE_ERROR
= 0x1,
80 DAT_OS_DBG_TYPE_GENERIC
= 0x2,
81 DAT_OS_DBG_TYPE_SR
= 0x4,
82 DAT_OS_DBG_TYPE_DR
= 0x8,
83 DAT_OS_DBG_TYPE_PROVIDER_API
= 0x10,
84 DAT_OS_DBG_TYPE_CONSUMER_API
= 0x20,
85 DAT_OS_DBG_TYPE_ALL
= 0xff
89 dat_os_dbg_init(void);
93 DAT_OS_DBG_TYPE_VAL type
,
104 #define DAT_ERROR(Type, SubType) ((DAT_RETURN)(DAT_CLASS_ERROR | Type | \
107 typedef size_t DAT_OS_SIZE
;
108 typedef void * DAT_OS_LIBRARY_HANDLE
;
112 const char *library_path
,
113 DAT_OS_LIBRARY_HANDLE
*library_handle_ptr
);
116 dat_os_library_unload(
117 const DAT_OS_LIBRARY_HANDLE library_handle
);
120 * void *dat_os_library_sym(DAT_OS_LIBRARY_HANDLE library_handle, char *sym)
122 #define dat_os_library_sym(libhndl, sym) dlsym((libhndl), (sym))
124 /* char *dat_os_getenv(const char *name) */
125 #define dat_os_getenv(name) getenv((name))
127 /* long int dat_os_strtol(const char *nptr, char **endptr, int base) */
128 #define dat_os_strtol(nptr, endptr, base) strtol((nptr), (endptr), (base))
130 /* DAT_OS_SIZE dat_os_strlen(const char *s) */
131 #define dat_os_strlen(s) strlen((s))
133 /* int dat_os_strncmp(const char *s1, const char *s2, DAT_OS_SIZE n) */
134 #define dat_os_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
136 /* void * dat_os_strncpy(char *dest, const char *src, DAT_OS_SIZE len) */
137 #define dat_os_strncpy(dest, src, len) strncpy((dest), (src), (len))
139 /* DAT_BOOLEAN dat_os_isblank(int c) */
140 #define dat_os_isblank(c) ((DAT_BOOLEAN)((' ' == (c)) || ('\t' == (c))) \
141 ? DAT_TRUE : DAT_FALSE)
144 /* DAT_BOOLEAN dat_os_isdigit(int c) */
145 #define dat_os_isdigit(c) ((DAT_BOOLEAN)(isdigit((c)) ? DAT_TRUE : \
148 /* void dat_os_usleep(unsigned long usec) */
149 #define dat_os_usleep(usec) usleep((usec))
157 /* void *dat_os_alloc(int size) */
158 #define dat_os_alloc(size) malloc((size))
160 /* void dat_os_free(void *ptr, int size) */
161 #define dat_os_free(ptr, size) free((ptr))
163 /* void *dat_os_memset(void *loc, int c, DAT_OS_SIZE size) */
164 #define dat_os_memset(loc, c, size) memset((loc), (c), (size))
172 typedef FILE DAT_OS_FILE
;
173 typedef fpos_t DAT_OS_FILE_POS
;
176 * DAT_OS_FILE *dat_os_fopen(const char *path)
177 * always open files in read only mode
179 #define dat_os_fopen(path) ((DAT_OS_FILE *)fopen((path), "rF"))
182 /* DAT_RETURN dat_os_fgetpos(DAT_OS_FILE *file, DAT_OS_FILE_POS *pos) */
183 #define dat_os_fgetpos(file, pos) ((DAT_RETURN)( \
184 (0 == fgetpos((file), (pos))) ? DAT_SUCCESS : \
187 /* DAT_RETURN dat_os_fsetpos(DAT_OS_FILE *file, DAT_OS_FILE_POS *pos) */
188 #define dat_os_fsetpos(file, pos) ((DAT_RETURN)( \
189 (0 == fsetpos((file), (pos))) ? DAT_SUCCESS : \
193 * dat_os_fgetc() returns EOF on error or end of file.
194 * int dat_os_fgetc(DAT_OS_FILE *file)
196 #define dat_os_fgetc(file) fgetc((file))
199 /* int dat_os_fputc(DAT_OS_FILE *file, int c) */
200 #define dat_os_fputc(file, c) fputc((c), (file))
202 /* int dat_os_fungetc(DAT_OS_FILE *file) */
203 #define dat_os_fungetc(file) fseek((file), -1, SEEK_CUR)
206 * dat_os_fread returns the number of bytes read from the file.
207 * DAT_OS_SIZE dat_os_fread(DAT_OS_FILE *file, char *buf, DAT_OS_SIZE len)
209 #define dat_os_fread(file, buf, len) fread((buf), sizeof (char), \
212 /* DAT_RETURN dat_os_fclose(DAT_OS_FILE *file) */
213 #define dat_os_fclose(file) ((0 == fclose(file)) ? DAT_SUCCESS : \
222 typedef pthread_mutex_t DAT_OS_LOCK
;
227 * DAT_RETURN dat_os_lock_init(IN DAT_OS_LOCK *m)
229 #define dat_os_lock_init(m) ((0 == pthread_mutex_init((m), NULL)) ? \
230 DAT_SUCCESS : DAT_INTERNAL_ERROR)
232 /* DAT_RETURN dat_os_lock(IN DAT_OS_LOCK *m) */
233 #define dat_os_lock(m) ((DAT_RETURN)( \
234 (0 == pthread_mutex_lock((m))) ? \
235 DAT_SUCCESS : DAT_INTERNAL_ERROR))
237 /* DAT_RETURN dat_os_unlock(IN DAT_OS_LOCK *m) */
238 #define dat_os_unlock(m) ((DAT_RETURN)( \
239 (0 == pthread_mutex_unlock((m))) ? \
240 DAT_SUCCESS : DAT_INTERNAL_ERROR))
242 /* DAT_RETURN dat_os_lock_destroy(IN DAT_OS_LOCK *m) */
243 #define dat_os_lock_destroy(m) ((DAT_RETURN)( \
244 (0 == pthread_mutex_destroy((m))) ? \
245 DAT_SUCCESS : DAT_INTERNAL_ERROR))
248 * Simple macro to verify a handle is bad. Conditions:
250 * - pointer is not word aligned
252 #define DAT_BAD_HANDLE(h) (((h) == NULL) || ((unsigned long)(h) & 3))
258 #endif /* _DAT_OSD_H_ */