VIA - Volumetric Image Analysis
os.h
1 /*
2  * $Id: os.h 726 2004-03-08 13:12:45Z lohmann $
3  *
4  * This header file tries to establish an environment containing the
5  * ANSI C, POSIX, and X/Open features that Vista relies on.
6  *
7  * In a Standard C Conforming POSIX environment it is equivalent to
8  * including: <float.h> <limits.h> <stdarg.h> <stdio.h> <stdlib.h>
9  * <string.h> <time.h> <unistd.h>
10  *
11  * This file requires an ANSI C compiler.
12  */
13 
14 #ifndef V_os_h
15 #define V_os_h 1
16 
17 /*
18  * Copyright 1994 University of British Columbia
19  *
20  * Permission to use, copy, modify, distribute, and sell this software and its
21  * documentation for any purpose is hereby granted without fee, provided that
22  * the above copyright notice appears in all copies and that both that
23  * copyright notice and this permission notice appear in supporting
24  * documentation. UBC makes no representations about the suitability of this
25  * software for any purpose. It is provided "as is" without express or
26  * implied warranty.
27  *
28  * Author: Arthur Pope, UBC Laboratory for Computational Intelligence
29  */
30 
31 
32 /*
33  * Only supports ANSI C.
34  */
35 
36 #ifndef __STDC__
37 #error __FILE__ requires an ANSI C compiler
38 #endif
39 
40 
41 /*
42  * Header files that are on all platforms of interest.
43  */
44 
45 #define _XOPEN_SOURCE
46 
47 #include <limits.h>
48 #include <stdarg.h>
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <string.h>
52 #include <time.h>
53 #include <unistd.h>
54 
55 
56 /*
57  * Determine what platform we're on.
58  */
59 
60 #undef SunOS_4
61 #undef SunOS_5
62 #if defined (sun) || defined (__sun)
63 #ifdef SVR4
64  #define SunOS_5
65 #else
66  #define SunOS_4
67 #endif
68 #endif
69 
70 
71 /*
72  * Platform-specific definitions and header inclusions to get us
73  * up to ANSI C and POSIX.
74  */
75 
76 /* Define limits for floating point numbers, normally in <float.h>: */
77 #if defined (SunOS_4) /* SunOS 4.1 */
78  #define DBL_MAX (1.797693134862315708e+308)
79  #define FLT_MAX ((float)3.40282346638528860e+38)
80 #else /* ANSI C library */
81  #include <float.h>
82 #endif
83 
84 /* Define maximum number of bytes in pathname, normally in <limits.h>: */
85 #if defined (SunOS_4) && ! defined (PATH_MAX) /* SunOS 4.1 */
86  #define PATH_MAX _POSIX_PATH_MAX
87 #endif
88 
89 /* Define function prototypes that are normally in <stdio.h>: */
90 #if defined (SunOS_4)
91  extern int _filbuf (FILE *);
92  extern int fclose (FILE *);
93  extern int fflush (FILE *);
94  extern int fgetc (FILE *);
95  extern int fprintf (FILE *, const char *, ...);
96  extern int fputc (int, FILE *);
97  extern int fputs (const char *, FILE *);
98  extern size_t fread (void *, size_t, size_t, FILE *);
99  extern int fscanf (FILE *, const char *, ...);
100  extern int fseek (FILE *, long int, int);
101  extern size_t fwrite (const void *, size_t, size_t, FILE *);
102  extern int printf (const char *, ...);
103  extern void rewind (FILE *);
104  extern int scanf (const char *, ...);
105 /* extern int sprintf (char *, const char *, ...); */
106  extern int sscanf (const char *, const char *, ...);
107  extern int ungetc (int, FILE *);
108  extern int vsprintf (char *, const char *, va_list);
109 #endif
110 
111 /* Define EXIT_SUCCESS, EXIT_FAILURE, which are normally in <stdlib.h>: */
112 #if defined (SunOS_4) /* SunOS 4.1 */
113  #define EXIT_SUCCESS 0
114  #define EXIT_FAILURE 1
115 #endif
116 
117 /* Get a definitions of strtox, which are normally in <stdlib.h>: */
118 #if defined (SunOS_4) /* SunOS 4.1 */
119  extern double strtod (const char *, char **);
120  extern long strtol (const char *, char **, int);
121 #endif
122 
123 /* Define strerror(), which is normally in <string.h>: */
124 #if defined (SunOS_4) /* SunOS 4.1 */
125  extern int sys_nerr;
126  extern char *sys_errlist[];
127  #define strerror(e) ((e) >= sys_nerr ? "Unknown" : sys_errlist[e])
128 #endif
129 
130 /* Define memcpy(), etc., which are normally in <string.h>: */
131 #if defined (SunOS_4) /* SunOS 4.1 */
132  extern void *memchr (const void *, int, size_t);
133  extern int memcmp (const void *, const void *, size_t);
134  extern void *memcpy (void *, const void *, size_t);
135  extern void *memmove (void *, const void *, size_t);
136  extern void *memset (void *, int, size_t);
137 #endif
138 
139 /* Get a definition of time(), which is normally in <time.h>: */
140 #if defined (SunOS_4) /* SunOS 4.1 */
141  extern time_t time (time_t *);
142 #endif
143 
144 
145 /*
146  * Definition of a random number generator.
147  *
148  * On systems that have drand48(), use it; otherwise use rand().
149  */
150 
151 #if defined (sun) || defined (sgi) || defined (_XPG4)
152  extern void srand48 (long);
153  extern double drand48 (void);
154  extern long mrand48 (void);
155  #define VRandomSeed(seed) srand48 ((long) seed)
156  #define VRandomDouble() ((VDouble) drand48 ())
157  #define VRandomLong() ((VLong) mrand48 ())
158 #else
159  #define VRandomSeed(seed) srand ((int) seed)
160  #ifdef RAND_MAX
161  #define VRandomDouble() ((unsigned int) rand () / (VDouble) RAND_MAX+1)
162  #else
163  #define VRandomDouble() ((unsigned int) rand () / (VDouble) 0x80000000)
164  #endif
165  #define VRandomLong() ((VLong) rand())
166 #endif
167 
168 
169 /*
170  * Other useful definitions.
171  */
172 
173 /* Include an identifying string in an object file without causing
174  `unused variable' warnings: */
175 #define VRcsId(str) static char *rcsid = (0 ? (char *) & rcsid : (str))
176 
177 
178 #endif /* V_Vos_h */