Commits

Greg Ward  committed c97b4fc

Move get_till_eol() from fossil.c to common.c and document it.

  • Participants
  • Parent commits 498a6db

Comments (0)

Files changed (3)

File src/common.c

 
     buf[i * 2] = '\0';
 }
+
+void
+get_till_eol(char *dest, const char *src, int n)
+{
+    char *newline = strchr(src, '\n');
+    if (newline) {
+        int m = (newline - src < n ? newline - src : n);
+        strncpy(dest, src, m);
+        dest[m] = '\0';
+    }
+    else {
+        // make sure caller doesn't use an uninitialized string
+        dest[0] = '\0';
+    }
+}

File src/common.h

 
 void dump_hex(const char* data, char* buf, int datasize);
 
+/* Copy up to n chars from src to dest, stopping at the first newline
+ * and terminating dest with a NUL char.  It is guaranteed that dest
+ * will not contain a newline and that strlen(dest) <= n.  If src
+ * contains no newlines, dest will be an empty string.  Caller must
+ * allocate n+1 chars for dest.
+ */
+void
+get_till_eol(char *dest, const char *src, int n);
+
 #endif

File src/fossil.c

     return isfile("_FOSSIL_");
 }
 
-void
-get_till_eol(char *dest, const char *src, int n)
-{
-    char *last = strchr(src, '\n');
-    if (last) {
-        int m = (last - src < n ? last - src : n);
-        strncpy(dest, src, m);
-        dest[m] = '\0';
-    }
-    else {
-        // make sure caller doesn't use an uninitialized string
-        dest[0] = '\0';
-    }
-}
-
 static result_t*
 fossil_get_info(vccontext_t* context)
 {