[439] | 1 | /* |
---|
| 2 | * stdlib.h - User level library definition. |
---|
| 3 | * |
---|
| 4 | * Author Alain Greiner (2016,2017) |
---|
| 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #ifndef _STDLIB_H_ |
---|
| 25 | #define _STDLIB_H |
---|
| 26 | |
---|
| 27 | #define RAND_MAX 65535 |
---|
| 28 | |
---|
| 29 | /********************************************************************************************* |
---|
| 30 | * This function tests the <expression> argument value. |
---|
| 31 | * When the value is false, it displays an error message, and terminates the calling thread. |
---|
| 32 | ********************************************************************************************* |
---|
| 33 | * @ expression : Boolean expression to be checked. |
---|
| 34 | ********************************************************************************************/ |
---|
| 35 | void assert( int expression ); |
---|
| 36 | |
---|
| 37 | /********************************************************************************************* |
---|
| 38 | * This function TODO |
---|
| 39 | ********************************************************************************************* |
---|
| 40 | ********************************************************************************************/ |
---|
| 41 | int atoi(const char *str); |
---|
| 42 | |
---|
| 43 | /********************************************************************************************* |
---|
| 44 | * This function TODO |
---|
| 45 | ********************************************************************************************* |
---|
| 46 | ********************************************************************************************/ |
---|
| 47 | double atof(const char *str); |
---|
| 48 | |
---|
| 49 | /********************************************************************************************* |
---|
| 50 | * This function copies the content of a <src> byte array to a <dst> byte array. |
---|
| 51 | * Behaviour is undefined if <src> and <dst> arrays overlap. |
---|
| 52 | ********************************************************************************************* |
---|
| 53 | * @ dst : pointer on destination array. |
---|
| 54 | * @ dst : pointer on source array. |
---|
| 55 | * @ size : number of bytes to move. |
---|
| 56 | * @ return first argument. |
---|
| 57 | ********************************************************************************************/ |
---|
| 58 | void * memcpy( void * dst, |
---|
| 59 | const void * src, |
---|
| 60 | unsigned int size ); |
---|
| 61 | |
---|
| 62 | /********************************************************************************************* |
---|
| 63 | * This function fill a byte array with a byte value. |
---|
| 64 | ********************************************************************************************* |
---|
| 65 | * @ dst : pointer on the byte array. |
---|
| 66 | * @ s : byte value (will be casted to unsigned char). |
---|
| 67 | * @ size : number of bytes to be set. |
---|
| 68 | * @ return first argument. |
---|
| 69 | ********************************************************************************************/ |
---|
| 70 | void * memset( void * dst, |
---|
| 71 | int s, |
---|
| 72 | unsigned int size); |
---|
| 73 | |
---|
| 74 | /********************************************************************************************* |
---|
| 75 | * This function writes a formated string to the standard "stdout" stream. |
---|
| 76 | ********************************************************************************************* |
---|
| 77 | * @ returns number of characters written if success / returns -1 if failure. |
---|
| 78 | ********************************************************************************************/ |
---|
| 79 | int printf( const char * format, ... ); |
---|
| 80 | |
---|
| 81 | /********************************************************************************************* |
---|
| 82 | * This function returns a positive integer fom the standard "stdin" stream. |
---|
| 83 | ********************************************************************************************* |
---|
| 84 | * returns the integer value if success / returns -1 if failure. |
---|
| 85 | ********************************************************************************************/ |
---|
| 86 | int getint(); |
---|
| 87 | |
---|
| 88 | /********************************************************************************************* |
---|
| 89 | * This function writes one single character to the standard "stdout" stream. |
---|
| 90 | ********************************************************************************************* |
---|
| 91 | * @ returns written character code if success / returns 0 (EOF) if failure. |
---|
| 92 | ********************************************************************************************/ |
---|
| 93 | int putchar( int c ); |
---|
| 94 | |
---|
| 95 | /********************************************************************************************* |
---|
| 96 | * This function returns one single character from the standard "stdin" stream. |
---|
| 97 | ********************************************************************************************* |
---|
| 98 | * @ returns read character code if success / returns 0 (EOF) if failure. |
---|
| 99 | ********************************************************************************************/ |
---|
| 100 | int getchar(); |
---|
| 101 | |
---|
| 102 | /********************************************************************************************* |
---|
| 103 | * This function copies a formated string to a fixed size buffer. |
---|
| 104 | * it includes the NUL terminating character. |
---|
| 105 | * it cheks that the formated string fit in the buffer length. |
---|
| 106 | ********************************************************************************************* |
---|
| 107 | * @ string : pointer on target buffer. |
---|
| 108 | * @ length : max bumber of characters in target buffer. |
---|
| 109 | * @ format : formated string. |
---|
| 110 | * @ returns number of characters written if success / returns -1 if failure. |
---|
| 111 | ********************************************************************************************/ |
---|
| 112 | int snprintf( char * string, |
---|
| 113 | unsigned int length, |
---|
| 114 | const char * format, ... ); |
---|
| 115 | |
---|
| 116 | /********************************************************************************************* |
---|
| 117 | * This function sets the seed for a new sequence of pseudo-random numbers to be returned |
---|
| 118 | * by the rand function rand(). These sequences are repeatable by calling srand() with |
---|
| 119 | * the same seed value. |
---|
| 120 | ********************************************************************************************* |
---|
| 121 | * # seed : seed value. |
---|
| 122 | ********************************************************************************************/ |
---|
| 123 | void srand( unsigned int seed ); |
---|
| 124 | |
---|
| 125 | /********************************************************************************************* |
---|
| 126 | * This function computes a sequence of pseudo-random integers in the range [0 to RAND_MAX]. |
---|
| 127 | ********************************************************************************************* |
---|
| 128 | * @ return an integer value between 0 and RAND_MAX. |
---|
| 129 | ********************************************************************************************/ |
---|
| 130 | int rand(); |
---|
| 131 | |
---|
| 132 | #endif // _STDLIB_H_ |
---|