]> git.sur5r.net Git - cc65/blob - include/stdlib.h
Merge pull request #625 from ops/VIAFIX
[cc65] / include / stdlib.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 stdlib.h                                  */
4 /*                                                                           */
5 /*                             General utilities                             */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2011, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                D-70794 Filderstadt                                        */
12 /* EMail:         uz@cc65.org                                                */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef _STDLIB_H
37 #define _STDLIB_H
38
39
40
41 /* size_t is needed */
42 #ifndef _HAVE_size_t
43 typedef unsigned size_t;
44 #define _HAVE_size_t
45 #endif
46
47 /* Standard exit codes */
48 #define EXIT_SUCCESS    0
49 #define EXIT_FAILURE    1
50
51 /* Return type of the div function */
52 typedef struct {
53     int rem;
54     int quot;
55 } div_t;
56
57 /* Return type of the ldiv function (which currently doesn't exist) */
58 typedef struct {
59     long rem;
60     long quot;
61 } ldiv_t;
62
63 /* Memory management */
64 void* __fastcall__ malloc (size_t size);
65 void* __fastcall__ calloc (size_t count, size_t size);
66 void* __fastcall__ realloc (void* block, size_t size);
67 void __fastcall__ free (void* block);
68
69 /* Non standard memory management functions */
70
71 #if __CC65_STD__ == __CC65_STD_CC65__
72 int __fastcall__ posix_memalign (void** memptr, size_t alignment, size_t size);
73 /* Allocate a block of memory with the given "size", which is aligned to a
74 ** memory address that is a multiple of "alignment".  "alignment" MUST NOT be
75 ** zero, and MUST be a power of two; otherwise, this function will return
76 ** EINVAL.  The function returns ENOMEM if not enough memory is available
77 ** to satisfy the request.  "memptr" must point to a variable; that variable
78 ** will return the address of the allocated memory.  Use free() to release that
79 ** allocated block.
80 */
81 #endif
82
83 void __fastcall__ _heapadd (void* mem, size_t size);
84 /* Add a block to the heap */
85
86 size_t __fastcall__ _heapblocksize (const void* block);
87 /* Return the size of an allocated block */
88
89 size_t _heapmemavail (void);
90 /* Return the total free heap space */
91
92 size_t _heapmaxavail (void);
93 /* Return the size of the largest free block on the heap */
94
95
96 /* Random numbers */
97 #define RAND_MAX        0x7FFF
98 int rand (void);
99 void __fastcall__ srand (unsigned seed);
100 void _randomize (void);         /* Non-standard */
101
102 /* Other standard stuff */
103 void abort (void) __attribute__ ((noreturn));
104 int __fastcall__ abs (int val);
105 long __fastcall__ labs (long val);
106 int __fastcall__ atoi (const char* s);
107 long __fastcall__ atol (const char* s);
108 int __fastcall__ atexit (void (*exitfunc) (void));
109 void* __fastcall__ bsearch (const void* key, const void* base, size_t n,
110                             size_t size, int __fastcall__ (* cmp) (const void*, const void*));
111 div_t __fastcall__ div (int numer, int denom);
112 void __fastcall__ exit (int ret) __attribute__ ((noreturn));
113 char* __fastcall__ getenv (const char* name);
114 void __fastcall__ qsort (void* base, size_t count, size_t size,
115                          int __fastcall__ (* compare) (const void*, const void*));
116 long __fastcall__ strtol (const char* nptr, char** endptr, int base);
117 unsigned long __fastcall__ strtoul (const char* nptr, char** endptr, int base);
118 int __fastcall__ system (const char* s);
119
120 /* Non-ANSI functions */
121 void __fastcall__ _swap (void* p, void* q, size_t size);
122 #if __CC65_STD__ == __CC65_STD_CC65__
123 char* __fastcall__ itoa (int val, char* buf, int radix);
124 char* __fastcall__ utoa (unsigned val, char* buf, int radix);
125 char* __fastcall__ ltoa (long val, char* buf, int radix);
126 char* __fastcall__ ultoa (unsigned long val, char* buf, int radix);
127 int __fastcall__ putenv (char* s);
128 #endif
129
130
131
132 /* End of stdlib.h */
133 #endif
134
135
136