2004-07-14 18:04:31 +00:00
|
|
|
/*
|
2005-11-05 19:57:48 +00:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 20:09:25 +00:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 12:43:37 +00:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 01:38:40 +00:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-07-14 18:04:31 +00:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2006-02-12 01:33:29 +00:00
|
|
|
#include "opal_config.h"
|
2005-07-04 01:36:20 +00:00
|
|
|
#include "opal/util/numtostr.h"
|
2005-07-04 02:16:57 +00:00
|
|
|
#include "opal/util/printf.h"
|
2004-07-14 18:04:31 +00:00
|
|
|
#include <stdio.h>
|
2004-07-15 13:19:18 +00:00
|
|
|
#include <stdlib.h>
|
2004-07-14 18:04:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
char*
|
2005-07-04 01:36:20 +00:00
|
|
|
opal_ltostr(long num)
|
2004-07-14 18:04:31 +00: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 15:38:19 +00:00
|
|
|
buf = (char*) malloc(sizeof(char) * buflen);
|
2004-07-14 18:04:31 +00:00
|
|
|
if (NULL == buf) return NULL;
|
|
|
|
|
|
|
|
ret = snprintf(buf, buflen, "%ld", num);
|
|
|
|
if (ret < 0) {
|
|
|
|
free(buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char*
|
2005-07-04 01:36:20 +00:00
|
|
|
opal_dtostr(double num)
|
2004-07-14 18:04:31 +00: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 15:38:19 +00:00
|
|
|
buf = (char*) malloc(sizeof(char) * buflen);
|
2004-07-14 18:04:31 +00:00
|
|
|
if (NULL == buf) return NULL;
|
|
|
|
|
|
|
|
ret = snprintf(buf, buflen, "%f", num);
|
|
|
|
if (ret < 0) {
|
|
|
|
free(buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|