+#define CONFIG_FILE ".linphone-history.db"
+
+const char *linphone_gtk_message_storage_get_db_file(const char *filename){
+ const int path_max=1024;
+ static char *db_file=NULL;
+
+ if (db_file) return db_file;
+
+ db_file=(char *)malloc(path_max*sizeof(char));
+ if (filename==NULL) filename=CONFIG_FILE;
+ /*try accessing a local file first if exists*/
+ if (access(CONFIG_FILE,F_OK)==0){
+ snprintf(db_file,path_max,"%s",filename);
+ }else{
+#ifdef WIN32
+ const char *appdata=getenv("APPDATA");
+ if (appdata){
+ snprintf(db_file,path_max,"%s\\%s",appdata,LINPHONE_CONFIG_DIR);
+ CreateDirectory(db_file,NULL);
+ snprintf(db_file,path_max,"%s\\%s\\%s",appdata,LINPHONE_CONFIG_DIR,filename);
+ }
+#else
+ const char *home=getenv("HOME");
+ if (home==NULL) home=".";
+ snprintf(db_file,path_max,"%s/%s",home,filename);
+#endif
+ }
+ return db_file;
+}
+
+