source: mainline/uspace/lib/posix/stdlib.h@ 11544f4

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 11544f4 was 11544f4, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 14 years ago

Implement a few functions for dealing with temporary files.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * Copyright (c) 2011 Petr Koupy
3 * Copyright (c) 2011 Jiri Zarevucky
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup libposix
31 * @{
32 */
33/** @file Standard library definitions.
34 */
35
36#ifndef POSIX_STDLIB_H_
37#define POSIX_STDLIB_H_
38
39#include "libc/stdlib.h"
40
41#ifndef NULL
42 #define NULL ((void *) 0)
43#endif
44
45/* Process Termination */
46#undef EXIT_FAILURE
47#define EXIT_FAILURE 1
48#undef EXIT_SUCCESS
49#define EXIT_SUCCESS 0
50#define _Exit exit
51extern int posix_atexit(void (*func)(void));
52
53/* Absolute Value */
54extern int posix_abs(int i);
55extern long posix_labs(long i);
56extern long long posix_llabs(long long i);
57
58/* Integer Division */
59
60typedef struct {
61 int quot, rem;
62} posix_div_t;
63
64typedef struct {
65 long quot, rem;
66} posix_ldiv_t;
67
68typedef struct {
69 long long quot, rem;
70} posix_lldiv_t;
71
72extern posix_div_t posix_div(int numer, int denom);
73extern posix_ldiv_t posix_ldiv(long numer, long denom);
74extern posix_lldiv_t posix_lldiv(long long numer, long long denom);
75
76/* Array Functions */
77extern void posix_qsort(void *array, size_t count, size_t size,
78 int (*compare)(const void *, const void *));
79extern void *posix_bsearch(const void *key, const void *base,
80 size_t nmemb, size_t size, int (*compar)(const void *, const void *));
81
82/* Environment Access */
83extern char *posix_getenv(const char *name);
84extern int posix_putenv(char *string);
85extern int posix_system(const char *string);
86
87/* Symbolic Links */
88extern char *posix_realpath(const char *restrict name, char *restrict resolved);
89
90/* Floating Point Conversion */
91extern double posix_atof(const char *nptr);
92extern float posix_strtof(const char *restrict nptr, char **restrict endptr);
93extern double posix_strtod(const char *restrict nptr, char **restrict endptr);
94extern long double posix_strtold(const char *restrict nptr, char **restrict endptr);
95
96/* Integer Conversion */
97extern int posix_atoi(const char *nptr);
98extern long int posix_atol(const char *nptr);
99extern long long int posix_atoll(const char *nptr);
100extern long int posix_strtol(const char *restrict nptr,
101 char **restrict endptr, int base);
102extern long long int posix_strtoll(const char *restrict nptr,
103 char **restrict endptr, int base);
104extern unsigned long int posix_strtoul(const char *restrict nptr,
105 char **restrict endptr, int base);
106extern unsigned long long int posix_strtoull(
107 const char *restrict nptr, char **restrict endptr, int base);
108
109/* Memory Allocation */
110extern void *posix_malloc(size_t size);
111extern void *posix_calloc(size_t nelem, size_t elsize);
112extern void *posix_realloc(void *ptr, size_t size);
113extern void posix_free(void *ptr);
114
115/* Temporary files */
116extern int posix_mkstemp(char *tmpl);
117
118/* Legacy Declarations */
119extern char *posix_mktemp(char *tmpl);
120extern int bsd_getloadavg(double loadavg[], int nelem);
121
122#ifndef LIBPOSIX_INTERNAL
123 #define atexit posix_atexit
124
125 #define abs posix_abs
126 #define labs posix_labs
127 #define llabs posix_llabs
128
129 #define div_t posix_div_t
130 #define ldiv_t posix_ldiv_t
131 #define lldiv_t posix_lldiv_t
132 #define div posix_div
133 #define ldiv posix_ldiv
134 #define lldiv posix_lldiv
135
136 #define qsort posix_qsort
137 #define bsearch posix_bsearch
138
139 #define getenv posix_getenv
140 #define putenv posix_putenv
141 #define system posix_system
142
143 #define realpath posix_realpath
144
145 #define atof posix_atof
146 #define strtof posix_strtof
147 #define strtod posix_strtod
148 #define strtold posix_strtold
149
150 #define atoi posix_atoi
151 #define atol posix_atol
152 #define atoll posix_atoll
153 #define strtol posix_strtol
154 #define strtoll posix_strtoll
155 #define strtoul posix_strtoul
156 #define strtoull posix_strtoull
157
158 #define malloc posix_malloc
159 #define calloc posix_calloc
160 #define realloc posix_realloc
161 #define free posix_free
162
163 #define mkstemp posix_mkstemp
164
165 #define mktemp posix_mktemp
166 #define getloadavg bsd_getloadavg
167#endif
168
169#endif // POSIX_STDLIB_H_
170
171/** @}
172 */
Note: See TracBrowser for help on using the repository browser.