2004-07-14 22:04:31 +04:00
|
|
|
/*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
* All rights reserved.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-07-14 22:04:31 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
#include "util/numtostr.h"
|
2004-10-22 20:06:05 +04:00
|
|
|
#include "util/printf.h"
|
2004-07-14 22:04:31 +04:00
|
|
|
#include <stdio.h>
|
2004-07-15 17:19:18 +04:00
|
|
|
#include <stdlib.h>
|
2004-07-14 22:04:31 +04:00
|
|
|
|
|
|
|
|
|
|
|
char*
|
2004-09-23 16:56:03 +04:00
|
|
|
ompi_ltostr(long num)
|
2004-07-14 22:04:31 +04:00
|
|
|
{
|
|
|
|
/* waste a little bit of space, but always have a big enough buffer */
|
|
|
|
int buflen = sizeof(long) * 8;
|
|
|
|
char *buf = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
|
2004-10-18 19:38:19 +04:00
|
|
|
buf = (char*) malloc(sizeof(char) * buflen);
|
2004-07-14 22:04:31 +04:00
|
|
|
if (NULL == buf) return NULL;
|
|
|
|
|
|
|
|
ret = snprintf(buf, buflen, "%ld", num);
|
|
|
|
if (ret < 0) {
|
|
|
|
free(buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char*
|
2004-09-23 16:56:03 +04:00
|
|
|
ompi_dtostr(double num)
|
2004-07-14 22:04:31 +04:00
|
|
|
{
|
|
|
|
/* waste a little bit of space, but always have a big enough buffer */
|
|
|
|
int buflen = sizeof(long) * 8;
|
|
|
|
char *buf = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
|
2004-10-18 19:38:19 +04:00
|
|
|
buf = (char*) malloc(sizeof(char) * buflen);
|
2004-07-14 22:04:31 +04:00
|
|
|
if (NULL == buf) return NULL;
|
|
|
|
|
|
|
|
ret = snprintf(buf, buflen, "%f", num);
|
|
|
|
if (ret < 0) {
|
|
|
|
free(buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|