[ovs-dev] [PATCH v3 1/7] dynamic-string: Make ds_chomp() return true if it removed a character.
Ben Pfaff
blp at ovn.org
Wed Feb 10 06:10:26 UTC 2016
This will be used in an upcoming commit.
Signed-off-by: Ben Pfaff <blp at ovn.org>
---
lib/dynamic-string.c | 7 +++++--
lib/dynamic-string.h | 4 ++--
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/lib/dynamic-string.c b/lib/dynamic-string.c
index a6c8f6c..a5a3460 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 f1e0a36..cc064c0 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. */
--
2.1.3
More information about the dev
mailing list