aboutsummaryrefslogtreecommitdiffstats
path: root/include/stdlib.h
blob: c26934d1e9bdf678093a3ddb0fae322e5402f772 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
 * @file stdlib.h
 * Provides missing C standard library functions
 * The newlib versions of these calls are not being used due to dependence on
 * unsupported system calls.
 *
 * Copyright (C) 2018 Clyne Sullivan
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef STDLIB_H_
#define STDLIB_H_

/**
 * Parses a formatted string, storing the result in the given buffer.
 * @param buf the buffer to print the parsed string to
 * @param max the maximum number of bytes to write to the buffer
 * @param format the format string
 * @return a pointer to the buffer
 */
char *snprintf(char *buf, unsigned int max, const char *format, ...);

/**
 * Attempts to convert the given string to a float.
 * @param s the string to convert
 * @param endptr if not-null, set to the address of the character after the
 * number
 * @return the resulting float, or zero if an error occurred
 */
float strtof(const char *s, char **endptr);

char *ftostr(char *buf, float f);

/**
 * Attempts to convert the given string to an integer.
 * @param s the string to convert
 * @return the resulting integer, or zero if an error occurred
 */
int atoi(const char *s);

#endif // STDLIB_H_