aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/support
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-11-18 12:45:16 -0800
committerGravatar Craig Tiller <ctiller@google.com>2016-11-18 12:45:16 -0800
commitac5f518016fbdce5f054e725be1eb1851ac4901d (patch)
treeca8270ae0986c479cbf8cd5a352547aedb9fd7ec /src/core/lib/support
parente17029353010d0ef393d0feeb14df20321d6c984 (diff)
parentb28c7e8710638b362e5bfdd7dd81a45241c376e8 (diff)
Merge branch 'slice_with_exec_ctx' into eliminate_mdstr
Diffstat (limited to 'src/core/lib/support')
-rw-r--r--src/core/lib/support/string.c9
-rw-r--r--src/core/lib/support/string.h3
2 files changed, 12 insertions, 0 deletions
diff --git a/src/core/lib/support/string.c b/src/core/lib/support/string.c
index 85b915f118..0dc55c2ca3 100644
--- a/src/core/lib/support/string.c
+++ b/src/core/lib/support/string.c
@@ -34,7 +34,9 @@
#include "src/core/lib/support/string.h"
#include <ctype.h>
+#include <limits.h>
#include <stddef.h>
+#include <stdlib.h>
#include <string.h>
#include <grpc/support/alloc.h>
@@ -189,6 +191,13 @@ int int64_ttoa(int64_t value, char *string) {
return i;
}
+int gpr_parse_nonnegative_int(const char *value) {
+ char *end;
+ long result = strtol(value, &end, 0);
+ if (*end != '\0' || result < 0 || result > INT_MAX) return -1;
+ return (int)result;
+}
+
char *gpr_leftpad(const char *str, char flag, size_t length) {
const size_t str_length = strlen(str);
const size_t out_length = str_length > length ? str_length : length;
diff --git a/src/core/lib/support/string.h b/src/core/lib/support/string.h
index 81a12ae476..43ab4dc1be 100644
--- a/src/core/lib/support/string.h
+++ b/src/core/lib/support/string.h
@@ -77,6 +77,9 @@ NOTE: This function ensures sufficient bit width even on Win x64,
where long is 32bit is size.*/
int int64_ttoa(int64_t value, char *output);
+// Parses a non-negative number from a value string. Returns -1 on error.
+int gpr_parse_nonnegative_int(const char *value);
+
/* Reverse a run of bytes */
void gpr_reverse_bytes(char *str, int len);