diff --git a/include/ucore/string.h b/include/ucore/string.h index a8f22be..b60eac9 100644 --- a/include/ucore/string.h +++ b/include/ucore/string.h @@ -96,8 +96,8 @@ char* uc_sprintbs(char *result, unsigned short value); /** Like http://swtch.com/plan9port/man/man3/getfields.html */ -int getfields(char *str, char **args, int max, int mflag, const char *sep); -int gettokens(char *str, char **args, int max, const char *sep); +int uc_getfields(char *str, char **args, int max, int mflag, const char *sep); +int uc_gettokens(char *str, char **args, int max, const char *sep); //Converts bytes to a human representable test, (i.e. 12kB, 160 MB 1.78 GB etc.) ///result should be at least of size 12, diff --git a/src/cmd/cmd.c b/src/cmd/cmd.c index 960ddd6..9734873 100644 --- a/src/cmd/cmd.c +++ b/src/cmd/cmd.c @@ -148,7 +148,7 @@ uc_cmd_tokenize(struct UCCmdTokenizer *t, const char *cmd, const char *delim) delim = "\r\n\t\v "; } - t->num_words = getfields(t->cmd_copy, + t->num_words = uc_getfields(t->cmd_copy, t->cmd_words, ARRAY_SIZE(t->cmd_words), 1, diff --git a/src/getfields.c b/src/getfields.c index 504ffdb..091232e 100644 --- a/src/getfields.c +++ b/src/getfields.c @@ -2,7 +2,7 @@ #include "ucore/string.h" int -getfields(char *str, char **args, int max, int mflag, const char *set) +uc_getfields(char *str, char **args, int max, int mflag, const char *set) { char r; int intok, narg; diff --git a/src/gettokens.c b/src/gettokens.c index 7c6c9a4..967463e 100644 --- a/src/gettokens.c +++ b/src/gettokens.c @@ -38,7 +38,7 @@ static char *qtoken(char *s, const char *sep) return t; } -int gettokens(char *str, char **args, int maxargs, const char *sep) +int uc_gettokens(char *str, char **args, int maxargs, const char *sep) { int nargs; diff --git a/test/test_string.c b/test/test_string.c index d573b42..13c28ca 100644 --- a/test/test_string.c +++ b/test/test_string.c @@ -11,7 +11,7 @@ START_TEST (test_getfields) char str[] = "a;b;c"; char *letters[5] = {NULL}; - int rc = getfields(str, letters, 5, 0, ";"); + int rc = uc_getfields(str, letters, 5, 0, ";"); ck_assert_int_eq(rc, 3); @@ -26,7 +26,7 @@ START_TEST (test_getfields_consecutive) char str[] = "a;;b;c;;;"; char *letters[7] = {NULL}; - int rc = getfields(str, letters, 5, 0, ";"); + int rc = uc_getfields(str, letters, 5, 0, ";"); ck_assert_int_eq(rc, 5); @@ -44,7 +44,7 @@ START_TEST (test_getfields_mflag) char str[] = "a;b;c"; char *letters[5] = {NULL}; - int rc = getfields(str, letters, 5, 1, ";"); + int rc = uc_getfields(str, letters, 5, 1, ";"); ck_assert_int_eq(rc, 3); @@ -59,7 +59,7 @@ START_TEST (test_getfields_consecutive_mflag) char str[] = "a;;b;c;;;"; char *letters[7] = {NULL}; - int rc = getfields(str, letters, 7, 1, ";"); + int rc = uc_getfields(str, letters, 7, 1, ";"); ck_assert_int_eq(rc, 3); @@ -76,7 +76,7 @@ START_TEST (test_getfields_too_many) char str[] = "a\r\nb\r\nc\r\nd\r\ne"; char *letters[4] = {NULL}; - int rc = getfields(str, letters, 4, 0, "\r\n"); + int rc = uc_getfields(str, letters, 4, 0, "\r\n"); ck_assert_int_eq(rc, 4); // This result is rather silly, but it's @@ -93,7 +93,7 @@ START_TEST (test_getfields_too_many_mflag) char str[] = "a\r\nb\r\nc\r\nd\r\ne"; char *letters[4] = {NULL}; - int rc = getfields(str, letters, 4, 1, "\r\n"); + int rc = uc_getfields(str, letters, 4, 1, "\r\n"); ck_assert_int_eq(rc, 4); ck_assert_str_eq("a", letters[0]); @@ -108,11 +108,11 @@ START_TEST (test_getfields_empty) char str[] = ""; char *letters[4] = {NULL}; - int rc = getfields(str, letters, 4, 0, ";\r\n"); + int rc = uc_getfields(str, letters, 4, 0, ";\r\n"); ck_assert_int_eq(rc, 1); ck_assert_str_eq("", letters[0]); - rc = getfields(str, letters, 4, 1, ";\r\n"); + rc = uc_getfields(str, letters, 4, 1, ";\r\n"); ck_assert_int_eq(rc, 0); @@ -123,7 +123,7 @@ START_TEST (test_gettokens) char str[] = "a;b;c"; char *letters[5] = {NULL}; - int rc = gettokens(str, letters, 5,";"); + int rc = uc_gettokens(str, letters, 5,";"); ck_assert_int_eq(rc, 3); @@ -138,7 +138,7 @@ START_TEST (test_gettokens_consecutive) char str[] = "a;;;b;;c;"; char *letters[5] = {NULL}; - int rc = gettokens(str, letters, 5,";"); + int rc = uc_gettokens(str, letters, 5,";"); ck_assert_int_eq(rc, 3); @@ -153,7 +153,7 @@ START_TEST (test_gettokens_empty) char str[] = ""; char *letters[5] = {NULL}; - int rc = gettokens(str, letters, 5,";"); + int rc = uc_gettokens(str, letters, 5,";"); ck_assert_int_eq(rc, 0); END_TEST @@ -163,7 +163,7 @@ START_TEST (test_gettokens_quotes) char str[] = "\"abc\";d;\"e \""; char *letters[5] = {NULL}; - int rc = gettokens(str, letters, 5,";"); + int rc = uc_gettokens(str, letters, 5,";"); ck_assert_int_eq(rc, 3); ck_assert_str_eq("abc", letters[0]);