[PATCH 2/3] notmuch-log.c: Add a function to log a pair of strings with a timestamp.

david at tethera.net david at tethera.net
Mon Oct 11 06:26:56 PDT 2010


From: David Bremner <bremner at unb.ca>

Since the function is supposed to work for any pair of strings, this
means some form of quoting seems necessary. I decided to re-use the
json quoting routines for convenience.
---
 notmuch-client.h |    4 ++++
 notmuch-log.c    |   18 ++++++++++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index 0422b1c..a849e21 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -201,6 +201,10 @@ notmuch_log_open (const char *path);
 notmuch_status_t
 notmuch_log_append (int file_desc, const char *buffer, size_t len);
 
+notmuch_status_t
+notmuch_log_string_pair (void *ctx, int file_desc,
+			 const char *str1, const char *str2);
+
 notmuch_bool_t
 debugger_is_active (void);
 
diff --git a/notmuch-log.c b/notmuch-log.c
index c4ddcd3..b0aca95 100644
--- a/notmuch-log.c
+++ b/notmuch-log.c
@@ -23,6 +23,8 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <time.h>
+#include <talloc.h>
 
 #include "notmuch-client.h"
 /*
@@ -100,3 +102,19 @@ notmuch_log_append (int file_desc, const char *buffer, size_t len){
 
     return NOTMUCH_STATUS_SUCCESS;
 }
+
+notmuch_status_t
+notmuch_log_string_pair(void *ctx, int log_fd,
+			const char *string1, const char *string2){
+
+    char *quoted1, *quoted2, *buffer;
+
+    quoted1 = json_quote_str (ctx, string1);
+    quoted2 = json_quote_str (ctx, string2);
+
+    buffer = talloc_asprintf (ctx, "%ld %s %s\n",
+			      (long)time(NULL),
+			      quoted1, quoted2);
+
+    return notmuch_log_append (log_fd, buffer, strlen(buffer));
+}
-- 
1.7.1



More information about the notmuch mailing list