diff options
author | Ben Pfaff <blp@nicira.com> | 2008-12-16 16:39:20 -0800 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2009-01-13 14:18:20 -0800 |
commit | 377cdbe1022b4557836e4efba2a748d450820ff2 (patch) | |
tree | d3f77a71dfa74ae8e3fd1f1a4e59b6f05b2fe74c | |
parent | 9190578db79763db13f2fa5763c739be241c0425 (diff) | |
download | openvswitch-377cdbe1022b4557836e4efba2a748d450820ff2.tar.gz |
New function ds_get_line().
-rw-r--r-- | lib/dynamic-string.c | 16 | ||||
-rw-r--r-- | lib/dynamic-string.h | 3 |
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/dynamic-string.c b/lib/dynamic-string.c index 2c2effbe8..03efac074 100644 --- a/lib/dynamic-string.c +++ b/lib/dynamic-string.c @@ -178,6 +178,22 @@ ds_put_strftime(struct ds *ds, const char *template, const struct tm *tm) } } +int +ds_get_line(struct ds *ds, FILE *file) +{ + ds_clear(ds); + for (;;) { + int c = getc(file); + if (c == EOF) { + return ds->length ? 0 : EOF; + } else if (c == '\n') { + return 0; + } else { + ds_put_char(ds, c); + } + } +} + char * ds_cstr(struct ds *ds) { diff --git a/lib/dynamic-string.h b/lib/dynamic-string.h index 0fb5ce4c0..5529d4b98 100644 --- a/lib/dynamic-string.h +++ b/lib/dynamic-string.h @@ -38,6 +38,7 @@ #include <stdbool.h> #include <stddef.h> #include <stdint.h> +#include <stdio.h> #include "compiler.h" struct tm; @@ -67,6 +68,8 @@ void ds_put_strftime(struct ds *, const char *, const struct tm *) STRFTIME_FORMAT(2); void ds_put_hex_dump(struct ds *ds, const void *buf_, size_t size, uintptr_t ofs, bool ascii); +int ds_get_line(struct ds *, FILE *); + char *ds_cstr(struct ds *); void ds_destroy(struct ds *); |