summaryrefslogtreecommitdiffstats
path: root/byterun/ints.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2003-03-31 08:41:58 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2003-03-31 08:41:58 +0000
commit3022b15ef3adb1233e9d50887554c92f8e33ae3f (patch)
tree0e59dd4ec377647257794b915a323dfed6ba2db3 /byterun/ints.c
parent0180aa6cd8ada8521cdc6f81402fe884ae0ca7cd (diff)
printf, formats non signes, argument de type Caml int: utiliser Unsigned_long_val au lieu de Long_val
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'byterun/ints.c')
-rw-r--r--byterun/ints.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/byterun/ints.c b/byterun/ints.c
index 208655fac..26c8c9322 100644
--- a/byterun/ints.c
+++ b/byterun/ints.c
@@ -107,10 +107,12 @@ CAMLprim value int_of_string(value s)
static char * parse_format(value fmt,
char * suffix,
char format_string[],
- char default_format_buffer[])
+ char default_format_buffer[],
+ char *conv)
{
- int prec, lastletter;
+ int prec;
char * p;
+ char lastletter;
mlsize_t len, len_suffix;
/* Copy Caml format fmt to format_string,
@@ -135,6 +137,7 @@ static char * parse_format(value fmt,
break;
}
}
+ *conv = lastletter;
if (prec < FORMAT_BUFFER_SIZE)
return default_format_buffer;
else
@@ -146,10 +149,18 @@ CAMLprim value format_int(value fmt, value arg)
char format_string[FORMAT_BUFFER_SIZE];
char default_format_buffer[FORMAT_BUFFER_SIZE];
char * buffer;
+ char conv;
value res;
- buffer = parse_format(fmt, "l", format_string, default_format_buffer);
- sprintf(buffer, format_string, Long_val(arg));
+ buffer = parse_format(fmt, "l", format_string, default_format_buffer, &conv);
+ switch (conv) {
+ case 'u': case 'x': case 'X': case 'o':
+ sprintf(buffer, format_string, Unsigned_long_val(arg));
+ break;
+ default:
+ sprintf(buffer, format_string, Long_val(arg));
+ break;
+ }
res = copy_string(buffer);
if (buffer != default_format_buffer) stat_free(buffer);
return res;
@@ -267,9 +278,10 @@ CAMLprim value int32_format(value fmt, value arg)
char format_string[FORMAT_BUFFER_SIZE];
char default_format_buffer[FORMAT_BUFFER_SIZE];
char * buffer;
+ char conv;
value res;
- buffer = parse_format(fmt, "", format_string, default_format_buffer);
+ buffer = parse_format(fmt, "", format_string, default_format_buffer, &conv);
sprintf(buffer, format_string, (long) Int32_val(arg));
res = copy_string(buffer);
if (buffer != default_format_buffer) stat_free(buffer);
@@ -439,10 +451,11 @@ CAMLprim value int64_format(value fmt, value arg)
char format_string[FORMAT_BUFFER_SIZE];
char default_format_buffer[FORMAT_BUFFER_SIZE];
char * buffer;
+ char conv;
value res;
buffer = parse_format(fmt, ARCH_INT64_PRINTF_FORMAT,
- format_string, default_format_buffer);
+ format_string, default_format_buffer, &conv);
I64_format(buffer, format_string, Int64_val(arg));
res = copy_string(buffer);
if (buffer != default_format_buffer) stat_free(buffer);
@@ -629,9 +642,10 @@ CAMLprim value nativeint_format(value fmt, value arg)
char format_string[FORMAT_BUFFER_SIZE];
char default_format_buffer[FORMAT_BUFFER_SIZE];
char * buffer;
+ char conv;
value res;
- buffer = parse_format(fmt, "l", format_string, default_format_buffer);
+ buffer = parse_format(fmt, "l", format_string, default_format_buffer, &conv);
sprintf(buffer, format_string, (long) Nativeint_val(arg));
res = copy_string(buffer);
if (buffer != default_format_buffer) stat_free(buffer);