MCPcopy Create free account
hub / github.com/F-Stack/f-stack / cmdline_parse_string

Function cmdline_parse_string

dpdk/lib/cmdline/cmdline_parse_string.c:50–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50int
51cmdline_parse_string(cmdline_parse_token_hdr_t *tk, const char *buf, void *res,
52 unsigned ressize)
53{
54 struct cmdline_token_string *tk2;
55 struct cmdline_token_string_data *sd;
56 unsigned int token_len;
57 const char *str;
58
59 if (res && ressize < STR_TOKEN_SIZE)
60 return -1;
61
62 if (!tk || !buf || ! *buf)
63 return -1;
64
65 tk2 = (struct cmdline_token_string *)tk;
66
67 sd = &tk2->string_data;
68
69 /* fixed string (known single token) */
70 if ((sd->str != NULL) && (strcmp(sd->str, TOKEN_STRING_MULTI) != 0)) {
71 str = sd->str;
72 do {
73 token_len = get_token_len(str);
74
75 /* if token is too big... */
76 if (token_len >= STR_TOKEN_SIZE - 1) {
77 continue;
78 }
79
80 if ( strncmp(buf, str, token_len) ) {
81 continue;
82 }
83
84 if ( !cmdline_isendoftoken(*(buf+token_len)) ) {
85 continue;
86 }
87
88 break;
89 } while ( (str = get_next_token(str)) != NULL );
90
91 if (!str)
92 return -1;
93 }
94 /* multi string */
95 else if (sd->str != NULL) {
96 if (ressize < STR_MULTI_TOKEN_SIZE)
97 return -1;
98
99 token_len = 0;
100 while (!cmdline_isendofcommand(buf[token_len]) &&
101 token_len < (STR_MULTI_TOKEN_SIZE - 1))
102 token_len++;
103
104 /* return if token too long */
105 if (token_len >= (STR_MULTI_TOKEN_SIZE - 1))
106 return -1;
107 }

Callers 3

test_parse_string_validFunction · 0.85

Calls 7

strcmpFunction · 0.85
get_token_lenFunction · 0.85
strncmpFunction · 0.85
cmdline_isendoftokenFunction · 0.85
get_next_tokenFunction · 0.85
cmdline_isendofcommandFunction · 0.85
strlcpyFunction · 0.50

Tested by 3

test_parse_string_validFunction · 0.68