diff --git a/fmt.h b/fmt.h index 45a6e4d..fc63663 100644 --- a/fmt.h +++ b/fmt.h @@ -1,6 +1,7 @@ #ifndef FMT_H #define FMT_H +#define FMT_LONG 41 /* enough space to hold -2^127 in decimal, plus \0 */ #define FMT_ULONG 40 /* enough space to hold 2^128 - 1 in decimal, plus \0 */ #define FMT_8LONG 44 /* enough space to hold 2^128 - 1 in octal, plus \0 */ #define FMT_XLONG 33 /* enough space to hold 2^128 - 1 in hexadecimal, plus \0 */ diff --git a/fmt/fmt_long.3 b/fmt/fmt_long.3 index e918383..72f1929 100644 --- a/fmt/fmt_long.3 +++ b/fmt/fmt_long.3 @@ -14,7 +14,7 @@ fmt_long does not append \\0. If \fIdest\fR equals FMT_LEN (i.e. is zero), fmt_long returns the number of bytes it would have written. -For convenience, fmt.h defines the integer FMT_ULONG to be big enough to -contain every possible fmt_ulong output plus \\0. +For convenience, fmt.h defines the integer FMT_LONG to be big enough to +contain every possible fmt_long output plus \\0. .SH "SEE ALSO" scan_long(3) diff --git a/fmt/fmt_strn.c b/fmt/fmt_strn.c index c0fd0c7..8728a38 100644 --- a/fmt/fmt_strn.c +++ b/fmt/fmt_strn.c @@ -3,12 +3,12 @@ unsigned int fmt_strn(char *out,const char *in,unsigned int limit) { register char* s=out; register const char* t=in; - register const char* u=out+limit; + register const char* u=in+limit; for (;;) { - if (!*t) break; *s=*t; if (s==u) break; ++s; ++t; - if (!*t) break; *s=*t; if (s==u) break; ++s; ++t; - if (!*t) break; *s=*t; if (s==u) break; ++s; ++t; - if (!*t) break; *s=*t; if (s==u) break; ++s; ++t; + if (!*t) break; if (s) { *s=*t; ++s; } if (t==u) break; ++t; + if (!*t) break; if (s) { *s=*t; ++s; } if (t==u) break; ++t; + if (!*t) break; if (s) { *s=*t; ++s; } if (t==u) break; ++t; + if (!*t) break; if (s) { *s=*t; ++s; } if (t==u) break; ++t; } - return s-out; + return t-in; } diff --git a/fmt/fmt_ulong0.c b/fmt/fmt_ulong0.c index 5366b33..efa2157 100644 --- a/fmt/fmt_ulong0.c +++ b/fmt/fmt_ulong0.c @@ -8,7 +8,7 @@ unsigned int fmt_ulong0(char *dest,unsigned long i,unsigned int pad) { /* now see if we need to pad */ if (dest) { while (len - typedef unsigned short uint16; #if defined(__i386__) && !defined(NO_UINT16_MACROS)