root/opal/util/numtostr.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. opal_ltostr
  2. opal_dtostr

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * $COPYRIGHT$
  13  *
  14  * Additional copyrights may follow
  15  *
  16  * $HEADER$
  17  */
  18 
  19 #include "opal_config.h"
  20 #include "opal/util/numtostr.h"
  21 #include "opal/util/printf.h"
  22 #include <stdio.h>
  23 #include <stdlib.h>
  24 
  25 
  26 char*
  27 opal_ltostr(long num)
  28 {
  29     /* waste a little bit of space, but always have a big enough buffer */
  30     int buflen = sizeof(long) * 8;
  31     char *buf = NULL;
  32     int ret = 0;
  33 
  34     buf = (char*) malloc(sizeof(char) * buflen);
  35     if (NULL == buf) return NULL;
  36 
  37     ret = snprintf(buf, buflen, "%ld", num);
  38     if (ret < 0) {
  39         free(buf);
  40         return NULL;
  41     }
  42 
  43     return buf;
  44 }
  45 
  46 
  47 char*
  48 opal_dtostr(double num)
  49 {
  50     /* waste a little bit of space, but always have a big enough buffer */
  51     int buflen = sizeof(long) * 8;
  52     char *buf = NULL;
  53     int ret = 0;
  54 
  55     buf = (char*) malloc(sizeof(char) * buflen);
  56     if (NULL == buf) return NULL;
  57 
  58     ret = snprintf(buf, buflen, "%f", num);
  59     if (ret < 0) {
  60         free(buf);
  61         return NULL;
  62     }
  63 
  64     return buf;
  65 }

/* [<][>][^][v][top][bottom][index][help] */