2004-07-14 22:04:31 +04:00
|
|
|
/*
|
2005-11-05 22:57:48 +03: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 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-07-14 22:04:31 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal_config.h"
|
2005-07-04 05:36:20 +04:00
|
|
|
#include "opal/util/numtostr.h"
|
2005-07-04 06:16:57 +04:00
|
|
|
#include "opal/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*
|
2005-07-04 05:36:20 +04:00
|
|
|
opal_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*
|
2005-07-04 05:36:20 +04:00
|
|
|
opal_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;
|
|
|
|
}
|