00001 00030 #include <stdio.h> 00031 #include <stdlib.h> 00032 #include <string.h> 00033 00034 #include "config.h" 00035 #include "common.h" 00036 00037 #define REGISTRY_FILENAME "/registry" 00038 #define REGISTRY_DIR PACKAGE 00039 #define DATA_HOME_DIR ".local/share" 00040 00044 char* registryGetFilename(void) { 00045 char *omxregistryfile = NULL; 00046 char *buffer; 00047 00048 buffer=getenv("OMX_BELLAGIO_REGISTRY"); 00049 if(buffer!=NULL&&*buffer!='\0') { 00050 omxregistryfile = strdup(buffer); 00051 return omxregistryfile; 00052 } 00053 00054 buffer=getenv("XDG_DATA_HOME"); 00055 if(buffer!=NULL&&*buffer!='\0') { 00056 omxregistryfile = malloc(strlen(buffer) + strlen(REGISTRY_DIR) + strlen(REGISTRY_FILENAME) + 2); 00057 strcpy(omxregistryfile, buffer); 00058 strcat(omxregistryfile, "/"); 00059 strcat(omxregistryfile, REGISTRY_DIR); 00060 goto addfilename; 00061 } 00062 00063 buffer=getenv("HOME"); 00064 if(buffer!=NULL&&*buffer!='\0') { 00065 omxregistryfile = malloc(strlen(buffer) + strlen(DATA_HOME_DIR) + strlen(REGISTRY_DIR) + strlen(REGISTRY_FILENAME) + 3); 00066 strcpy(omxregistryfile, buffer); 00067 strcat(omxregistryfile, "/"); 00068 strcat(omxregistryfile, DATA_HOME_DIR); 00069 strcat(omxregistryfile, "/"); 00070 strcat(omxregistryfile, REGISTRY_DIR); 00071 } else { 00072 omxregistryfile = malloc(strlen(REGISTRY_DIR) + strlen(REGISTRY_FILENAME) + 2); 00073 strcpy(omxregistryfile, "."); 00074 strcat(omxregistryfile, REGISTRY_DIR); 00075 } 00076 00077 addfilename: 00078 strcat(omxregistryfile, REGISTRY_FILENAME); 00079 00080 return omxregistryfile; 00081 } 00082 00083 00084 00085 #ifdef COMMON_TEST 00086 int main (int argc, char*argv[]) { 00087 printf (registryGetFilename ()); 00088 } 00089 #endif