Clean up stdlib

This commit is contained in:
Enrico Fraccaroli
2019-05-16 17:22:21 +02:00
parent c16a750251
commit bc2623ce99
2 changed files with 6 additions and 45 deletions
+4 -18
View File
@@ -11,29 +11,15 @@
/// @brief Malloc based on the number of elements.
void *calloc(size_t element_number, size_t element_size);
/// @brief Allows to set the seed of the random value generator.
void srand(int x);
void *malloc(unsigned int size);
void free(void * p);
/// The maximum value returned by the rand function.
#define RAND_MAX ((1U << 31U) - 1U)
#ifndef MS_RAND
/// @brief The maximum value of the random.
#define RAND_MAX ((1U << 31) - 1)
/// @brief Allows to set the seed of the random value generator.
void srand(int x);
/// @brief Generates a random value.
int rand();
// MS rand
#else
#define RAND_MAX_32 ((1U << 31) - 1)
#define RAND_MAX ((1U << 15) - 1)
int rand();
#endif
+2 -27
View File
@@ -8,9 +8,6 @@
#include "stdlib.h"
#include "string.h"
/// Used to align the memory.
#define ALIGN(x) (((x) + (sizeof(size_t) - 1)) & ~(sizeof(size_t) - 1))
void *malloc(unsigned int size)
{
void *_res;
@@ -36,38 +33,16 @@ void *calloc(size_t element_number, size_t element_size)
}
/// Seed used to generate random numbers.
int rseed = 0;
static int rseed = 0;
inline void srand(int x)
{
rseed = x;
}
#ifndef MS_RAND
/// The maximum value returned by the rand function.
#define RAND_MAX ((1U << 31) - 1)
/// @brief Returns a pseudo-random integral number in the range
/// between 0 and RAND_MAX.
inline int rand()
{
return rseed = (rseed * 1103515245 + 12345) & RAND_MAX;
return rseed = (rseed * 1103515245U + 12345U) & RAND_MAX;
}
// MS rand.
#else
/// The maximum 32bit value returned by the rand function.
#define RAND_MAX_32 ((1U << 31) - 1)
/// The maximum value returned by the rand function.
#define RAND_MAX ((1U << 15) - 1)
/// @brief Returns a pseudo-random integral number in the range
/// between 0 and RAND_MAX.
inline int rand()
{
return (rseed = (rseed * 214013 + 2531011) & RAND_MAX_32) >> 16;
}
<<<<<<< HEAD
#endif