getenv_int.c File Reference

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include "utility.h"
Include dependency graph for getenv_int.c:

Go to the source code of this file.


int getenv_int (char *name, int defval)

Function Documentation

int getenv_int ( char *  name,
int  defval 

Definition at line 11 of file getenv_int.c.

  char *envstr = NULL;
  long int longval = -1;
  char *endptr;
  extern int errno;

  if (name == NULL) return defval;

  /* Env variable does not exist */
  if ((envstr = getenv(name)) == NULL) return defval;

  /* Convert to long, checking for errors */
  longval = strtol(envstr, &endptr, 10);
  if ((errno == ERANGE) || (longval==0 && endptr==envstr))
    return defval;

  return (int)longval;

Here is the caller graph for this function: