1
1
openmpi/src/util/numtostr.c
Brian Barrett 452bd7ddca * need stdlib.h to have malloc.
This commit was SVN r1735.
2004-07-15 13:19:18 +00:00

52 строки
897 B
C

/*
* $HEADER$
*/
#include "ompi_config.h"
#include "util/numtostr.h"
#include <stdio.h>
#include <stdlib.h>
char*
ltostr(long num)
{
/* waste a little bit of space, but always have a big enough buffer */
int buflen = sizeof(long) * 8;
char *buf = NULL;
int ret = 0;
buf = malloc(sizeof(char) * buflen);
if (NULL == buf) return NULL;
ret = snprintf(buf, buflen, "%ld", num);
if (ret < 0) {
free(buf);
return NULL;
}
return buf;
}
char*
dtostr(double num)
{
/* waste a little bit of space, but always have a big enough buffer */
int buflen = sizeof(long) * 8;
char *buf = NULL;
int ret = 0;
buf = malloc(sizeof(char) * buflen);
if (NULL == buf) return NULL;
ret = snprintf(buf, buflen, "%f", num);
if (ret < 0) {
free(buf);
return NULL;
}
return buf;
}