Changeset da60ba9 for util.c


Ignore:
Timestamp:
Sep 25, 2009, 6:08:24 PM (15 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
7b4d90e
Parents:
dbe172d
Message:
Cause unsub to warn user if user wasn't subbed

Add a return value to owl_util_file_deleteline and use it to warn the
user appropriately on unsub. Fixes #35.

Signed-off-by: David Benjamin <davidben@mit.edu>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • util.c

    reea72a13 rda60ba9  
    557557 * inefficient impelementation which reads the entire file into
    558558 * memory.
     559 *
     560 * Returns the number of lines removed
    559561 */
    560 void owl_util_file_deleteline(const char *filename, const char *line, int backup)
     562int owl_util_file_deleteline(const char *filename, const char *line, int backup)
    561563{
    562564  char buff[LINE], *text;
     
    564566  FILE *file, *backupfile=NULL;
    565567  int size, newline;
     568  int numremoved = 0;
    566569
    567570  /* open the file for reading */
     
    569572  if (!file) {
    570573    owl_function_error("Error opening file %s", filename);
    571     return;
     574    return 0;
    572575  }
    573576
     
    580583      owl_free(backupfilename);
    581584      fclose(file);
    582       return;
     585      return 0;
    583586    }
    584587  }
     
    604607      strcat(text, buff);
    605608      if (newline) strcat(text, "\n");
     609    } else {
     610      numremoved++;
    606611    }
    607612
     
    628633    owl_free(backupfilename);
    629634  owl_free(text);
     635
     636  return numremoved;
    630637}
    631638
Note: See TracChangeset for help on using the changeset viewer.