|
@@ -8,6 +8,8 @@ extern void free ( void *ptr );
|
8
|
8
|
extern int system ( const char *command );
|
9
|
9
|
extern long int random ( void );
|
10
|
10
|
|
|
11
|
+extern void * _calloc ( size_t len );
|
|
12
|
+
|
11
|
13
|
/**
|
12
|
14
|
* Allocate cleared memory
|
13
|
15
|
*
|
|
@@ -17,12 +19,12 @@ extern long int random ( void );
|
17
|
19
|
*
|
18
|
20
|
* Allocate memory as per malloc(), and zero it.
|
19
|
21
|
*
|
20
|
|
- * Note that malloc() and calloc() are identical, in the interests of
|
21
|
|
- * reducing code size. Callers should not, however, rely on malloc()
|
22
|
|
- * clearing memory, since this behaviour may change in future.
|
|
22
|
+ * This is implemented as a static inline, with the body of the
|
|
23
|
+ * function in _calloc(), since in most cases @c nmemb will be 1 and
|
|
24
|
+ * doing the multiply is just wasteful.
|
23
|
25
|
*/
|
24
|
26
|
static inline void * calloc ( size_t nmemb, size_t size ) {
|
25
|
|
- return malloc ( nmemb * size );
|
|
27
|
+ return _calloc ( nmemb * size );
|
26
|
28
|
}
|
27
|
29
|
|
28
|
30
|
#endif /* STDLIB_H */
|