1 /* File: mystdlib.h 2 * Author: Jean Thierry-Mieg (mieg@mrc-lmb.cam.ac.uk) 3 * Copyright (C) J Thierry-Mieg and R Durbin, 1992 4 *------------------------------------------------------------------- 5 * This file is part of the ACEDB genome database package, written by 6 * Richard Durbin (MRC LMB, UK) rd@mrc-lmb.cam.ac.uk, and 7 * Jean Thierry-Mieg (CRBM du CNRS, France) mieg@kaa.cnrs-mop.fr 8 * 9 * Description: 10 ** Prototypes of system calls 11 ** One should in principle use stdlib, however on the various machines, 12 stdlibs do not always agree, I found easier to look by hand 13 and copy here my human interpretation of what I need. 14 Examples of problems are: reservations for multi processor 15 architectures on some Silicon machines, necessity to define myFile_t on 16 some machines and not on others etc. 17 * Exported functions: 18 * HISTORY: 19 * Last edited: Dec 4 16:03 1998 (fw) 20 * * Feb 6 14:04 1997 (srk) 21 * * Jun 11 16:46 1996 (rbrusk): WIN32 tace fixes 22 * * Jun 10 17:46 1996 (rbrusk): strcasecmp etc. back to simple defines... 23 * * Jun 9 19:29 1996 (rd) 24 * * Jun 5 15:36 1996 (rbrusk): WIN32 port details 25 * - Added O/S specific pathname syntax token conventions as #defined symbols 26 * * Jun 5 10:06 1996 (rbrusk): moved X_OK etc. from filsubs.c for IBM 27 * Jun 4 23:33 1996 (rd) 28 * * Jun 4 21:19 1996 (rd): WIN32 changes 29 * Created: Fri Jun 5 18:29:09 1992 (mieg) 30 *------------------------------------------------------------------- 31 */ 32 33 /* $Id: mystdlib.h,v 1.1 2002/11/14 20:00:06 lstein Exp $ */ 34 35 #ifndef DEF_MYSTDLIB_H 36 #define DEF_MYSTDLIB_H 37 38 /* below needed for MAXPATHLEN */ 39 #if !defined(WIN32) 40 #include <sys/param.h> 41 #endif 42 43 #if defined(MSDOS) 44 #define O_RDONLY 1 45 #define O_WRONLY 2 46 #define O_RDWR 4 47 #define O_BINARY 0x8000 48 #else 49 #if !(defined(MACINTOSH) || defined(WIN32)) 50 #define O_BINARY 0 51 #endif 52 #endif 53 54 #if defined(ALLIANT) || defined(CONVEX) 55 #define O_RDONLY 0 56 #endif 57 58 /************************ WIN32 stuff ************************/ 59 #if defined(WIN32) 60 61 #include <sys/stat.h> /* for S_IREAD | S_IWRITE */ 62 63 #define X_OK 0 64 #define W_OK 2 65 #define R_OK 4 66 #define F_OK X_OK /* if i exist in WIN32, then i might be executable? */ 67 68 #include <io.h> /* for access() in dotter.c */ 69 typedef int uid_t ; /* UNIX/RPC types not currently used in WIN32 */ 70 71 /* O/S specific file system pathname conventions: 72 general syntax conventions symbolically defined */ 73 74 /* In WIN32/DOS... */ 75 76 #define PATH_DELIMITER ';' 77 #define DRIVE_DELIMITER ':' /* Not used in UNIX */ 78 #define DRIVE_DELIMITER_STR ":" /* Not used in UNIX */ 79 #define SUBDIR_DELIMITER '\\' 80 #define SUBDIR_DELIMITER_STR "\\" 81 82 char *DosToPosix(char *path) ; /* defined in filsubs.c */ 83 #define UNIX_PATHNAME(z) DosToPosix(z) 84 85 /**************** some NON-WIN32 equivalents ******************/ 86 #else /* UNIX-like, NOT WIN32 */ 87 88 #define PATH_DELIMITER ':' 89 #define SUBDIR_DELIMITER '/' 90 #define SUBDIR_DELIMITER_STR "/" 91 92 #define UNIX_PATHNAME(z) z /* Already a UNIX filename? */ 93 94 #endif 95 /************** #endif !defined(WIN32) *************************/ 96 97 98 /*<<--neil 16Sep92: to avoid using values.h*/ 99 #define ACEDB_MAXINT 2147483647 100 #define ACEDB_MINDOUBLE 1.0e-305 101 #define ACEDB_LN_MINDOUBLE -700 102 103 /* The next few are designed to determine how the compiler aligns structures, 104 not what we can get away with; change only if extreme circumstances */ 105 106 #define INT_ALIGNMENT (sizeof(struct{char c; int i; }) - sizeof(int)) 107 #define DOUBLE_ALIGNMENT (sizeof(struct {char c; double d; }) - sizeof(double)) 108 #define SHORT_ALIGNMENT (sizeof(struct {char c; short s; }) - sizeof(short)) 109 #define FLOAT_ALIGNMENT (sizeof(struct {char c; float f; }) - sizeof(float)) 110 #define PTR_ALIGNMENT (sizeof(struct {char c; void *p; }) - sizeof(void *)) 111 112 /* Constants for store alignment */ 113 114 /* These are defined as follows: 115 MALLOC_ALIGNMENT 116 Alignment of most restrictive data type, the system malloc will 117 return addresses aligned to this, and we do the same in messalloc. 118 119 STACK_ALIGNMENT 120 Alignment of data objects on a Stack; this should really be 121 the same as MALLOC_ALIGNMENT, but for most 32 bit pointer machines 122 we align stacks to 4 bytes to save memory. 123 124 STACK_DOUBLE_ALIGNMENT 125 Alignment of doubles required on stack, if this is greater than 126 STACK_ALIGNMENT, we read and write doubles on a stack by steam. 127 128 129 Put specific exceptions first, the defaults below should cope 130 with most cases. Oh, one more thing, STACK_ALIGNMENT and 131 STACK_DOUBLE ALIGNMENT are used on pre-processor constant 132 expressions so no sizeofs, sorry. 133 */ 134 135 136 /* 680x0 processors can fix up unaligned accesses so we trade off speed 137 against memory usage on a Mac. I have no idea if this is a good 138 trade-off, I only program real computers - srk */ 139 140 #if defined(NEXT) || defined(MACINTOSH) 141 # define STACK_ALIGNMENT 2 142 # define STACK_DOUBLE_ALIGNMENT 2 143 # define MALLOC_ALIGNMENT 4 144 #endif 145 146 /* Alpha pointers are 8 bytes, so align the stack to that */ 147 #if defined(ALPHA) || defined(ALIGNMENT_64_BIT) 148 # define STACK_ALIGNMENT 8 149 #endif 150 151 #if !defined(STACK_ALIGNMENT) 152 # define STACK_ALIGNMENT 4 153 #endif 154 155 #if !defined(STACK_DOUBLE_ALIGNMENT) 156 # define STACK_DOUBLE_ALIGNMENT 8 157 #endif 158 159 #if !defined(MALLOC_ALIGNMENT) 160 # define MALLOC_ALIGNMENT DOUBLE_ALIGNMENT 161 #endif 162 163 #if defined(POSIX) || defined(LINUX) || defined(SOLARIS) || defined(SGI) || \ 164 defined(HP) || defined(WIN32) || defined(INTEL_SOLARIS) || \ 165 defined(FREEBSD) || defined(DRAGONFLY) 166 167 #ifdef WIN32 168 #include <mbctype.h> 169 #endif /* WIN32 */ 170 171 #include <stdlib.h> 172 #include <math.h> 173 #include <string.h> 174 #include <stdio.h> 175 #include <fcntl.h> 176 177 #include <sys/types.h> 178 #include <sys/stat.h> 179 180 #if !defined(WIN32) 181 #include <unistd.h> 182 #include <sys/param.h> 183 #endif /* !WIN32 */ 184 185 #if defined(HP) 186 #include <sys/unistd.h> 187 #define seteuid setuid /* bizare that this is missing on the HP ?? */ 188 #endif /* HP */ 189 190 typedef size_t mysize_t; 191 /* typedef fpos_t myoff_t; why? i remove this on jan 98 to compile on fujitsu */ 192 typedef off_t myoff_t; 193 typedef mysize_t myFile_t; 194 195 #define FIL_BUFFER_SIZE 256 196 #define DIR_BUFFER_SIZE MAXPATHLEN 197 198 #if defined(WIN32) 199 200 /* _MAX_PATH is 260 in WIN32 but each path component can be max. 256 in size */ 201 #undef DIR_BUFFER_SIZE 202 #define DIR_BUFFER_SIZE FIL_BUFFER_SIZE 203 #define MAXPATHLEN _MAX_PATH 204 205 #define popen _popen 206 #define pclose _pclose 207 208 /* rename to actual WIN32 built-in functions 209 * (rbrusk): this little code generated a "trigraph" error message 210 * when built in unix with the gcc compiler; however, I don't understand 211 * why gcc even sees this code, which is #if defined(WIN32)..#endif protected. 212 * Changing these to macros is problematic in lex4subs.c et al, which expects 213 * the names as function names (without parentheses. So, I change them back.. 214 * If the trigraph error message returns, look for another explanation, 215 * like MSDOS carriage returns, or something? */ 216 #define strcasecmp _stricmp 217 #define strncasecmp _strnicmp 218 #endif /* WIN32 */ 219 220 #else /* not POSIX etc. e.g. SUNOS */ 221 222 /* local versions of general types */ 223 224 #if defined(ALLIANT) || defined (DEC) || defined(MAC_AUX) || defined(MACINTOSH) 225 typedef unsigned int mysize_t ; 226 #elif defined(SGI) 227 typedef unsigned mysize_t ; 228 #elif defined(NEXT) || defined(IBM) || defined(MACINTOSH) 229 typedef unsigned long mysize_t ; 230 #else 231 typedef int mysize_t ; 232 #endif 233 234 /* stdio */ 235 236 #include <stdio.h> 237 238 /* Definition of the file position type */ 239 #if defined(SUN) 240 typedef long fpos_t; 241 #endif /* SUN */ 242 243 #if defined(ALLIANT) || defined(CONVEX) || defined(MAC_AUX) || defined(METROWERKS) 244 typedef long myoff_t ; 245 #else 246 typedef fpos_t myoff_t ; 247 #endif 248 249 /* Constants to be used as 3rd argument for "fseek" function */ 250 #if !defined(SGI) && !defined(ALLIANT) 251 #define SEEK_CUR 1 252 #define SEEK_END 2 253 #define SEEK_SET 0 254 #endif 255 256 257 /* io.h definitions and prototypes */ 258 #ifndef METROWERKS 259 #include <fcntl.h> 260 #endif /* !METROWERKS */ 261 262 #ifdef IBM 263 #include <sys/param.h> 264 #include <strings.h> 265 #endif /* IBM */ 266 267 268 #if !defined(MACINTOSH) 269 #include <sys/types.h> 270 #include <sys/stat.h> 271 272 #include <unistd.h> 273 #include <time.h> 274 #endif /* !MACINTOSH */ 275 276 277 /* string and memory stuff */ 278 279 #include <memory.h> 280 #include <string.h> 281 282 283 /* missing */ 284 #if defined(DEC) || defined(MACINTOSH) || defined (SUN) || defined (NEC)|| defined(HP) || defined(IBM) 285 /* case-insensitive string comparison */ 286 int strcasecmp (const char *a, const char *b) ; 287 int strncasecmp(const char *s1, const char *s2, mysize_t n); 288 #endif 289 290 #ifndef __malloc_h 291 void free (void *block) ; /* int on SUN, void on SGI etc */ 292 #endif 293 294 /* system functions and sorts - simplest to give full prototypes for all */ 295 int system (const char *command); 296 #ifndef IBM 297 void exit (int status); 298 #endif 299 char * getenv (const char *name); 300 301 #if !defined(NEXT) && !defined(ALPHA) 302 void qsort (void *base, mysize_t nelem, mysize_t width, 303 int (*fcmp)(const void *, const void *)) ; 304 #endif /* !NEXT or !ALPHA */ 305 306 /* math stuff */ 307 #include <math.h> 308 309 #ifndef THINK_C 310 extern double atof (const char *cp) ; /* I hope ! */ 311 #endif 312 313 #ifndef MAXPATHLEN 314 #define MAXPATHLEN 1024 315 #endif 316 #define FIL_BUFFER_SIZE 256 317 #define DIR_BUFFER_SIZE MAXPATHLEN 318 319 #endif /* not POSIX etc. */ 320 321 322 323 /***************** missing in some stdio.h ****************/ 324 #ifdef SUN 325 int rename (const char *from, const char *to); 326 #endif /* SUN */ 327 328 329 330 /************** missing in some unistd.h *******************/ 331 #if defined SUN || defined SOLARIS 332 int lockf(int filedes, int request, off_t size ); 333 int gethostname(char *name, int namelen); 334 #endif /* SOLARIS */ 335 336 /************* handling of variable-length parameter lists *********/ 337 338 #include <stdarg.h> 339 340 #if !(defined(MACINTOSH) || defined(SOLARIS) || defined(POSIX) || defined(WIN32)) 341 int vfprintf (FILE *stream, const char *format, va_list arglist); 342 int vprintf (const char *format, va_list arglist); 343 #endif /* !( defined(MACINTOSH) etc. ) */ 344 345 #if defined(SUN) 346 char *vsprintf (char *buffer, const char *format, va_list arglist); 347 #else 348 #if ! defined(POSIX) && ! defined(SOLARIS) 349 int vsprintf (char *buffer, const char *format, va_list arglist); 350 #endif /* !POSIX */ 351 #endif /* !SUN */ 352 353 /*******************************************************************/ 354 355 #ifdef SUN /* missing prototypes on SUN */ 356 int fclose (FILE *stream); 357 int fflush (FILE *stream); 358 int fgetc (FILE *stream); 359 int ungetc (int c, FILE *stream) ; 360 int _filbuf (FILE *stream) ; 361 int _flsbuf (unsigned char x, FILE *stream) ; 362 int fprintf (FILE *stream, const char *format, ...); 363 int fscanf (FILE *stream, const char *format, ...); 364 int scanf (const char *format, ...); 365 int printf (const char *format, ...); 366 int sscanf (const char *buffer, const char *format, ...); 367 int fgetpos (FILE *stream, fpos_t *pos); 368 char * fgets (char *s, int n, FILE *stream); 369 FILE * fopen (const char *path, const char *mode); 370 int fputc (int c, FILE *stream); 371 int fputs (const char *s, FILE *stream); 372 int fseek (FILE *stream, long offset, int whence); 373 int fsetpos (FILE *stream, const fpos_t *pos); 374 long ftell (FILE *stream); 375 mysize_t fread (void *ptr, mysize_t size, mysize_t n, FILE *stream); 376 mysize_t fwrite (const void *ptr, mysize_t size, mysize_t n, 377 FILE *stream); 378 void perror (const char *s); 379 FILE *popen (const char *command, const char *type); 380 int pclose (FILE *stream); 381 void rewind (FILE *stream); 382 void setbuf (FILE *stream, char *buf); 383 384 /*int isalpha (int c); - fails for some reason with "parse error before `+'" */ 385 char getopt (int c, char **s1, char *s2); 386 #endif /* defined SUN */ 387 388 /************************************************************/ 389 390 #ifdef SUN 391 /* memmove is not included in SunOS libc, bcopy is */ 392 #define memmove(d,s,l) bcopy(s,d,l) 393 void bcopy(char *b1, char *b2, int length); 394 395 /* for 'bare' calls, in case the storage is destroyed by 396 lower-level libraries not using messalloc */ 397 #include "malloc.h" 398 399 /* not defined in SUN's unistd.h */ 400 int setruid(uid_t ruid); 401 int seteuid(uid_t euid); 402 #endif /* SUN */ 403 404 /*******************************************************************/ 405 406 407 /* some stdlib.h don't define these exit codes */ 408 #ifndef EXIT_FAILURE 409 #define EXIT_FAILURE (1) /* exit function failure */ 410 #endif /* if !EXIT_FAILURE */ 411 412 #ifndef EXIT_SUCCESS 413 #define EXIT_SUCCESS 0 /* exit function success */ 414 #endif /* if !EXIT_SUCCESS */ 415 416 417 #endif /* DEF_MYSTDLIB_H */ 418 419 /***********************************************************/ 420