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

Function ng_decodeidname

lib/ff_ng_base.c:950–968  ·  view source on GitHub ↗

* Decode an ID name, eg. "[f03034de]". Returns 0 if the * string is not valid, otherwise returns the value. */

Source from the content-addressed store, hash-verified

948 * string is not valid, otherwise returns the value.
949 */
950static ng_ID_t
951ng_decodeidname(const char *name)
952{
953 const int len = strlen(name);
954 char *eptr;
955 u_long val;
956
957 /* Check for proper length, brackets, no leading junk */
958 if ((len < 3) || (name[0] != '[') || (name[len - 1] != ']') ||
959 (!isxdigit(name[1])))
960 return ((ng_ID_t)0);
961
962 /* Decode number */
963 val = strtoul(name + 1, &eptr, 16);
964 if ((eptr - name != len - 1) || (val == ULONG_MAX) || (val == 0))
965 return ((ng_ID_t)0);
966
967 return ((ng_ID_t)val);
968}
969
970/*
971 * Remove a name from a node. This should only be called

Callers 2

ng_name_nodeFunction · 0.70
ng_name2noderefFunction · 0.70

Calls 2

isxdigitFunction · 0.85
strtoulFunction · 0.85

Tested by

no test coverage detected