aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStrake <devnull@localhost>2013-07-12 18:10:52 -0500
committerStrake <devnull@localhost>2013-07-12 18:10:52 -0500
commite999ca008416e3d41c1079bcb4d151b43c95dc3a (patch)
tree3402d83e94af49e67e287831ba829ccbb1ec67f6 /lib
parent19ee0eb865a674c8c11dc8e89ef5e1498a27b087 (diff)
downloadtoybox-e999ca008416e3d41c1079bcb4d151b43c95dc3a.tar.gz
add grep
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c22
-rw-r--r--lib/lib.h4
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index dca92cbe..f4fcaef4 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -1291,3 +1291,25 @@ unsigned long get_int_value(const char *numstr, unsigned lowrange, unsigned high
return rvalue; //Not reachable; to avoid waring message.
}
}
+
+/*
+ * strcat to mallocated buffer
+ * reallocate if need be
+ */
+char *astrcat (char *x, char *y) {
+ char *z;
+ z = x;
+ x = realloc (x, (x ? strlen (x) : 0) + strlen (y) + 1);
+ if (!x) return 0;
+ (z ? strcat : strcpy) (x, y);
+ return x;
+}
+
+/*
+ * astrcat, but die on failure
+ */
+char *xastrcat (char *x, char *y) {
+ x = astrcat (x, y);
+ if (!x) error_exit ("xastrcat");
+ return x;
+}
diff --git a/lib/lib.h b/lib/lib.h
index 70f8f493..2b65495a 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -192,3 +192,7 @@ char* make_human_readable(unsigned long long size, unsigned long unit);
// cut helper functions
unsigned long get_int_value(const char *numstr, unsigned lowrange, unsigned highrange);
+
+// grep helper functions
+char *astrcat (char *, char *);
+char *xastrcat (char *, char *);