source: trunk/libs/mini-libc/stdlib.h @ 458

Last change on this file since 458 was 445, checked in by alain, 7 years ago

Restructure the mini_libc.

File size: 6.3 KB
Line 
1/*
2 * stdlib.h - User level <stdlib> 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/*****************************************************************************************
28 * This file defines the user side <stdlib> library.
29 * Some functions make a system call to access the kernel VFS.
30 * The user/kernel shared structures and mnemonics are defined in
31 * the <syscalls/shared_include/shared_fcntl.h> file.
32 ****************************************************************************************/
33
34#include <shared_stdlib.h>
35
36/*****************************************************************************************
37 * This function terminates a process.
38 *****************************************************************************************
39 * @ status   : terminaison status : 0 / EXIT_SUCCESS / EXIT_FAILURE.
40 ****************************************************************************************/
41void exit( int status );
42
43/*********************************************************************************************
44 * This function translates an ascii character string to an integer value.
45 *********************************************************************************************
46 * @ str   : pointer on charactter string.
47 * @ return an integer value.
48 ********************************************************************************************/
49int atoi(const char * str );
50
51/*********************************************************************************************
52 * This function translates an ascii character string to a float value.
53 *********************************************************************************************
54 * @ str   : pointer on charactter string.
55 * @ return a double value.
56 ********************************************************************************************/
57double atof(const char * str );
58
59/*********************************************************************************************
60 * This function sets the seed for a new sequence of pseudo-random numbers to be returned
61 * by the rand function rand(). These sequences are repeatable by calling srand() with
62 * the same seed value.
63 *********************************************************************************************
64 * # seed  : seed value.
65 ********************************************************************************************/
66void srand( unsigned int seed );
67
68/*********************************************************************************************
69 * This function computes a sequence of pseudo-random integers in the range [0 to RAND_MAX].
70 *********************************************************************************************
71 * @ return an integer value between 0 and RAND_MAX.
72 ********************************************************************************************/
73int rand();
74
75/*****************************************************************************************
76 * This function allocates <size> bytes of memory in user space and returns a pointer
77 * on the allocated buffer. The physical memory is allocated from store located in
78 * the calling core cluster.
79 *****************************************************************************************
80 * @ size    : number of requested bytes.
81 * @ returns a pointer on the allocated buffer if success / returns NULL if failure
82 ****************************************************************************************/
83void * malloc( unsigned int size );
84
85/*****************************************************************************************
86 * This function releases the memory buffer identified by the <ptr> argument,
87 * to the store located in the calling core cluster.
88 * It displays an error message, but does nothing if the ptr is illegal.
89 *****************************************************************************************
90 * @ ptr   : pointer on the released buffer.
91 ****************************************************************************************/
92void free( void * ptr );
93
94/*****************************************************************************************
95 * This function releases the memory buffer identified by the <ptr> argument,
96 * to the store located in the calling core cluster, and allocates a new buffer
97 * containing <size> bytes from this store.
98 * The content of the old buffer is copied to the new buffer, up to <size> bytes.
99 * It displays an error message, but does nothing if the ptr is illegal.
100 *****************************************************************************************
101 * @ ptr   : pointer on the released buffer.
102 * @ size  : new buffer requested size (bytes).
103 * @ return a pointer on allocated buffer if success / return NULL if failure
104 ****************************************************************************************/
105void * realloc( void        * ptr,
106                unsigned int  size );
107
108
109/*****************************************************************************************
110 * This function allocates enough space for <count> objects that are <size> bytes
111 * of memory each from the store located in the calling core cluster.
112 * The allocated memory is filled with bytes of value zero.
113 *****************************************************************************************
114 * @ count   : number of requested objects.
115 * @ size    : number of bytes per object.
116 * @ returns a pointer on allocated buffer if success / returns NULL if failure
117 ****************************************************************************************/
118void * calloc( unsigned int count,
119               unsigned int size );
120
121#endif  // _STDLIB_H_
Note: See TracBrowser for help on using the repository browser.