From 6f4585f1e19602414bc4971c9d19fc5d600eb0fa Mon Sep 17 00:00:00 2001 From: mquinson Date: Mon, 13 Jul 2009 15:27:53 +0000 Subject: [PATCH 1/1] XBT: Add xbt_str_from_file(FILE*) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6480 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- ChangeLog | 1 + include/xbt/str.h | 3 +++ src/xbt/xbt_str.c | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/ChangeLog b/ChangeLog index 083aeea747..f8feaa987a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -55,6 +55,7 @@ SimGrid (3.3.2-svn) unstable; urgency=low XBT: * Add xbt_set_get_by_name_or_null() [Silas De Munck] * Add xbt_graph_node_get_outedges() [Silas De Munck] + * Add xbt_str_from_file(FILE*) -- Da SimGrid team diff --git a/include/xbt/str.h b/include/xbt/str.h index 333461a491..d1cf58001f 100644 --- a/include/xbt/str.h +++ b/include/xbt/str.h @@ -74,6 +74,9 @@ XBT_PUBLIC(char *) xbt_str_varsubst(char *str, xbt_dict_t patterns); XBT_PUBLIC(void) xbt_str_strip_spaces(char *); XBT_PUBLIC(char *) xbt_str_diff(char *a, char *b); + +XBT_PUBLIC(char*)xbt_str_from_file(FILE *file); + /** @brief Classical alias to (char*) * * This of almost no use, beside cosmetics and the GRAS parsing macro (see \ref GRAS_dd_auto). diff --git a/src/xbt/xbt_str.c b/src/xbt/xbt_str.c index 73279a41e8..d18a94588f 100644 --- a/src/xbt/xbt_str.c +++ b/src/xbt/xbt_str.c @@ -699,3 +699,23 @@ char *xbt_str_diff(char *a, char *b) return res; } + + +/** @brief creates a new string containing what can be read on a fd + * + */ +char* xbt_str_from_file(FILE *file) { + xbt_strbuff_t buff = xbt_strbuff_new(); + char *res; + char bread[1024]; + + while (!feof(file)) { + fread(bread, 1, 1023, file); + bread[1023] = '\0'; + xbt_strbuff_append(buff,bread); + } + + res = buff->data; + xbt_strbuff_free_container(buff); + return res; +} -- 2.20.1