File: mystdlib.h

package info (click to toggle)
libace-perl 1.92-12
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,012 kB
  • sloc: perl: 7,763; ansic: 7,420; makefile: 81
file content (418 lines) | stat: -rw-r--r-- 12,583 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/*  File: mystdlib.h
 *  Author: Jean Thierry-Mieg (mieg@mrc-lmb.cam.ac.uk)
 *  Copyright (C) J Thierry-Mieg and R Durbin, 1992
 *-------------------------------------------------------------------
 * This file is part of the ACEDB genome database package, written by
 * 	Richard Durbin (MRC LMB, UK) rd@mrc-lmb.cam.ac.uk, and
 *	Jean Thierry-Mieg (CRBM du CNRS, France) mieg@kaa.cnrs-mop.fr
 *
 * Description:
 ** Prototypes of system calls
 ** One should in principle use stdlib, however on the various machines,
    stdlibs do not always agree, I found easier to look by hand 
    and copy here my human interpretation of what I need.
    Examples of problems are: reservations for multi processor
    architectures on some Silicon machines, necessity to define myFile_t on
    some machines and not on others etc.
 * Exported functions:
 * HISTORY:
 * Last edited: Dec  4 16:03 1998 (fw)
 * * Feb  6 14:04 1997 (srk)
 * * Jun 11 16:46 1996 (rbrusk): WIN32 tace fixes
 * * Jun 10 17:46 1996 (rbrusk): strcasecmp etc. back to simple defines...
 * * Jun  9 19:29 1996 (rd)
 * * Jun 5 15:36 1996 (rbrusk): WIN32 port details
 *	-	Added O/S specific pathname syntax token conventions as #defined symbols
 * * Jun 5 10:06 1996 (rbrusk): moved X_OK etc. from filsubs.c for IBM
 * Jun  4 23:33 1996 (rd)
 * * Jun  4 21:19 1996 (rd): WIN32 changes
 * Created: Fri Jun  5 18:29:09 1992 (mieg)
 *-------------------------------------------------------------------
 */

/* $Id: mystdlib.h,v 1.1 2002/11/14 20:00:06 lstein Exp $ */

#ifndef DEF_MYSTDLIB_H
#define DEF_MYSTDLIB_H

/* below needed for MAXPATHLEN */
#if !defined(WIN32)
#include <sys/param.h>
#endif

#if defined(MSDOS)
  #define O_RDONLY 1
  #define O_WRONLY 2
  #define O_RDWR   4
  #define O_BINARY 0x8000
#else
#if !(defined(MACINTOSH) || defined(WIN32))
#define O_BINARY 0
#endif
#endif

#if defined(ALLIANT) || defined(CONVEX) 
#define O_RDONLY 0
#endif

/************************ WIN32 stuff ************************/
#if defined(WIN32)

#include <sys/stat.h> /* for S_IREAD | S_IWRITE */

#define X_OK	0
#define W_OK	2
#define R_OK	4
#define F_OK	X_OK /* if i exist in WIN32, then i might be executable? */

#include <io.h>		/* for access() in dotter.c */
typedef int uid_t ;	/* UNIX/RPC types not currently used in WIN32 */

/*  O/S specific file system pathname conventions:
	general syntax conventions symbolically defined */

/* In WIN32/DOS... */ 

#define PATH_DELIMITER ';'
#define DRIVE_DELIMITER ':'			/* Not used in UNIX */
#define DRIVE_DELIMITER_STR ":"		/* Not used in UNIX */
#define SUBDIR_DELIMITER '\\'
#define SUBDIR_DELIMITER_STR "\\"

char *DosToPosix(char *path) ; /* defined in filsubs.c */
#define UNIX_PATHNAME(z) DosToPosix(z)

/**************** some NON-WIN32 equivalents ******************/
#else  /* UNIX-like, NOT WIN32 */

#define PATH_DELIMITER ':'
#define SUBDIR_DELIMITER '/'
#define SUBDIR_DELIMITER_STR "/"

#define UNIX_PATHNAME(z) z   /* Already a UNIX filename? */

#endif
/************** #endif !defined(WIN32) *************************/


  /*<<--neil 16Sep92: to avoid using values.h*/
#define ACEDB_MAXINT 2147483647
#define ACEDB_MINDOUBLE 1.0e-305
#define ACEDB_LN_MINDOUBLE -700

/* The next few are designed to determine how the compiler aligns structures,
   not what we can get away with; change only if extreme circumstances */

#define INT_ALIGNMENT (sizeof(struct{char c; int i; }) - sizeof(int))
#define DOUBLE_ALIGNMENT (sizeof(struct {char c; double d; }) - sizeof(double))
#define SHORT_ALIGNMENT (sizeof(struct {char c; short s; }) - sizeof(short))
#define FLOAT_ALIGNMENT (sizeof(struct {char c; float f; }) - sizeof(float))
#define PTR_ALIGNMENT (sizeof(struct {char c; void *p; }) - sizeof(void *))

/* Constants for store alignment */

/* These are defined as follows:
   MALLOC_ALIGNMENT
   Alignment of most restrictive data type, the system malloc will 
   return addresses aligned to this, and we do the same in messalloc.

   STACK_ALIGNMENT 
   Alignment of data objects on a Stack; this should really be
   the same as MALLOC_ALIGNMENT, but for most 32 bit pointer machines
   we align stacks to 4 bytes to save memory.

   STACK_DOUBLE_ALIGNMENT
   Alignment of doubles required on stack, if this is greater than
   STACK_ALIGNMENT, we read and write doubles on a stack by steam.


   Put specific exceptions first, the defaults below should cope 
   with most cases. Oh, one more thing, STACK_ALIGNMENT and
   STACK_DOUBLE ALIGNMENT are used on pre-processor constant 
   expressions so no sizeofs, sorry.
*/


/* 680x0 processors can fix up unaligned accesses so we trade off speed
   against memory usage on a Mac. I have no idea if this is a good
   trade-off, I only program real computers - srk */

#if defined(NEXT) || defined(MACINTOSH) 
#  define STACK_ALIGNMENT 2
#  define STACK_DOUBLE_ALIGNMENT 2
#  define MALLOC_ALIGNMENT 4
#endif

/* Alpha pointers are 8 bytes, so align the stack to that */
#if defined(ALPHA) || defined(ALIGNMENT_64_BIT)
#  define STACK_ALIGNMENT 8
#endif

#if !defined(STACK_ALIGNMENT)
#  define STACK_ALIGNMENT 4
#endif

#if !defined(STACK_DOUBLE_ALIGNMENT)
#  define STACK_DOUBLE_ALIGNMENT 8
#endif

#if !defined(MALLOC_ALIGNMENT) 
#  define MALLOC_ALIGNMENT DOUBLE_ALIGNMENT
#endif

#if defined(POSIX) || defined(LINUX) || defined(SOLARIS) || defined(SGI) || \
	defined(HP) || defined(WIN32) || defined(INTEL_SOLARIS)

#ifdef WIN32
#include <mbctype.h>
#endif /* WIN32 */

#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>

#include <sys/types.h>
#include <sys/stat.h>

#if !defined(WIN32)
#include <unistd.h>
#include <sys/param.h>
#endif /* !WIN32 */

#if defined(HP)
#include <sys/unistd.h>
#define seteuid setuid     /* bizare that this is missing on the HP ?? */
#endif /* HP */

typedef size_t mysize_t;
/* typedef fpos_t myoff_t;  why? i remove this on jan 98 to compile on fujitsu */
typedef off_t myoff_t;
typedef mysize_t myFile_t;

#define FIL_BUFFER_SIZE 256
#define DIR_BUFFER_SIZE MAXPATHLEN

#if defined(WIN32)

  /* _MAX_PATH is 260 in WIN32 but each path component can be max. 256 in size */
#undef DIR_BUFFER_SIZE
#define DIR_BUFFER_SIZE   FIL_BUFFER_SIZE
#define MAXPATHLEN        _MAX_PATH

#define popen _popen
#define pclose _pclose

/* rename to actual WIN32 built-in functions
* (rbrusk): this little code generated a "trigraph" error message
* when built in unix with the gcc compiler; however, I don't understand
* why gcc even sees this code, which is #if defined(WIN32)..#endif protected.
* Changing these to macros is problematic in lex4subs.c et al, which expects
* the names as function names (without parentheses.  So, I change them back..
* If the trigraph error message returns, look for another explanation,
* like MSDOS carriage returns, or something? */
#define strcasecmp  _stricmp 
#define strncasecmp  _strnicmp 
#endif /* WIN32 */

#else  /* not POSIX etc. e.g. SUNOS */

/* local versions of general types */

#if defined(ALLIANT) || defined (DEC) || defined(MAC_AUX) || defined(MACINTOSH)
  typedef unsigned int mysize_t ;
#elif defined(SGI)
  typedef unsigned mysize_t ;
#elif defined(NEXT) || defined(IBM) || defined(MACINTOSH)
  typedef unsigned long mysize_t ;
#else
  typedef int mysize_t ;
#endif

/* stdio */

#include <stdio.h>

/* Definition of the file position type */
#if defined(SUN) 
  typedef long    fpos_t;
#endif /* SUN */

#if defined(ALLIANT) || defined(CONVEX) || defined(MAC_AUX) || defined(METROWERKS)
  typedef long myoff_t ;
#else
  typedef fpos_t myoff_t ;
#endif

/* Constants to be used as 3rd argument for "fseek" function */
#if !defined(SGI) && !defined(ALLIANT)
#define SEEK_CUR        1
#define SEEK_END        2
#define SEEK_SET        0
#endif


/* io.h definitions and prototypes */
#ifndef METROWERKS
#include <fcntl.h>
#endif /* !METROWERKS */

#ifdef IBM
#include <sys/param.h>
#include <strings.h>
#endif /* IBM */


#if !defined(MACINTOSH)
#include <sys/types.h>
#include <sys/stat.h>

#include <unistd.h>
#include <time.h>
#endif /* !MACINTOSH */


/* string and memory stuff */

#include <memory.h>
#include <string.h>


/* missing */
#if defined(DEC) || defined(MACINTOSH) || defined (SUN) || defined (NEC)|| defined(HP) || defined(IBM)
/* case-insensitive string comparison */
int     strcasecmp (const char *a, const char *b) ;
int     strncasecmp(const char *s1, const char *s2, mysize_t n);
#endif

#ifndef	__malloc_h
void free (void *block) ;  /* int on SUN, void on SGI etc */
#endif

/* system functions and sorts - simplest to give full prototypes for all */
int      system    (const char *command);
#ifndef IBM
void     exit      (int status); 
#endif
char   * getenv    (const char *name);

#if !defined(NEXT) && !defined(ALPHA)
void     qsort     (void *base, mysize_t nelem, mysize_t width,
                    int  (*fcmp)(const void *, const void *)) ;
#endif /* !NEXT or !ALPHA */

/* math stuff */
#include <math.h>

#ifndef THINK_C
extern double atof (const char *cp) ; /* I hope ! */
#endif

#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif
#define FIL_BUFFER_SIZE 256
#define DIR_BUFFER_SIZE MAXPATHLEN 

#endif  /* not POSIX etc. */



/***************** missing in some stdio.h ****************/
#ifdef SUN
int rename (const char *from, const char *to);
#endif /* SUN */



/************** missing in some unistd.h *******************/
#if defined SUN || defined SOLARIS 
int lockf(int filedes, int request, off_t size );
int gethostname(char *name, int namelen);
#endif /* SOLARIS */

/************* handling of variable-length parameter lists *********/

#include <stdarg.h>

#if !(defined(MACINTOSH)  || defined(SOLARIS) || defined(POSIX) || defined(WIN32))
 int vfprintf (FILE *stream, const char *format, va_list arglist);
 int vprintf  (const char *format, va_list arglist);
#endif	/* !( defined(MACINTOSH)  etc. ) */

#if defined(SUN)
 char *vsprintf (char *buffer, const char *format, va_list arglist);
#else
#if ! defined(POSIX) && ! defined(SOLARIS)
 int vsprintf (char *buffer, const char *format, va_list arglist);
#endif /* !POSIX */
#endif /* !SUN */

/*******************************************************************/

#ifdef SUN			/* missing prototypes on SUN */
int       fclose   (FILE *stream);
int       fflush   (FILE *stream);
int       fgetc    (FILE *stream);
int       ungetc   (int c, FILE *stream) ;
int       _filbuf  (FILE *stream) ;
int       _flsbuf  (unsigned char x, FILE *stream) ;
int       fprintf  (FILE *stream, const char *format, ...);
int       fscanf   (FILE *stream, const char *format, ...);
int       scanf    (const char *format, ...);
int       printf   (const char *format, ...);
int       sscanf   (const char *buffer, const char *format, ...);
int       fgetpos  (FILE *stream, fpos_t *pos);
char    * fgets    (char *s, int n, FILE *stream);
FILE    * fopen    (const char *path, const char *mode);
int       fputc    (int c, FILE *stream);
int       fputs    (const char *s, FILE *stream);
int       fseek    (FILE *stream, long offset, int whence);
int       fsetpos  (FILE *stream, const fpos_t *pos);
long      ftell    (FILE *stream);
mysize_t  fread    (void *ptr, mysize_t size, mysize_t n, FILE *stream);
mysize_t  fwrite   (const void *ptr, mysize_t size, mysize_t n,
                          FILE *stream);
void      perror   (const char *s);
FILE      *popen   (const char *command, const char *type);
int       pclose   (FILE *stream);
void      rewind   (FILE *stream);
void      setbuf   (FILE *stream, char *buf);

/*int       isalpha  (int c); - fails for some reason with "parse error before `+'" */
char      getopt   (int c, char **s1, char *s2);
#endif /* defined SUN */

/************************************************************/

#ifdef SUN
/* memmove is not included in SunOS libc, bcopy is */
#define memmove(d,s,l) bcopy(s,d,l)
void  bcopy(char *b1, char *b2, int length);

/* for 'bare' calls, in case the storage is destroyed by 
   lower-level libraries not using messalloc */
#include "malloc.h"

/* not defined in SUN's unistd.h */
int setruid(uid_t ruid);
int seteuid(uid_t euid);
#endif /* SUN */

/*******************************************************************/


/* some stdlib.h don't define these exit codes */
#ifndef EXIT_FAILURE
#define EXIT_FAILURE   (1)              /* exit function failure        */
#endif /* if !EXIT_FAILURE */

#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS    0               /* exit function success        */
#endif /* if !EXIT_SUCCESS */


#endif  /* DEF_MYSTDLIB_H */

/***********************************************************/