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.
|
2015-06-24 06:59:57 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
2004-11-28 23:09:25 +03:00
|
|
|
* 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$
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Additional copyrights may follow
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
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;
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2004-07-14 22:04:31 +04:00
|
|
|
ret = snprintf(buf, buflen, "%ld", num);
|
|
|
|
if (ret < 0) {
|
|
|
|
free(buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2004-07-14 22:04:31 +04:00
|
|
|
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;
|
2015-06-24 06:59:57 +03:00
|
|
|
|
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;
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2004-07-14 22:04:31 +04:00
|
|
|
ret = snprintf(buf, buflen, "%f", num);
|
|
|
|
if (ret < 0) {
|
|
|
|
free(buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2004-07-14 22:04:31 +04:00
|
|
|
return buf;
|
|
|
|
}
|