Mercurial > hg > octave-nkf > gnulib-hg
comparison lib/inttostr.c @ 12221:a12bc0c11a21
inttostr: aesthetics and improved (compile-time) safety
Define inttype_is_signed rather than inttype_is_unsigned,
since the sole use is via "#if inttype_is_signed".
* lib/imaxtostr.c (inttype_is_signed): Define this, rather than
inttype_is_unsigned.
* lib/offtostr.c (inttype_is_signed): Likewise.
* lib/uinttostr.c (inttype_is_signed): Likewise.
* lib/umaxtostr.c (inttype_is_signed): Likewise.
* lib/inttostr.c (inttostr): Use verify to cross-check the
inttype_is_signed value and the signedness of the actual type.
* modules/inttostr (Depends-on): Add verify.
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Sat, 31 Oct 2009 09:42:37 +0100 |
parents | 1785ef4dfcdf |
children | e8d2c6fc33ad |
comparison
equal
deleted
inserted
replaced
12220:1785ef4dfcdf | 12221:a12bc0c11a21 |
---|---|
18 /* Written by Paul Eggert */ | 18 /* Written by Paul Eggert */ |
19 | 19 |
20 #include <config.h> | 20 #include <config.h> |
21 | 21 |
22 #include "inttostr.h" | 22 #include "inttostr.h" |
23 #include "verify.h" | |
23 | 24 |
24 /* Convert I to a printable string in BUF, which must be at least | 25 /* Convert I to a printable string in BUF, which must be at least |
25 INT_BUFSIZE_BOUND (INTTYPE) bytes long. Return the address of the | 26 INT_BUFSIZE_BOUND (INTTYPE) bytes long. Return the address of the |
26 printable string, which need not start at BUF. */ | 27 printable string, which need not start at BUF. */ |
27 | 28 |
29 inttostr (inttype i, char *buf) | 30 inttostr (inttype i, char *buf) |
30 { | 31 { |
31 char *p = buf + INT_STRLEN_BOUND (inttype); | 32 char *p = buf + INT_STRLEN_BOUND (inttype); |
32 *p = 0; | 33 *p = 0; |
33 | 34 |
34 #ifndef inttype_is_unsigned | 35 verify (TYPE_SIGNED (inttype) == inttype_is_signed); |
36 #if inttype_is_signed | |
35 if (i < 0) | 37 if (i < 0) |
36 { | 38 { |
37 do | 39 do |
38 *--p = '0' - i % 10; | 40 *--p = '0' - i % 10; |
39 while ((i /= 10) != 0); | 41 while ((i /= 10) != 0); |