AVR-LibC  2.2.0
Standard C library for AVR-GCC
 

AVR-LibC Documentation

Logo

AVR-LibC Development Pages

Main Page

User Manual

Library Reference

FAQ

Example Projects

File List

Loading...
Searching...
No Matches
stdlib.h
Go to the documentation of this file.
1/* Copyright (c) 2002, Marek Michalkiewicz
2 Copyright (c) 2004,2007 Joerg Wunsch
3
4 Portions of documentation Copyright (c) 1990, 1991, 1993, 1994
5 The Regents of the University of California.
6
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14
15 * Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in
17 the documentation and/or other materials provided with the
18 distribution.
19
20 * Neither the name of the copyright holders nor the names of
21 contributors may be used to endorse or promote products derived
22 from this software without specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35
36 $Id$
37*/
38
39#ifndef _STDLIB_H_
40#define _STDLIB_H_ 1
41
42#ifndef __ASSEMBLER__
43
44#ifndef __DOXYGEN__
45#define __need_NULL
46#define __need_size_t
47#define __need_wchar_t
48#include <stddef.h>
49
50#ifndef __ptr_t
51#define __ptr_t void *
52#endif
53#endif /* !__DOXYGEN__ */
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
59/** \file */
60
61/** \defgroup avr_stdlib <stdlib.h>: General utilities
62 \code #include <stdlib.h> \endcode
63
64 This file declares some basic C macros and functions as
65 defined by the ISO standard, plus some AVR-specific extensions.
66*/
67
68/** \ingroup avr_stdlib */
69/**@{*/
70/** Result type for function div(). */
71typedef struct {
72 int quot; /**< The Quotient. */
73 int rem; /**< The Remainder. */
74} div_t;
75
76/** Result type for function ldiv(). */
77typedef struct {
78 long quot; /**< The Quotient. */
79 long rem; /**< The Remainder. */
80} ldiv_t;
81
82/** Comparision function type for qsort(), just for convenience. */
83typedef int (*__compar_fn_t)(const void *, const void *);
84
85#ifndef __DOXYGEN__
86
87#ifndef __ATTR_CONST__
88# define __ATTR_CONST__ __attribute__((__const__))
89#endif
90
91#ifndef __ATTR_MALLOC__
92# define __ATTR_MALLOC__ __attribute__((__malloc__))
93#endif
94
95#ifndef __ATTR_NORETURN__
96# define __ATTR_NORETURN__ __attribute__((__noreturn__))
97#endif
98
99#ifndef __ATTR_PURE__
100# define __ATTR_PURE__ __attribute__((__pure__))
101#endif
102
103#ifndef __ATTR_GNU_INLINE__
104# ifdef __GNUC_STDC_INLINE__
105# define __ATTR_GNU_INLINE__ __attribute__((__gnu_inline__))
106# else
107# define __ATTR_GNU_INLINE__
108# endif
109#endif
110
111#ifndef __ATTR_ALWAYS_INLINE__
112#define __ATTR_ALWAYS_INLINE__ __inline__ __attribute__((__always_inline__))
113#endif
114
115#endif
116
117/** The abort() function causes abnormal program termination to occur.
118 This realization disables interrupts and jumps to _exit() function
119 with argument equal to 1. In the limited AVR environment, execution is
120 effectively halted by entering an infinite loop. */
121extern void abort(void) __ATTR_NORETURN__;
122
123#ifndef __DOXYGEN__
124static __ATTR_ALWAYS_INLINE__
125int abs (int __i)
126{
127 return __builtin_abs (__i);
128}
129#endif
130/** The abs() function computes the absolute value of the integer \c i.
131 \note The abs() and labs() functions are builtins of gcc.
132*/
133extern int abs(int __i) __ATTR_CONST__;
134
135#ifndef __DOXYGEN__
136static __ATTR_ALWAYS_INLINE__
137long labs (long __i)
138{
139 return __builtin_labs (__i);
140}
141#endif
142/** The labs() function computes the absolute value of the long integer
143 \c i.
144 \note The abs() and labs() functions are builtins of gcc.
145*/
146extern long labs(long __i) __ATTR_CONST__;
147
148/**
149 The bsearch() function searches an array of \c nmemb objects, the
150 initial member of which is pointed to by \c base, for a member
151 that matches the object pointed to by \c key. The size of each
152 member of the array is specified by \c size.
153
154 The contents of the array should be in ascending sorted order
155 according to the comparison function referenced by \c compar.
156 The \c compar routine is expected to have two arguments which
157 point to the key object and to an array member, in that order,
158 and should return an integer less than, equal to, or greater than
159 zero if the key object is found, respectively, to be less than,
160 to match, or be greater than the array member.
161
162 The bsearch() function returns a pointer to a matching member of
163 the array, or a null pointer if no match is found. If two
164 members compare as equal, which member is matched is unspecified.
165*/
166extern void *bsearch(const void *__key, const void *__base, size_t __nmemb,
167 size_t __size, int (*__compar)(const void *, const void *));
168
169/* __divmodhi4 and __divmodsi4 from libgcc.a */
170/**
171 The div() function computes the value \c num/denom and returns
172 the quotient and remainder in a structure named \c div_t that
173 contains two int members named \c quot and \c rem.
174*/
175extern div_t div(int __num, int __denom) __asm__("__divmodhi4") __ATTR_CONST__;
176/**
177 The ldiv() function computes the value \c num/denom and returns
178 the quotient and remainder in a structure named \c ldiv_t that
179 contains two long integer members named \c quot and \c rem.
180*/
181extern ldiv_t ldiv(long __num, long __denom) __asm__("__divmodsi4") __ATTR_CONST__;
182
183/**
184 The qsort() function is a modified partition-exchange sort, or
185 quicksort.
186
187 The qsort() function sorts an array of \c nmemb objects, the
188 initial member of which is pointed to by \c base. The size of
189 each object is specified by \c size. The contents of the array
190 base are sorted in ascending order according to a comparison
191 function pointed to by \c compar, which requires two arguments
192 pointing to the objects being compared.
193
194 The comparison function must return an integer less than, equal
195 to, or greater than zero if the first argument is considered to
196 be respectively less than, equal to, or greater than the second.
197*/
198extern void qsort(void *__base, size_t __nmemb, size_t __size,
199 __compar_fn_t __compar);
200
201/**
202 The strtol() function converts the string in \c nptr to a long
203 value. The conversion is done according to the given base, which
204 must be between 2 and 36 inclusive, or be the special value 0.
205
206 The string may begin with an arbitrary amount of white space (as
207 determined by isspace()) followed by a single optional \c '+' or \c '-'
208 sign. If \c base is zero or 16, the string may then include a
209 \c "0x" prefix, and the number will be read in base 16; otherwise,
210 a zero base is taken as 10 (decimal) unless the next character is
211 \c '0', in which case it is taken as 8 (octal).
212
213 The remainder of the string is converted to a long value in the
214 obvious manner, stopping at the first character which is not a
215 valid digit in the given base. (In bases above 10, the letter \c 'A'
216 in either upper or lower case represents 10, \c 'B' represents 11,
217 and so forth, with \c 'Z' representing 35.)
218
219 If \c endptr is not NULL, strtol() stores the address of the first
220 invalid character in \c *endptr. If there were no digits at all,
221 however, strtol() stores the original value of \c nptr in \c
222 *endptr. (Thus, if \c *nptr is not \c '\\0' but \c **endptr is \c '\\0'
223 on return, the entire string was valid.)
224
225 The strtol() function returns the result of the conversion, unless
226 the value would underflow or overflow. If no conversion could be
227 performed, 0 is returned. If an overflow or underflow occurs, \c
228 errno is set to \ref avr_errno "ERANGE" and the function return value
229 is clamped to \c LONG_MIN or \c LONG_MAX, respectively.
230*/
231extern long strtol(const char *__nptr, char **__endptr, int __base);
232
233/**
234 The strtoul() function converts the string in \c nptr to an
235 unsigned long value. The conversion is done according to the
236 given base, which must be between 2 and 36 inclusive, or be the
237 special value 0.
238
239 The string may begin with an arbitrary amount of white space (as
240 determined by isspace()) followed by a single optional \c '+' or \c '-'
241 sign. If \c base is zero or 16, the string may then include a
242 \c "0x" prefix, and the number will be read in base 16; otherwise,
243 a zero base is taken as 10 (decimal) unless the next character is
244 \c '0', in which case it is taken as 8 (octal).
245
246 The remainder of the string is converted to an unsigned long value
247 in the obvious manner, stopping at the first character which is
248 not a valid digit in the given base. (In bases above 10, the
249 letter \c 'A' in either upper or lower case represents 10, \c 'B'
250 represents 11, and so forth, with \c 'Z' representing 35.)
251
252 If \c endptr is not NULL, strtoul() stores the address of the first
253 invalid character in \c *endptr. If there were no digits at all,
254 however, strtoul() stores the original value of \c nptr in \c
255 *endptr. (Thus, if \c *nptr is not \c '\\0' but \c **endptr is \c '\\0'
256 on return, the entire string was valid.)
257
258 The strtoul() function return either the result of the conversion
259 or, if there was a leading minus sign, the negation of the result
260 of the conversion, unless the original (non-negated) value would
261 overflow; in the latter case, strtoul() returns ULONG_MAX, and \c
262 errno is set to \ref avr_errno "ERANGE". If no conversion could
263 be performed, 0 is returned.
264*/
265extern unsigned long strtoul(const char *__nptr, char **__endptr, int __base);
266
267/**
268 The atol() function converts the initial portion of the string
269 pointed to by \p s to long integer representation. In contrast to
270
271 \code strtol(s, (char **)NULL, 10); \endcode
272
273 this function does not detect overflow (\c errno is not changed and
274 the result value is not predictable), uses smaller memory (flash and
275 stack) and works more quickly.
276*/
277extern long atol(const char *__s) __ATTR_PURE__;
278
279/**
280 The atoi() function converts the initial portion of the string
281 pointed to by \p s to integer representation. In contrast to
282
283 \code (int)strtol(s, (char **)NULL, 10); \endcode
284
285 this function does not detect overflow (\c errno is not changed and
286 the result value is not predictable), uses smaller memory (flash and
287 stack) and works more quickly.
288*/
289extern int atoi(const char *__s) __ATTR_PURE__;
290
291/**
292 The exit() function terminates the application. Since there is no
293 environment to return to, \c status is ignored, and code execution
294 will eventually reach an infinite loop, thereby effectively halting
295 all code processing. Before entering the infinite loop, interrupts
296 are globally disabled.
297
298 Global destructors will be called before halting
299 execution, see the \ref sec_dot_fini ".fini" sections.
300*/
301extern void exit(int __status) __ATTR_NORETURN__;
302
303/**
304 The malloc() function allocates \c size bytes of memory.
305 If malloc() fails, a NULL pointer is returned.
306
307 Note that malloc() does \e not initialize the returned memory to
308 zero bytes.
309
310 See the chapter about \ref malloc "malloc() usage" for implementation
311 details.
312*/
313extern void *malloc(size_t __size) __ATTR_MALLOC__;
314
315/**
316 The free() function causes the allocated memory referenced by \c
317 ptr to be made available for future allocations. If \c ptr is
318 NULL, no action occurs.
319*/
320extern void free(void *__ptr);
321
322/**
323 \c malloc() \ref malloc_tunables "tunable".
324*/
325extern size_t __malloc_margin;
326
327/**
328 \c malloc() \ref malloc_tunables "tunable".
329*/
330extern char *__malloc_heap_start;
331
332/**
333 \c malloc() \ref malloc_tunables "tunable".
334*/
335extern char *__malloc_heap_end;
336
337/**
338 Allocate \c nele elements of \c size each. Identical to calling
339 \c malloc() using <tt>nele * size</tt> as argument, except the
340 allocated memory will be cleared to zero.
341*/
342extern void *calloc(size_t __nele, size_t __size) __ATTR_MALLOC__;
343
344/**
345 The realloc() function tries to change the size of the region
346 allocated at \c ptr to the new \c size value. It returns a
347 pointer to the new region. The returned pointer might be the
348 same as the old pointer, or a pointer to a completely different
349 region.
350
351 The contents of the returned region up to either the old or the new
352 size value (whatever is less) will be identical to the contents of
353 the old region, even in case a new region had to be allocated.
354
355 It is acceptable to pass \c ptr as NULL, in which case realloc()
356 will behave identical to malloc().
357
358 If the new memory cannot be allocated, realloc() returns NULL, and
359 the region at \c ptr will not be changed.
360*/
361extern void *realloc(void *__ptr, size_t __size) __ATTR_MALLOC__;
362
363extern float strtof(const char *__nptr, char **__endptr);
364/** \ingroup avr_stdlib
365 The strtod() function is similar to strtof(), except that the conversion
366 result is of type \c double instead of \c float.
367
368 strtod() is currently only supported when \c double is a 32-bit type. */
369extern double strtod(const char *__nptr, char **__endptr);
370/** \ingroup avr_stdlib
371 The strtold() function is similar to strtof(), except that the conversion
372 result is of type \c long \c double instead of \c float.
373
374 strtold() is currently only supported when \c long \c double is a
375 32-bit type. */
376extern long double strtold(const char *__nptr, char **__endptr);
377
378/**
379 \ingroup avr_stdlib
380 The atexit() function registers function \a func to be run as part of
381 the \c exit() function during \ref sec_dot_fini ".fini8".
382 atexit() calls malloc().
383 */
384extern int atexit(void (*func)(void));
385
386/** \ingroup avr_stdlib
387 \fn float atoff (const char *nptr)
388
389 The atoff() function converts the initial portion of the string pointed
390 to by \a nptr to \c float representation.
391
392 It is equivalent to calling
393 \code strtof(nptr, (char**) 0); \endcode */
394extern float atoff(const char *__nptr);
395/** \ingroup avr_stdlib
396 \fn double atof (const char *nptr)
397
398 The atof() function converts the initial portion of the string pointed
399 to by \a nptr to \c double representation.
400
401 It is equivalent to calling
402 \code strtod(nptr, (char**) 0); \endcode */
403extern double atof(const char *__nptr);
404/** \ingroup avr_stdlib
405 \fn long double atofl (const char *nptr)
406
407 The atofl() function converts the initial portion of the string pointed
408 to by \a nptr to \c long \c double representation.
409
410 It is equivalent to calling
411 \code strtold(nptr, (char**) 0); \endcode */
412extern long double atofl(const char *__nptr);
413
414/** Highest number that can be generated by rand(). */
415#define RAND_MAX 0x7FFF
416
417/**
418 The rand() function computes a sequence of pseudo-random integers in the
419 range of 0 to \c RAND_MAX (as defined by the header file <stdlib.h>).
420
421 The srand() function sets its argument \c seed as the seed for a new
422 sequence of pseudo-random numbers to be returned by rand(). These
423 sequences are repeatable by calling srand() with the same seed value.
424
425 If no seed value is provided, the functions are automatically seeded with
426 a value of 1.
427
428 In compliance with the C standard, these functions operate on
429 \c int arguments. Since the underlying algorithm already uses
430 32-bit calculations, this causes a loss of precision. See
431 \c random() for an alternate set of functions that retains full
432 32-bit precision.
433*/
434extern int rand(void);
435/**
436 Pseudo-random number generator seeding; see rand().
437*/
438extern void srand(unsigned int __seed);
439
440/**
441 Variant of rand() that stores the context in the user-supplied
442 variable located at \c ctx instead of a static library variable
443 so the function becomes re-entrant.
444*/
445extern int rand_r(unsigned long *__ctx);
446/**@}*/
447
448/**@{*/
449/** \name Non-standard (i.e. non-ISO C) functions.
450 \ingroup avr_stdlib
451*/
452/**
453 \brief Convert an integer to a string.
454
455 The function itoa() converts the integer value from \c val into an
456 ASCII representation that will be stored under \c s. The caller
457 is responsible for providing sufficient storage in \c s.
458
459 \note The minimal size of the buffer \c s depends on the choice of
460 radix. For example, if the radix is 2 (binary), you need to supply a buffer
461 with a minimal length of 8 * sizeof (int) + 1 characters, i.e. one
462 character for each bit plus one for the string terminator. Using a larger
463 radix will require a smaller minimal buffer size.
464
465 \warning If the buffer is too small, you risk a buffer overflow.
466
467 Conversion is done using the \c radix as base, which may be a
468 number between 2 (binary conversion) and up to 36. If \c radix
469 is greater than 10, the next digit after \c '9' will be the letter
470 \c 'a'.
471
472 If radix is 10 and val is negative, a minus sign will be prepended.
473
474 The itoa() function returns the pointer passed as \c s.
475*/
476#ifdef __DOXYGEN__
477extern char *itoa(int val, char *s, int radix);
478#else
479extern __inline__ __ATTR_GNU_INLINE__
480char *itoa (int __val, char *__s, int __radix)
481{
482 if (!__builtin_constant_p (__radix)) {
483 extern char *__itoa (int, char *, int);
484 return __itoa (__val, __s, __radix);
485 } else if (__radix < 2 || __radix > 36) {
486 *__s = 0;
487 return __s;
488 } else {
489 extern char *__itoa_ncheck (int, char *, unsigned char);
490 return __itoa_ncheck (__val, __s, __radix);
491 }
492}
493#endif
494
495/**
496 \ingroup avr_stdlib
497
498 \brief Convert a long integer to a string.
499
500 The function ltoa() converts the long integer value from \c val into an
501 ASCII representation that will be stored under \c s. The caller
502 is responsible for providing sufficient storage in \c s.
503
504 \note The minimal size of the buffer \c s depends on the choice of
505 radix. For example, if the radix is 2 (binary), you need to supply a buffer
506 with a minimal length of 8 * sizeof (long int) + 1 characters, i.e. one
507 character for each bit plus one for the string terminator. Using a larger
508 radix will require a smaller minimal buffer size.
509
510 \warning If the buffer is too small, you risk a buffer overflow.
511
512 Conversion is done using the \c radix as base, which may be a
513 number between 2 (binary conversion) and up to 36. If \c radix
514 is greater than 10, the next digit after \c '9' will be the letter
515 \c 'a'.
516
517 If radix is 10 and val is negative, a minus sign will be prepended.
518
519 The ltoa() function returns the pointer passed as \c s.
520*/
521#ifdef __DOXYGEN__
522extern char *ltoa(long val, char *s, int radix);
523#else
524extern __inline__ __ATTR_GNU_INLINE__
525char *ltoa (long __val, char *__s, int __radix)
526{
527 if (!__builtin_constant_p (__radix))
528 {
529 extern char *__ltoa (long, char *, int);
530 return __ltoa (__val, __s, __radix);
531 }
532 else if (__radix < 2 || __radix > 36)
533 {
534 *__s = 0;
535 return __s;
536 }
537 else
538 {
539 extern char *__ltoa_ncheck (long, char *, unsigned char);
540 return __ltoa_ncheck (__val, __s, __radix);
541 }
542}
543#endif
544
545/**
546 \ingroup avr_stdlib
547
548 \brief Convert an unsigned integer to a string.
549
550 The function utoa() converts the unsigned integer value from \c val into an
551 ASCII representation that will be stored under \c s. The caller
552 is responsible for providing sufficient storage in \c s.
553
554 \note The minimal size of the buffer \c s depends on the choice of
555 radix. For example, if the radix is 2 (binary), you need to supply a buffer
556 with a minimal length of 8 * sizeof (unsigned int) + 1 characters, i.e. one
557 character for each bit plus one for the string terminator. Using a larger
558 radix will require a smaller minimal buffer size.
559
560 \warning If the buffer is too small, you risk a buffer overflow.
561
562 Conversion is done using the \c radix as base, which may be a
563 number between 2 (binary conversion) and up to 36. If \c radix
564 is greater than 10, the next digit after \c '9' will be the letter
565 \c 'a'.
566
567 The utoa() function returns the pointer passed as \c s.
568*/
569#ifdef __DOXYGEN__
570extern char *utoa(unsigned int val, char *s, int radix);
571#else
572extern __inline__ __ATTR_GNU_INLINE__
573char *utoa (unsigned int __val, char *__s, int __radix)
574{
575 if (!__builtin_constant_p (__radix))
576 {
577 extern char *__utoa (unsigned int, char *, int);
578 return __utoa (__val, __s, __radix);
579 }
580 else if (__radix < 2 || __radix > 36)
581 {
582 *__s = 0;
583 return __s;
584 }
585 else
586 {
587 extern char *__utoa_ncheck (unsigned int, char *, unsigned char);
588 return __utoa_ncheck (__val, __s, __radix);
589 }
590}
591#endif
592
593/**
594 \ingroup avr_stdlib
595 \brief Convert an unsigned long integer to a string.
596
597 The function ultoa() converts the unsigned long integer value from
598 \c val into an ASCII representation that will be stored under \c s.
599 The caller is responsible for providing sufficient storage in \c s.
600
601 \note The minimal size of the buffer \c s depends on the choice of
602 radix. For example, if the radix is 2 (binary), you need to supply a buffer
603 with a minimal length of 8 * sizeof (unsigned long int) + 1 characters,
604 i.e. one character for each bit plus one for the string terminator. Using a
605 larger radix will require a smaller minimal buffer size.
606
607 \warning If the buffer is too small, you risk a buffer overflow.
608
609 Conversion is done using the \c radix as base, which may be a
610 number between 2 (binary conversion) and up to 36. If \c radix
611 is greater than 10, the next digit after \c '9' will be the letter
612 \c 'a'.
613
614 The ultoa() function returns the pointer passed as \c s.
615*/
616#ifdef __DOXYGEN__
617extern char *ultoa(unsigned long val, char *s, int radix);
618#else
619extern __inline__ __ATTR_GNU_INLINE__
620char *ultoa (unsigned long __val, char *__s, int __radix)
621{
622 if (!__builtin_constant_p (__radix)) {
623 extern char *__ultoa (unsigned long, char *, int);
624 return __ultoa (__val, __s, __radix);
625 } else if (__radix < 2 || __radix > 36) {
626 *__s = 0;
627 return __s;
628 } else {
629 extern char *__ultoa_ncheck (unsigned long, char *, unsigned char);
630 return __ultoa_ncheck (__val, __s, __radix);
631 }
632}
633#endif
634
635/** \ingroup avr_stdlib
636Highest number that can be generated by random(). */
637#define RANDOM_MAX 0x7FFFFFFF
638
639/**
640 \ingroup avr_stdlib
641 The random() function computes a sequence of pseudo-random integers in the
642 range of 0 to \c RANDOM_MAX (as defined by the header file <stdlib.h>).
643
644 The srandom() function sets its argument \c seed as the seed for a new
645 sequence of pseudo-random numbers to be returned by rand(). These
646 sequences are repeatable by calling srandom() with the same seed value.
647
648 If no seed value is provided, the functions are automatically seeded with
649 a value of 1.
650*/
651extern long random(void);
652/**
653 \ingroup avr_stdlib
654 Pseudo-random number generator seeding; see random().
655*/
656extern void srandom(unsigned long __seed);
657
658/**
659 \ingroup avr_stdlib
660 Variant of random() that stores the context in the user-supplied
661 variable located at \c ctx instead of a static library variable
662 so the function becomes re-entrant.
663*/
664extern long random_r(unsigned long *__ctx);
665#endif /* __ASSEMBLER */
666/**@}*/
667
668/**@{*/
669/** \name Conversion functions for double arguments. */
670/** \ingroup avr_stdlib
671 Bit value that can be passed in \c flags to ftostre(),
672 dtostre() and ldtostre(). */
673#define DTOSTR_ALWAYS_SIGN 0x01 /* put '+' or ' ' for positives */
674/** \ingroup avr_stdlib
675 Bit value that can be passed in \c flags to ftostre(),
676 dtostre() and ldtostre(). */
677#define DTOSTR_PLUS_SIGN 0x02 /* put '+' rather than ' ' */
678/** \ingroup avr_stdlib
679 Bit value that can be passed in \c flags to ftostre(),
680 dtostre() and ldtostre(). */
681#define DTOSTR_UPPERCASE 0x04 /* put 'E' rather 'e' */
682
683#ifndef __ASSEMBLER__
684
685/**
686 \ingroup avr_stdlib
687 The ftostre() function converts the \c float value passed in \c val into
688 an ASCII representation that will be stored under \c s. The caller
689 is responsible for providing sufficient storage in \c s.
690
691 Conversion is done in the format
692 <tt>&quot;[-]d.ddde&plusmn;dd&quot;</tt> where there is
693 one digit before the decimal-point character and the number of
694 digits after it is equal to the precision \c prec; if the precision
695 is zero, no decimal-point character appears. If \c flags has the
696 #DTOSTR_UPPERCASE bit set, the letter \c 'E' (rather than \c 'e' ) will be
697 used to introduce the exponent. The exponent always contains two
698 digits; if the value is zero, the exponent is \c "00".
699
700 If \c flags has the #DTOSTR_ALWAYS_SIGN bit set, a space character
701 will be placed into the leading position for positive numbers.
702
703 If \c flags has the #DTOSTR_PLUS_SIGN bit set, a plus sign will be
704 used instead of a space character in this case.
705
706 The ftostre() function returns the pointer to the converted string \c s.
707*/
708extern char *ftostre(float __val, char *__s, unsigned char __prec,
709 unsigned char __flags);
710/**
711 \ingroup avr_stdlib
712 The dtostre() function is similar to the ftostre() function, except that
713 it converts a \c double value instead of a \c float value.
714
715 dtostre() is currently only supported when \c double is a 32-bit type. */
716extern char *dtostre(double __val, char *__s, unsigned char __prec,
717 unsigned char __flags);
718/**
719 \ingroup avr_stdlib
720 The ldtostre() function is similar to the ftostre() function, except that
721 it converts a \c long \c double value instead of a \c float value.
722
723 ldtostre() is currently only supported when \c long \c double is a
724 32-bit type. */
725extern char *ldtostre(long double __val, char *__s, unsigned char __prec,
726 unsigned char __flags);
727
728/**
729 \ingroup avr_stdlib
730 The ftostrf() function converts the \c float value passed in \c val into
731 an ASCII representationthat will be stored in \c s. The caller
732 is responsible for providing sufficient storage in \c s.
733
734 Conversion is done in the format \c "[-]d.ddd". The minimum field
735 width of the output string (including the possible \c '.' and the possible
736 sign for negative values) is given in \c width, and \c prec determines
737 the number of digits after the decimal sign. \c width is signed value,
738 negative for left adjustment.
739
740 The ftostrf() function returns the pointer to the converted string \c s.
741*/
742extern char *ftostrf(float __val, signed char __width,
743 unsigned char __prec, char *__s);
744/**
745 \ingroup avr_stdlib
746 The dtostrf() function is similar to the ftostrf() function, except that
747 converts a \c double value instead of a \c float value.
748
749 ldtostre() is currently only supported when \c double is a 32-bit type. */
750extern char *dtostrf(double __val, signed char __width,
751 unsigned char __prec, char *__s);
752/**
753 \ingroup avr_stdlib
754 The ldtostrf() function is similar to the ftostrf() function, except that
755 converts a \c long \c double value instead of a \c float value.
756
757 ldtostre() is currently only supported when \c long \c double is a
758 32-bit type. */
759extern char *ldtostrf(long double __val, signed char __width,
760 unsigned char __prec, char *__s);
761
762/**
763 \ingroup avr_stdlib
764 Successful termination for exit(); evaluates to 0.
765*/
766#define EXIT_SUCCESS 0
767
768/**
769 \ingroup avr_stdlib
770 Unsuccessful termination for exit(); evaluates to a non-zero value.
771*/
772#define EXIT_FAILURE 1
773
774/**@}*/
775
776#ifndef __DOXYGEN__
777/* dummy declarations for libstdc++ compatibility */
778extern int system (const char *);
779extern char *getenv (const char *);
780#endif /* __DOXYGEN__ */
781
782#ifdef __cplusplus
783}
784#endif
785
786#endif /* __ASSEMBLER */
787
788#endif /* _STDLIB_H_ */
void exit(int __status)
char * ftostre(float __val, char *__s, unsigned char __prec, unsigned char __flags)
Definition: dtostre.c:39
char * ldtostrf(long double __val, signed char __width, unsigned char __prec, char *__s)
char * ltoa(long val, char *s, int radix)
Convert a long integer to a string.
long random(void)
Definition: random.c:81
long atol(const char *__s)
Definition: atol.c:34
long double atofl(const char *__nptr)
int(* __compar_fn_t)(const void *, const void *)
Definition: stdlib.h:83
char * dtostre(double __val, char *__s, unsigned char __prec, unsigned char __flags)
char * __malloc_heap_end
Definition: malloc.c:61
void srandom(unsigned long __seed)
Definition: random.c:88
ldiv_t ldiv(long __num, long __denom) __asm__("__divmodsi4")
double strtod(const char *__nptr, char **__endptr)
long double strtold(const char *__nptr, char **__endptr)
void * calloc(size_t __nele, size_t __size)
Definition: calloc.c:39
int atoi(const char *__s)
Definition: atoi.c:34
double atof(const char *__nptr)
float strtof(const char *__nptr, char **__endptr)
Definition: strtod.c:99
div_t div(int __num, int __denom) __asm__("__divmodhi4")
char * dtostrf(double __val, signed char __width, unsigned char __prec, char *__s)
int atexit(void(*func)(void))
Definition: atexit.c:42
char * ldtostre(long double __val, char *__s, unsigned char __prec, unsigned char __flags)
void abort(void)
Definition: abort.c:34
char * __malloc_heap_start
Definition: malloc.c:60
char * itoa(int val, char *s, int radix)
Convert an integer to a string.
long random_r(unsigned long *__ctx)
Definition: random.c:71
void srand(unsigned int __seed)
Definition: rand.c:98
int abs(int __i)
char * ftostrf(float __val, signed char __width, unsigned char __prec, char *__s)
Definition: dtostrf.c:51
char * ultoa(unsigned long val, char *s, int radix)
Convert an unsigned long integer to a string.
long labs(long __i)
int rand(void)
Definition: rand.c:91
float atoff(const char *__nptr)
char * utoa(unsigned int val, char *s, int radix)
Convert an unsigned integer to a string.
unsigned long strtoul(const char *__nptr, char **__endptr, int __base)
int rand_r(unsigned long *__ctx)
Definition: rand.c:81
void * bsearch(const void *__key, const void *__base, size_t __nmemb, size_t __size, int(*__compar)(const void *, const void *))
Definition: bsearch.c:56
long strtol(const char *__nptr, char **__endptr, int __base)
void qsort(void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar)
size_t __malloc_margin
Definition: malloc.c:59
Definition: stdlib.h:71
int quot
Definition: stdlib.h:72
int rem
Definition: stdlib.h:73
Definition: stdlib.h:77
long rem
Definition: stdlib.h:79
long quot
Definition: stdlib.h:78