aboutsummaryrefslogtreecommitdiff
path: root/notmuch.c
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2009-10-21 15:59:11 -0700
committerCarl Worth <cworth@cworth.org>2009-10-21 15:59:11 -0700
commitf96f4fe427d7fd8930db7589e377f5c8cb97f2dc (patch)
treef806233e8dcd405a8a90508689000ffd352e9f33 /notmuch.c
parentdefd216487bb6549d6e866fe578d2c3d3de77fd6 (diff)
Pull out a chomp_newline function from "notmuch setup"
We'll want this same thing with "notmuch restore", (and really anything using getline).
Diffstat (limited to 'notmuch.c')
-rw-r--r--notmuch.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/notmuch.c b/notmuch.c
index d764252..2d208ce 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -55,6 +55,13 @@ typedef struct {
struct timeval tv_start;
} add_files_state_t;
+static void
+chomp_newline (char *str)
+{
+ if (str && str[strlen(str)-1] == '\n')
+ str[strlen(str)-1] = '\0';
+}
+
/* Compute the number of seconds elapsed from start to end. */
double
tv_elapsed (struct timeval start, struct timeval end)
@@ -289,13 +296,9 @@ setup_command (int argc, char *argv[])
mail_directory = NULL;
getline (&mail_directory, &line_size, stdin);
- printf ("\n");
+ chomp_newline (mail_directory);
- if (mail_directory &&
- mail_directory[strlen(mail_directory)-1] == '\n')
- {
- mail_directory[strlen(mail_directory)-1] = '\0';
- }
+ printf ("\n");
if (mail_directory == NULL || strlen (mail_directory) == 0) {
if (mail_directory)