MCPcopy Index your code
hub / github.com/F-Stack/f-stack / ng_bytearray_parse

Function ng_bytearray_parse

freebsd/netgraph/ng_parse.c:1091–1127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1089};
1090
1091static int
1092ng_bytearray_parse(const struct ng_parse_type *type,
1093 const char *s, int *off, const u_char *const start,
1094 u_char *const buf, int *buflen)
1095{
1096 char *str;
1097 int toklen;
1098 int slen;
1099
1100 /* We accept either an array of bytes or a string constant */
1101 if ((str = ng_get_string_token(s, off, &toklen, &slen)) != NULL) {
1102 ng_parse_array_getLength_t *const getLength = type->info;
1103 int arraylen;
1104
1105 arraylen = (*getLength)(type, start, buf);
1106 if (arraylen > *buflen) {
1107 free(str, M_NETGRAPH_PARSE);
1108 return (ERANGE);
1109 }
1110 if (slen > arraylen) {
1111 free(str, M_NETGRAPH_PARSE);
1112 return (E2BIG);
1113 }
1114 bcopy(str, buf, slen);
1115 bzero(buf + slen, arraylen - slen);
1116 free(str, M_NETGRAPH_PARSE);
1117 *off += toklen;
1118 *buflen = arraylen;
1119 return (0);
1120 } else {
1121 struct ng_parse_type subtype;
1122
1123 subtype = ng_parse_bytearray_subtype;
1124 subtype.private = __DECONST(void *, type->info);
1125 return ng_array_parse(&subtype, s, off, start, buf, buflen);
1126 }
1127}
1128
1129static int
1130ng_bytearray_unparse(const struct ng_parse_type *type,

Callers

nothing calls this directly

Calls 4

ng_get_string_tokenFunction · 0.85
bzeroFunction · 0.85
ng_array_parseFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected