logd: liblog: logcat: Arbitrary time to tail

Change-Id: I10e8d92c933e31ee11e78d2d1114261a30c4be0e
diff --git a/include/log/log_read.h b/include/log/log_read.h
index 7edfe3c..bd9de12 100644
--- a/include/log/log_read.h
+++ b/include/log/log_read.h
@@ -17,11 +17,17 @@
 #ifndef _LIBS_LOG_LOG_READ_H
 #define _LIBS_LOG_LOG_READ_H
 
+#include <stdint.h>
 #include <time.h>
 
 /* struct log_time is a wire-format variant of struct timespec */
 #define NS_PER_SEC 1000000000ULL
+
 #ifdef __cplusplus
+
+// NB: do NOT define a copy constructor. This will result in structure
+// no longer being compatible with pass-by-value which is desired
+// efficient behavior. Also, pass-by-reference breaks C/C++ ABI.
 struct log_time {
 public:
     uint32_t tv_sec; // good to Feb 5 2106
@@ -32,16 +38,12 @@
         tv_sec = T.tv_sec;
         tv_nsec = T.tv_nsec;
     }
-    log_time(const log_time &T)
-    {
-        tv_sec = T.tv_sec;
-        tv_nsec = T.tv_nsec;
-    }
     log_time(uint32_t sec, uint32_t nsec)
     {
         tv_sec = sec;
         tv_nsec = nsec;
     }
+    static const timespec EPOCH;
     log_time()
     {
     }
@@ -86,6 +88,12 @@
     {
         return !(*this > T);
     }
+    log_time operator-= (const timespec &T);
+    log_time operator- (const timespec &T) const
+    {
+        log_time local(*this);
+        return local -= T;
+    }
 
     // log_time
     bool operator== (const log_time &T) const
@@ -114,17 +122,31 @@
     {
         return !(*this > T);
     }
+    log_time operator-= (const log_time &T);
+    log_time operator- (const log_time &T) const
+    {
+        log_time local(*this);
+        return local -= T;
+    }
 
     uint64_t nsec() const
     {
         return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec;
     }
+
+    static const char default_format[];
+
+    // Add %#q for the fraction of a second to the standard library functions
+    char *strptime(const char *s, const char *format = default_format);
 } __attribute__((__packed__));
+
 #else
+
 typedef struct log_time {
     uint32_t tv_sec;
     uint32_t tv_nsec;
 } __attribute__((__packed__)) log_time;
+
 #endif
 
 #endif /* define _LIBS_LOG_LOG_READ_H */
diff --git a/include/log/logger.h b/include/log/logger.h
index 8dab234..3c6ea30 100644
--- a/include/log/logger.h
+++ b/include/log/logger.h
@@ -12,6 +12,7 @@
 
 #include <stdint.h>
 #include <log/log.h>
+#include <log/log_read.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -161,6 +162,9 @@
 struct logger_list *android_logger_list_alloc(int mode,
                                               unsigned int tail,
                                               pid_t pid);
+struct logger_list *android_logger_list_alloc_time(int mode,
+                                                   log_time start,
+                                                   pid_t pid);
 void android_logger_list_free(struct logger_list *logger_list);
 /* In the purest sense, the following two are orthogonal interfaces */
 int android_logger_list_read(struct logger_list *logger_list,