/* fmtulong.c -- Convert unsigned long int to string. */
-/* Copyright (C) 1998, Free Software Foundation, Inc.
+/* Copyright (C) 1998-2011 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
- Bash is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free
- Software Foundation; either version 2, or (at your option) any later
- version.
+ Bash is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- Bash is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- for more details.
+ Bash is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License along
- with Bash; see the file COPYING. If not, write to the Free Software
- Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ You should have received a copy of the GNU General Public License
+ along with Bash. If not, see <http://www.gnu.org/licenses/>.
+*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
#include <chartypes.h>
#include <errno.h>
+#include <bashintl.h>
+
#include "stdc.h"
#include <typemax.h>
# define FL_UNSIGNED 0x08 /* don't add any sign */
#endif
-#ifdef QUAD
- /* fmtullong */
-# define LONG long long
-# define FMTUL_LONG_MAX LLONG_MAX
-# define FMTUL_ULONG_MAX ULLONG_MAX
-#else
+#ifndef LONG
# define LONG long
-# define FMTUL_LONG_MAX LONG_MAX
-# define FMTUL_ULONG_MAX ULONG_MAX
-#endif
-
-/* Set the name */
-#ifdef QUAD
-# define fmtulong fmtullong
+# define UNSIGNED_LONG unsigned long
#endif
/* `unsigned long' (or unsigned long long) to string conversion for a given
check for buffer underflow, but currently does not. */
char *
fmtulong (ui, base, buf, len, flags)
- unsigned LONG ui;
+ UNSIGNED_LONG ui;
int base;
char *buf;
size_t len;
if (base < 2 || base > 64)
{
#if 1
- strncpy (buf, "invalid base", len - 1);
- buf[len] = '\0';
+ /* XXX - truncation possible with long translation */
+ strncpy (buf, _("invalid base"), len - 1);
+ buf[len-1] = '\0';
errno = EINVAL;
return (p = buf);
#else
}
/* Favor signed arithmetic over unsigned arithmetic; it is faster on
many machines. */
- if (ui > FMTUL_LONG_MAX)
+ if ((LONG)ui < 0)
{
*p-- = TOCHAR (ui % 10);
si = ui / 10;