Environment Variable Handling const char* get_fortune_device() { static char* dev_file = NULL; char* dev_file_env = NULL; /* if we've already built the device file, return it */ if (dev_file) return dev_file; /* has the user set a FORTUNE_DEVICE environment variable for us? */ dev_file_env = getenv("FORTUNE_DEVICE"); /* guess not */ if (!dev_file_env){ /* make enough room in the buffer for the DEFUALT_FORTUNE_DEVICE */ dev_file = zmalloc(strlen(DEFAULT_FORTUNE_DEVICE)+1); }else{ /* yup. make enough room in the buffer for the user's environment var */ dev_file = zmalloc(strlen(dev_file_env)+1); } /* make our buffer contain the correct path to the device */ sprintf(dev_file, "%s", dev_file_env ? dev_file_env : DEFAULT_FORTUNE_DEVICE); /* and return it */ return dev_file; }