return t;
}
-static void gvconfig_library_install_from_config(GVC_t * gvc, char *s)
+static void gvconfig_plugin_install_from_config(GVC_t * gvc, char *s)
{
char *path, *api, *type;
api_t gv_api;
}
}
-static void gvconfig_library_install_from_struct(GVC_t * gvc, gvplugin_library_t *library)
+static void gvconfig_plugin_install_from_library(GVC_t * gvc, gvplugin_library_t *library)
{
gvplugin_api_t *apis;
gvplugin_type_t *types;
gvplugin_library_t *library;
int sz, rc, i;
struct stat config_st, libdir_st;
- FILE *f;
- char *config_path, *config_glob, *home, *config_text;
+ FILE *f = NULL;
+ char *config_path = NULL, *config_text = NULL;
+ char *config_glob, *home;
glob_t globbuf;
char *dot_graphviz = "/.graphviz";
#ifdef DISABLE_LTDL
for (libraryp = builtins; *libraryp; libraryp++) {
- gvconfig_library_install_from_struct(gvc, *libraryp);
+ gvconfig_plugin_install_from_library(gvc, *libraryp);
}
#else
/* see if there are any new plugins */
}
home = getenv ("HOME");
- if (!home) {
- return;
- }
-
- config_path = malloc(strlen(home) + strlen(dot_graphviz) + 1);
- strcpy(config_path, home);
- strcat(config_path, dot_graphviz);
+ if (home) {
+ config_path = malloc(strlen(home) + strlen(dot_graphviz) + 1);
+ strcpy(config_path, home);
+ strcat(config_path, dot_graphviz);
- rc = stat(config_path, &config_st);
-
- if (rc == -1 || libdir_st.st_mtime > config_st.st_mtime) {
- f = fopen(config_path,"w");
- if (!f) {
- fprintf(stderr,"failed to open %s for write.\n", config_path);
+ rc = stat(config_path, &config_st);
+ if (rc == -1) {
+ free(config_path);
+ config_path = NULL;
+ }
+ }
+
+ if (! config_path || libdir_st.st_mtime > config_st.st_mtime) {
+ if (config_path) {
+ f = fopen(config_path,"w");
+ if (!f) {
+ fprintf(stderr,"failed to open %s for write.\n", config_path);
+ }
}
/* load all libraries even if can't save config */
for (i = 0; i < globbuf.gl_pathc; i++) {
library = gvplugin_library_load(globbuf.gl_pathv[i]);
if (library) {
- gvconfig_library_install_from_struct(gvc, library);
+ gvconfig_plugin_install_from_library(gvc, library);
if (f) {
gvconfig_write_library_config(globbuf.gl_pathv[i], library, f);
}
}
globfree(&globbuf);
free(config_glob);
- if (f)
- fclose(f);
}
else {
/* load in the cached plugin library data */
if (config_st.st_size > MAX_SZ_CONFIG) {
fprintf(stderr,"%s is bigger than I can handle.\n", config_path);
- free(config_path);
- return;
}
- f = fopen(config_path,"r");
- if (!f) { /* if we fail to open it then it probably doesn't exists
- so just fail silently, clean up and return */
- free(config_path);
- return;
- }
- config_text = malloc(config_st.st_size + 1);
- config_text[0] = '\0';
- sz = fread(config_text, 1, config_st.st_size, f);
- if (sz == 0) {
- fprintf(stderr,"%s is zero sized, or other read error.\n", config_path);
- free(config_path);
- free(config_text);
- return;
+ else {
+ f = fopen(config_path,"r");
+ if (!f) {
+ fprintf(stderr,"failed to open %s for read.\n", config_path);
+ }
+ else {
+ config_text = malloc(config_st.st_size + 1);
+ sz = fread(config_text, 1, config_st.st_size, f);
+ if (sz == 0) {
+ fprintf(stderr,"%s is zero sized, or other read error.\n", config_path);
+ free(config_text);
+ }
+ else {
+ config_text[sz] = '\0'; /* make input into a null terminated string */
+ gvconfig_plugin_install_from_config(gvc, config_text);
+ /* NB. config_text not freed becasue we retain char* into it */
+ }
+ }
}
- fclose(f);
- free(config_path); /* not needed now that we've slurped in the contents */
-
- config_text[config_st.st_size] = '\0'; /* make input into a null terminated string */
-
- gvconfig_library_install_from_config(gvc, config_text);
}
+ if (config_path)
+ free(config_path);
+ if (f)
+ fclose(f);
#endif
}