Example #1
0
static void
load_config_dir(const char *prog, const struct cmdinfo* cmdinfos)
{
  char *dirname;
  struct dirent **dlist;
  int dlist_n, i;

  dirname = m_malloc(strlen(CONFIGDIR "/.cfg.d") + strlen(prog) + 1);
  sprintf(dirname, "%s/%s.cfg.d", CONFIGDIR, prog);

  dlist_n = scandir(dirname, &dlist, valid_config_filename, alphasort);
  if (dlist_n < 0) {
    if (errno == ENOENT) {
      free(dirname);
      return;
    } else
      ohshite(_("error opening configuration directory '%s'"), dirname);
  }

  for (i = 0; i < dlist_n; i++) {
    char *filename;

    filename = m_malloc(strlen(dirname) + 1 + strlen(dlist[i]->d_name) + 1);
    sprintf(filename, "%s/%s", dirname, dlist[i]->d_name);

    myfileopt(filename, cmdinfos);

    free(dlist[i]);
    free(filename);
  }

  free(dirname);
  free(dlist);
}
Example #2
0
void loadcfgfile(const char *prog, const struct cmdinfo* cmdinfos) {
  char *home, *file;
  int l1, l2;
  l1 = strlen(CONFIGDIR "/.cfg") + strlen(prog);
  file = m_malloc(l1 + 1);
  sprintf(file, CONFIGDIR "/%s.cfg", prog);
  myfileopt(file, cmdinfos);
  if ((home = getenv("HOME")) != NULL) {
    l2 = strlen(home) + 1 + strlen("/.cfg") + strlen(prog);
    if (l2 > l1) {
      free(file);
      file = m_malloc(l2 + 1);
    }
    sprintf(file, "%s/.%s.cfg", home, prog);
    myfileopt(file, cmdinfos);
  }
  free(file);
}