Skip to content

Commit

Permalink
New function ds_steal_cstr().
Browse files Browse the repository at this point in the history
  • Loading branch information
blp committed Jul 16, 2009
1 parent a8b5f8b commit 4871855
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/dynamic-string.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008 Nicira Networks.
* Copyright (c) 2008, 2009 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -187,6 +187,17 @@ ds_cstr(struct ds *ds)
return ds->string;
}

/* Returns a null-terminated string representing the current contents of 'ds',
* which the caller is expected to free with free(), then clears the contents
* of 'ds'. */
char *
ds_steal_cstr(struct ds *ds)
{
char *s = ds_cstr(ds);
ds_init(ds);
return s;
}

void
ds_destroy(struct ds *ds)
{
Expand Down
3 changes: 2 additions & 1 deletion lib/dynamic-string.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008 Nicira Networks.
* Copyright (c) 2008, 2009 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,6 +54,7 @@ void ds_put_hex_dump(struct ds *ds, const void *buf_, size_t size,
int ds_get_line(struct ds *, FILE *);

char *ds_cstr(struct ds *);
char *ds_steal_cstr(struct ds *);
void ds_destroy(struct ds *);

int ds_last(const struct ds *);
Expand Down

0 comments on commit 4871855

Please sign in to comment.