From: Ben Pfaff <blp@nicira.com>
Date: Wed, 15 Jul 2009 17:57:17 +0000 (-0700)
Subject: New function ds_steal_cstr().
X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4871855420190bc83fda294d7e815bd4e9c8531a;p=openvswitch

New function ds_steal_cstr().
---

diff --git a/lib/dynamic-string.c b/lib/dynamic-string.c
index 7e4843d1..9684ffad 100644
--- a/lib/dynamic-string.c
+++ b/lib/dynamic-string.c
@@ -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.
@@ -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)
 {
diff --git a/lib/dynamic-string.h b/lib/dynamic-string.h
index 1d006ff0..a44e0b30 100644
--- a/lib/dynamic-string.h
+++ b/lib/dynamic-string.h
@@ -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.
@@ -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 *);