VIA - Volumetric Image Analysis

os.h

00001 /*
00002  *  $Id: os.h 726 2004-03-08 13:12:45Z lohmann $
00003  *
00004  *  This header file tries to establish an environment containing the
00005  *  ANSI C, POSIX, and X/Open features that Vista relies on.
00006  *
00007  *  In a Standard C Conforming POSIX environment it is equivalent to
00008  *  including:  <float.h> <limits.h> <stdarg.h> <stdio.h> <stdlib.h>
00009  *              <string.h> <time.h> <unistd.h>
00010  *
00011  *  This file requires an ANSI C compiler.
00012  */
00013 
00014 #ifndef V_os_h
00015 #define V_os_h 1
00016 
00017 /*
00018  *  Copyright 1994 University of British Columbia
00019  *
00020  *  Permission to use, copy, modify, distribute, and sell this software and its
00021  *  documentation for any purpose is hereby granted without fee, provided that
00022  *  the above copyright notice appears in all copies and that both that
00023  *  copyright notice and this permission notice appear in supporting
00024  *  documentation. UBC makes no representations about the suitability of this
00025  *  software for any purpose. It is provided "as is" without express or
00026  *  implied warranty.
00027  *
00028  *  Author: Arthur Pope, UBC Laboratory for Computational Intelligence
00029  */
00030 
00031 
00032 /*
00033  *  Only supports ANSI C.
00034  */
00035 
00036 #ifndef __STDC__
00037 #error __FILE__ requires an ANSI C compiler
00038 #endif
00039 
00040 
00041 /*
00042  *  Header files that are on all platforms of interest.
00043  */
00044 
00045 #define _XOPEN_SOURCE
00046 
00047 #include <limits.h>
00048 #include <stdarg.h>
00049 #include <stdio.h>
00050 #include <stdlib.h>
00051 #include <string.h>
00052 #include <time.h>
00053 #include <unistd.h>
00054 
00055 
00056 /*
00057  *  Determine what platform we're on.
00058  */
00059 
00060 #undef SunOS_4
00061 #undef SunOS_5
00062 #if defined (sun) || defined (__sun)
00063 #ifdef SVR4
00064   #define SunOS_5
00065 #else
00066   #define SunOS_4
00067 #endif
00068 #endif
00069 
00070 
00071 /*
00072  *  Platform-specific definitions and header inclusions to get us
00073  *  up to ANSI C and POSIX.
00074  */
00075 
00076 /* Define limits for floating point numbers, normally in <float.h>: */
00077 #if defined (SunOS_4)                                   /* SunOS 4.1 */
00078   #define DBL_MAX (1.797693134862315708e+308)
00079   #define FLT_MAX ((float)3.40282346638528860e+38)
00080 #else                                                   /* ANSI C library */
00081   #include <float.h>
00082 #endif
00083 
00084 /* Define maximum number of bytes in pathname, normally in <limits.h>: */
00085 #if defined (SunOS_4) && ! defined (PATH_MAX)           /* SunOS 4.1 */
00086   #define PATH_MAX _POSIX_PATH_MAX
00087 #endif
00088 
00089 /* Define function prototypes that are normally in <stdio.h>: */
00090 #if defined (SunOS_4)
00091   extern int _filbuf (FILE *);
00092   extern int fclose (FILE *);
00093   extern int fflush (FILE *);
00094   extern int fgetc (FILE *);
00095   extern int fprintf (FILE *, const char *, ...);
00096   extern int fputc (int, FILE *);
00097   extern int fputs (const char *, FILE *);
00098   extern size_t fread (void *, size_t, size_t, FILE *);
00099   extern int fscanf (FILE *, const char *, ...);
00100   extern int fseek (FILE *, long int, int);
00101   extern size_t fwrite (const void *, size_t, size_t, FILE *);
00102   extern int printf (const char *, ...);
00103   extern void rewind (FILE *);
00104   extern int scanf (const char *, ...);
00105 /* extern int sprintf (char *, const char *, ...); */
00106   extern int sscanf (const char *, const char *, ...);
00107   extern int ungetc (int, FILE *);
00108   extern int vsprintf (char *, const char *, va_list);
00109 #endif
00110 
00111 /* Define EXIT_SUCCESS, EXIT_FAILURE, which are normally in <stdlib.h>: */
00112 #if defined (SunOS_4)                                   /* SunOS 4.1 */
00113   #define EXIT_SUCCESS 0
00114   #define EXIT_FAILURE 1
00115 #endif
00116 
00117 /* Get a definitions of strtox, which are normally in <stdlib.h>: */
00118 #if defined (SunOS_4)                                   /* SunOS 4.1 */
00119   extern double strtod (const char *, char **);
00120   extern long strtol (const char *, char **, int);
00121 #endif
00122 
00123 /* Define strerror(), which is normally in <string.h>: */
00124 #if defined (SunOS_4)                                   /* SunOS 4.1 */
00125   extern int sys_nerr;
00126   extern char *sys_errlist[];
00127   #define strerror(e)   ((e) >= sys_nerr ? "Unknown" : sys_errlist[e])
00128 #endif
00129 
00130 /* Define memcpy(), etc., which are normally in <string.h>: */
00131 #if defined (SunOS_4)                                   /* SunOS 4.1 */
00132   extern void *memchr (const void *, int, size_t);
00133   extern int memcmp (const void *, const void *, size_t);
00134   extern void *memcpy (void *, const void *, size_t);
00135   extern void *memmove (void *, const void *, size_t);
00136   extern void *memset (void *, int, size_t);
00137 #endif
00138 
00139 /* Get a definition of time(), which is normally in <time.h>: */
00140 #if defined (SunOS_4)                                   /* SunOS 4.1 */
00141   extern time_t time (time_t *);
00142 #endif
00143 
00144 
00145 /*
00146  *  Definition of a random number generator.
00147  *
00148  *  On systems that have drand48(), use it; otherwise use rand().
00149  */
00150 
00151 #if defined (sun) || defined (sgi) || defined (_XPG4)
00152   extern void srand48 (long);
00153   extern double drand48 (void);
00154   extern long mrand48 (void);
00155   #define VRandomSeed(seed)     srand48 ((long) seed)
00156   #define VRandomDouble()       ((VDouble) drand48 ())
00157   #define VRandomLong()         ((VLong) mrand48 ())
00158 #else
00159   #define VRandomSeed(seed)     srand ((int) seed)
00160   #ifdef RAND_MAX
00161     #define VRandomDouble()     ((unsigned int) rand () / (VDouble) RAND_MAX+1)
00162   #else
00163     #define VRandomDouble()     ((unsigned int) rand () / (VDouble) 0x80000000)
00164   #endif
00165   #define VRandomLong()         ((VLong) rand())
00166 #endif
00167 
00168 
00169 /*
00170  *  Other useful definitions.
00171  */
00172 
00173 /* Include an identifying string in an object file without causing
00174    `unused variable' warnings: */
00175 #define VRcsId(str) static char *rcsid = (0 ? (char *) & rcsid : (str))
00176 
00177 
00178 #endif /* V_Vos_h */