From: Ben Pfaff Date: Wed, 10 Feb 2016 04:54:03 +0000 (-0800) Subject: dynamic-string: Make ds_chomp() return true if it removed a character. X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=29100ef2ba237a198b9cf85241107589af7b51d4 dynamic-string: Make ds_chomp() return true if it removed a character. This will be used in an upcoming commit. Signed-off-by: Ben Pfaff Acked-by: Jarno Rajahalme --- diff --git a/lib/dynamic-string.c b/lib/dynamic-string.c index a6c8f6c76..a5a3460ef 100644 --- a/lib/dynamic-string.c +++ b/lib/dynamic-string.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2016 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -446,10 +446,13 @@ ds_last(const struct ds *ds) return ds->length > 0 ? (unsigned char) ds->string[ds->length - 1] : EOF; } -void +bool ds_chomp(struct ds *ds, int c) { if (ds->length > 0 && ds->string[ds->length - 1] == (char) c) { ds->string[--ds->length] = '\0'; + return true; + } else { + return false; } } diff --git a/lib/dynamic-string.h b/lib/dynamic-string.h index f1e0a368a..cc064c084 100644 --- a/lib/dynamic-string.h +++ b/lib/dynamic-string.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2016 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,7 +73,7 @@ void ds_destroy(struct ds *); void ds_swap(struct ds *, struct ds *); int ds_last(const struct ds *); -void ds_chomp(struct ds *, int c); +bool ds_chomp(struct ds *, int c); /* Inline functions. */