Add out-param to signal length of buffer

pull/188/head
Craig Tiller 10 years ago
parent d90e29971f
commit 16ae23dac1
  1. 2
      src/core/channel/call_op_string.c
  2. 9
      src/core/support/string.c
  3. 8
      src/core/support/string.h
  4. 2
      src/core/surface/event_string.c

@ -117,7 +117,7 @@ char *grpc_call_op_string(grpc_call_op *op) {
gpr_asprintf(&tmp, " flags=0x%08x", op->flags);
gpr_strvec_add(&b, tmp);
out = gpr_strvec_flatten(&b);
out = gpr_strvec_flatten(&b, NULL);
gpr_strvec_destroy(&b);
return out;

@ -153,7 +153,7 @@ int gpr_ltoa(long value, char *string) {
return i;
}
char *gpr_strjoin(const char **strs, size_t nstrs) {
char *gpr_strjoin(const char **strs, size_t nstrs, size_t *final_length) {
size_t out_length = 0;
size_t i;
char *out;
@ -169,6 +169,9 @@ char *gpr_strjoin(const char **strs, size_t nstrs) {
out_length += slen;
}
out[out_length] = 0;
if (final_length != NULL) {
*final_length = out_length;
}
return out;
}
@ -192,6 +195,6 @@ void gpr_strvec_add(gpr_strvec *sv, char *str) {
sv->strs[sv->count++] = str;
}
char *gpr_strvec_flatten(gpr_strvec *sv) {
return gpr_strjoin((const char**)sv->strs, sv->count);
char *gpr_strvec_flatten(gpr_strvec *sv, size_t *final_length) {
return gpr_strjoin((const char**)sv->strs, sv->count, final_length);
}

@ -81,8 +81,10 @@ void gpr_reverse_bytes(char *str, int len);
the result is undefined. */
int gpr_asprintf(char **strp, const char *format, ...);
/* Join a set of strings, returning the resulting string */
char *gpr_strjoin(const char **strs, size_t nstrs);
/* Join a set of strings, returning the resulting string.
Total combined length (excluding null terminator) is returned in total_length
if it is non-null. */
char *gpr_strjoin(const char **strs, size_t nstrs, size_t *total_length);
/* A vector of strings... addition takes ownership of strings */
typedef struct {
@ -94,7 +96,7 @@ typedef struct {
void gpr_strvec_init(gpr_strvec *strs);
void gpr_strvec_destroy(gpr_strvec *strs);
void gpr_strvec_add(gpr_strvec *strs, char *add);
char *gpr_strvec_flatten(gpr_strvec *strs);
char *gpr_strvec_flatten(gpr_strvec *strs, size_t *total_length);
#ifdef __cplusplus
}

@ -131,7 +131,7 @@ char *grpc_event_string(grpc_event *ev) {
break;
}
out = gpr_strvec_flatten(&buf);
out = gpr_strvec_flatten(&buf, NULL);
gpr_strvec_destroy(&buf);
return out;
}

Loading…
Cancel
Save