Changeset 6ea3890


Ignore:
Timestamp:
Oct 17, 2009, 6:08:20 PM (12 years ago)
Author:
Karl Ramm <kcr@1ts.org>
Branches:
master, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
99cc3dc
Parents:
b7ee89b
git-author:
Karl Ramm <kcr@1ts.org> (10/16/09 11:21:14)
git-committer:
Karl Ramm <kcr@1ts.org> (10/17/09 18:08:20)
Message:
helper function owl_zephyr_dotfile and refactor to use it

There were the ~same four lines of code in many different places,
so I stuck them in a function.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zephyr.c

    rb7ee89b r6ea3890  
    1919
    2020#define HM_SVC_FALLBACK         htons((unsigned short) 2104)
     21
     22static char *owl_zephyr_dotfile(const char *name, const char *input)
     23{
     24  if (input != NULL)
     25    return owl_strdup(input);
     26  else
     27    return owl_sprintf("%s/%s", owl_global_get_homedir(&g), name);
     28}
    2129
    2230#ifdef HAVE_LIBZEPHYR
     
    254262
    255263  subs = owl_malloc(sizeof(ZSubscription_t) * subSize);
    256   if (filename == NULL)
    257     subsfile = owl_sprintf("%s/.zephyr.subs", owl_global_get_homedir(&g));
    258   else
    259     subsfile = owl_strdup(filename);
     264  subsfile = owl_zephyr_dotfile(".zephyr.subs", filename);
    260265
    261266  if (stat(subsfile, &statbuff) != 0) {
     
    373378
    374379  subs = owl_malloc(numSubs * sizeof(ZSubscription_t));
    375 
    376   if (filename==NULL)
    377     subsfile = owl_sprintf("%s/%s", owl_global_get_homedir(&g), ".anyone");
    378   else
    379     subsfile = owl_strdup(filename);
     380  subsfile = owl_zephyr_dotfile(".anyone", filename);
    380381
    381382  if (stat(subsfile, &statbuff) == -1)
     
    957958
    958959  line = owl_zephyr_makesubline(class, inst, recip);
    959 
    960   if (filename == NULL)
    961     subsfile = owl_sprintf("%s/.zephyr.subs", owl_global_get_homedir(&g));
    962   else
    963     subsfile = owl_strdup(filename);
     960  subsfile = owl_zephyr_dotfile(".zephyr.subs", filename);
    964961
    965962  /* if the file already exists, check to see if the sub is already there */
     
    1000997  line[strlen(line)-1]='\0';
    1001998
    1002   if (!filename) {
    1003     subsfile=owl_sprintf("%s/.zephyr.subs", owl_global_get_homedir(&g));
    1004   } else {
    1005     subsfile=owl_strdup(filename);
    1006   }
     999  subsfile = owl_zephyr_dotfile(".zephyr.subs", filename);
    10071000 
    10081001  linesdeleted = owl_util_file_deleteline(subsfile, line, 1);
     
    10791072  FILE *file;
    10801073 
    1081   filename=owl_sprintf("%s/.anyone", owl_global_get_homedir(&g));
    1082   file=fopen(filename, "a");
     1074  filename = owl_zephyr_dotfile(".anyone", NULL);
     1075  file = fopen(filename, "a");
    10831076  owl_free(filename);
    10841077  if (!file) {
     
    10941087  char *filename;
    10951088
    1096   filename=owl_sprintf("%s/.anyone", owl_global_get_homedir(&g));
     1089  filename = owl_zephyr_dotfile(".anyone", NULL);
    10971090  owl_util_file_deleteline(filename, name, 0);
    10981091  owl_free(filename);
     
    12781271  FILE *f;
    12791272
    1280   if (filename == NULL)
    1281     ourfile = owl_sprintf("%s/.anyone", owl_global_get_homedir(&g));
    1282   else
    1283     ourfile = owl_strdup(filename);
     1273  ourfile = owl_zephyr_dotfile(".anyone", filename);
    12841274
    12851275  f = fopen(ourfile, "r");
Note: See TracChangeset for help on using the changeset viewer.