@@ -171,6 +171,28 @@ char *mstrcat(const char **nodes, const char *delim)
return dest;
}
+/*
+ * Alocate and return a string as part of
+ * another string
+ * s = substring(src, n)
+ * the returned string is allocated on the heap
+ * and must be freed by the caller
+ */
+char *substring(const char *src, int first, int len) {
+ char *s;
+ if (len > strlen(src))
+ len = strlen(src);
+ if (first > len)
+ return NULL;
+ s = malloc(len + 1);
+ if (!s)
+ return NULL;
+ memcpy(s, &src[first], len);
+ s[len] = '\0';
+ return s;
+}
+
+
int openfileoutput(const char *filename)
{
int fdout;
@@ -181,6 +181,7 @@ int syslog_init(void);
char **splitargs(char *args, int *argc);
char *mstrcat(const char **nodes, const char *delim);
char** string_split(const char* a_str, const char a_delim);
+char *substring(const char *src, int first, int len);
void freeargs (char **argv);
int get_hw_revision(struct hw_type *hw);
void get_sw_versions(char *cfgfname, struct swupdate_cfg *sw);
substring(string, len) Signed-off-by: Stefano Babic <sbabic@denx.de> --- core/util.c | 22 ++++++++++++++++++++++ include/util.h | 1 + 2 files changed, 23 insertions(+)