NASM 0.91
[nasm/sigaren-mirror.git] / nasmlib.h
blobd8273719cf28bf5a39a75c853b81ea475ebc7839
1 /* nasmlib.c header file for nasmlib.h
3 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
4 * Julian Hall. All rights reserved. The software is
5 * redistributable under the licence given in the file "Licence"
6 * distributed in the NASM archive.
7 */
9 #ifndef NASM_NASMLIB_H
10 #define NASM_NASMLIB_H
13 * Wrappers around malloc, realloc and free. nasm_malloc will
14 * fatal-error and die rather than return NULL; nasm_realloc will
15 * do likewise, and will also guarantee to work right on being
16 * passed a NULL pointer; nasm_free will do nothing if it is passed
17 * a NULL pointer.
19 void nasm_set_malloc_error (efunc);
20 void *nasm_malloc (size_t);
21 void *nasm_realloc (void *, size_t);
22 void nasm_free (void *);
23 char *nasm_strdup (char *);
26 * ANSI doesn't guarantee the presence of `stricmp' or
27 * `strcasecmp'.
29 int nasm_stricmp (char *, char *);
30 int nasm_strnicmp (char *, char *, int);
33 * Convert a string into a number, using NASM number rules. Sets
34 * `*error' to TRUE if an error occurs, and FALSE otherwise.
36 long readnum(char *str, int *error);
39 * seg_init: Initialise the segment-number allocator.
40 * seg_alloc: allocate a hitherto unused segment number.
42 void seg_init(void);
43 long seg_alloc(void);
46 * many output formats will be able to make use of this: a standard
47 * function to add an extension to the name of the input file
49 void standard_extension (char *inname, char *outname, char *extension,
50 efunc error);
53 * some handy macros that will probably be of use in more than one
54 * output format: convert integers into little-endian byte packed
55 * format in memory
58 #define WRITELONG(p,v) \
59 do { \
60 *(p)++ = (v) & 0xFF; \
61 *(p)++ = ((v) >> 8) & 0xFF; \
62 *(p)++ = ((v) >> 16) & 0xFF; \
63 *(p)++ = ((v) >> 24) & 0xFF; \
64 } while (0)
66 #define WRITESHORT(p,v) \
67 do { \
68 *(p)++ = (v) & 0xFF; \
69 *(p)++ = ((v) >> 8) & 0xFF; \
70 } while (0)
73 * and routines to do the same thing to a file
75 void fwriteshort (int data, FILE *fp);
76 void fwritelong (long data, FILE *fp);
79 * Routines to manage a dynamic random access array of longs which
80 * may grow in size to be more than the largest single malloc'able
81 * chunk.
84 struct RAA;
86 struct RAA *raa_init (void);
87 void raa_free (struct RAA *);
88 long raa_read (struct RAA *, long);
89 struct RAA *raa_write (struct RAA *r, long posn, long value);
92 * Routines to manage a dynamic sequential-access array, under the
93 * same restriction on maximum mallocable block. This array may be
94 * written to in two ways: a contiguous chunk can be reserved of a
95 * given size, and a pointer returned, or single-byte data may be
96 * written. The array can also be read back in the same two ways:
97 * as a series of big byte-data blocks or as a list of structures
98 * of a given size.
101 struct SAA;
103 struct SAA *saa_init (long elem_len); /* 1 == byte */
104 void saa_free (struct SAA *);
105 void *saa_wstruct (struct SAA *); /* return a structure of elem_len */
106 void saa_wbytes (struct SAA *, void *, long); /* write arbitrary bytes */
107 void saa_rewind (struct SAA *); /* for reading from beginning */
108 void *saa_rstruct (struct SAA *); /* return NULL on EOA */
109 void *saa_rbytes (struct SAA *, long *); /* return 0 on EOA */
110 void saa_rnbytes (struct SAA *, void *, long); /* read a given no. of bytes */
111 void saa_fread (struct SAA *s, long posn, void *p, long len); /* fixup */
112 void saa_fwrite (struct SAA *s, long posn, void *p, long len); /* fixup */
113 void saa_fpwrite (struct SAA *, FILE *);
115 #endif