1 /*****************************************************************************/
5 /* General utilities */
9 /* (C) 1998-2005 Ullrich von Bassewitz */
10 /* Römerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
41 /* size_t is needed */
43 typedef unsigned size_t;
47 /* Standard exit codes */
48 #define EXIT_SUCCESS 0
49 #define EXIT_FAILURE 1
51 /* Return type of the div function */
57 /* Memory management */
58 void* __fastcall__ malloc (size_t size);
59 void* __fastcall__ calloc (size_t count, size_t size);
60 void* __fastcall__ realloc (void* block, size_t size);
61 void __fastcall__ free (void* block);
63 /* Non standard memory management functions */
65 #if __CC65_STD__ == __CC65_STD_CC65__
66 int __fastcall__ posix_memalign (void** memptr, size_t alignment, size_t size);
67 /* Allocate a block of memory with the given "size", which is aligned to a
68 * memory address that is a multiple of "alignment". "alignment" MUST NOT be
69 * zero, and MUST be a power of two; otherwise, this function will return
70 * EINVAL. The function returns ENOMEM if not enough memory is available
71 * to satisfy the request. "memptr" must point to a variable; that variable
72 * will return the address of the allocated memory. Use free() to release that
77 void __fastcall__ _heapadd (void* mem, size_t size);
78 /* Add a block to the heap */
80 size_t __fastcall__ _heapblocksize (const void* block);
81 /* Return the size of an allocated block */
83 size_t __fastcall__ _heapmemavail (void);
84 /* Return the total free heap space */
86 size_t __fastcall__ _heapmaxavail (void);
87 /* Return the size of the largest free block on the heap */
91 #define RAND_MAX 0x7FFF
93 void __fastcall__ srand (unsigned seed);
94 void _randomize (void); /* Non-standard */
96 /* Other standard stuff */
98 int __fastcall__ abs (int val);
99 long __fastcall__ labs (long val);
100 int __fastcall__ atoi (const char* s);
101 long __fastcall__ atol (const char* s);
102 int __fastcall__ atexit (void (*exitfunc) (void));
103 void* __fastcall__ bsearch (const void* key, const void* base, size_t n,
104 size_t size, int (*cmp) (const void*, const void*));
105 div_t __fastcall__ div (int numer, int denom);
106 void __fastcall__ exit (int ret);
107 char* __fastcall__ getenv (const char* name);
108 void __fastcall__ qsort (void* base, size_t count, size_t size,
109 int (*compare) (const void*, const void*));
110 int system (const char* s);
112 /* Non-ANSI functions */
113 void __fastcall__ _swap (void* p, void* q, size_t size);
114 #if __CC65_STD__ == __CC65_STD_CC65__
115 char* __fastcall__ itoa (int val, char* buf, int radix);
116 char* __fastcall__ utoa (unsigned val, char* buf, int radix);
117 char* __fastcall__ ltoa (long val, char* buf, int radix);
118 char* __fastcall__ ultoa (unsigned long val, char* buf, int radix);
119 int __fastcall__ putenv (char* s);
124 /* End of stdlib.h */