MCPcopy Create free account
hub / github.com/antirez/ds4 / dist_parse_layers

Function dist_parse_layers

ds4_distributed.c:8036–8076  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8034 *out = DS4_DISTRIBUTED_COORDINATOR;
8035 return true;
8036 }
8037 if (!strcmp(s, "worker")) {
8038 *out = DS4_DISTRIBUTED_WORKER;
8039 return true;
8040 }
8041 return false;
8042}
8043
8044static bool dist_parse_u32_component(const char *p, size_t len, uint32_t *out) {
8045 if (!p || len == 0 || !out) return false;
8046 char buf[32];
8047 if (len >= sizeof(buf)) return false;
8048 memcpy(buf, p, len);
8049 buf[len] = '\0';
8050
8051 errno = 0;
8052 char *end = NULL;
8053 unsigned long v = strtoul(buf, &end, 10);
8054 if (errno != 0 || end == buf || *end != '\0' || v > UINT32_MAX) return false;
8055 *out = (uint32_t)v;
8056 return true;
8057}
8058
8059static bool dist_parse_layers(const char *s, ds4_distributed_layers *out, char *err, size_t errlen) {
8060 if (!s || !out) {
8061 if (errlen) snprintf(err, errlen, "missing layer range");
8062 return false;
8063 }
8064
8065 const char *colon = strchr(s, ':');
8066 if (!colon || colon == s || colon[1] == '\0') {
8067 if (errlen) snprintf(err, errlen, "expected A:B or A:output");
8068 return false;
8069 }
8070 if (strchr(colon + 1, ':')) {
8071 if (errlen) snprintf(err, errlen, "layer range has too many ':' separators");
8072 return false;
8073 }
8074
8075 ds4_distributed_layers parsed = {0};
8076 if (!dist_parse_u32_component(s, (size_t)(colon - s), &parsed.start)) {
8077 if (errlen) snprintf(err, errlen, "invalid start layer in %s", s);
8078 return false;
8079 }

Callers 1

ds4_dist_parse_cli_argFunction · 0.85

Calls 1

dist_parse_u32_componentFunction · 0.85

Tested by

no test coverage detected