X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fdynamic-string.c;h=c3338180d250aed389c432031598fde630cb8afa;hb=836fad5e1ae4316752150fcdfba9afbf8d5f5801;hp=531e53bbe9ab9f2195d4a7481cd7aeea306439f4;hpb=f38b84ea2b6b61d309c604faedd41ab3b0fcf16b;p=openvswitch diff --git a/lib/dynamic-string.c b/lib/dynamic-string.c index 531e53bb..c3338180 100644 --- a/lib/dynamic-string.c +++ b/lib/dynamic-string.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009 Nicira Networks. + * Copyright (c) 2008, 2009, 2010 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -115,6 +115,13 @@ ds_put_cstr(struct ds *ds, const char *s) memcpy(ds_put_uninit(ds, s_len), s, s_len); } +void +ds_put_and_free_cstr(struct ds *ds, char *s) +{ + ds_put_cstr(ds, s); + free(s); +} + void ds_put_format(struct ds *ds, const char *format, ...) { @@ -212,6 +219,12 @@ ds_cstr(struct ds *ds) return ds->string; } +const char * +ds_cstr_ro(const struct ds *ds) +{ + return ds_cstr((struct ds *) ds); +} + /* 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'. */ @@ -229,6 +242,15 @@ ds_destroy(struct ds *ds) free(ds->string); } +/* Swaps the content of 'a' and 'b'. */ +void +ds_swap(struct ds *a, struct ds *b) +{ + struct ds temp = *a; + *a = *b; + *b = temp; +} + /* Writes the 'size' bytes in 'buf' to 'string' as hex bytes arranged 16 per * line. Numeric offsets are also included, starting at 'ofs' for the first * byte in 'buf'. If 'ascii' is true then the corresponding ASCII characters