avr-libc  2.2.0git
Standard C library for AVR-GCC

AVR Libc Home Page

AVRs

AVR Libc Development Pages

Main Page

User Manual

Library Reference

FAQ

Example Projects

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