diff options
Diffstat (limited to 'replay.c')
-rw-r--r-- | replay.c | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -137,10 +137,14 @@ void formattime(char *str) { } // Return the number of lines in the replay log since 'seconds' seconds ago, or -1 if there a problem. -int replaylines(int seconds) { +// 'basedir' is the directory in which to find 'replay.log'. +int replaylines(int seconds, char *basedir) { FILE *fp; char str[MAXCHAR]; - char* filename = "replay.log"; + char filename[PATH_MAX]; + + // Build path + snprintf(filename, PATH_MAX, "%s/replay.log", basedir); int numlines = 0; @@ -175,14 +179,18 @@ int replaylines(int seconds) { } // Set 'str' to the line in the log with a timestamp of greater than 'seconds' -// seconds ago, plus however many lines 'linenum' is set to. +// seconds ago, plus however many lines 'linenum' is set to. 'basedir' is the +// directory in which to find 'replay.log'. // Also modify the line to include a timestamp in the form "[HH:MM:SS]". // Returns 1 on success, or 0 on failure. // TODO - This is horribly inefficient since it re-reads the entire file each call, rewrite this! -int readreplayline(int seconds, int linenum, char *str) { +int readreplayline(int seconds, int linenum, char *str, char *basedir) { FILE *fp; char line[MAXCHAR]; - char* filename = "replay.log"; + char filename[PATH_MAX]; + + // Build path + snprintf(filename, PATH_MAX, "%s/replay.log", basedir); int count = 0; @@ -226,15 +234,19 @@ int readreplayline(int seconds, int linenum, char *str) { } // Write the line 'str' to the replay log file after prepending it with -// the current unixtime timestamp. +// the current unixtime timestamp. 'basedir' is the directory in which +// to write to 'replay.log'. // Expects a string in the format: // :from!bar@baz PRIVMSG to :hello world // With the ":foo!bar@baz "prefix being important. // Returns 1 on success or 0 on failure. -int writereplayline(char *str) { +int writereplayline(char *str, char *basedir) { FILE *fp; char line[MAXCHAR]; - char* filename = "replay.log"; + char filename[PATH_MAX]; + + // Build path + snprintf(filename, PATH_MAX, "%s/replay.log", basedir); int bytes = 0; |