Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
XBT: Add xbt_str_from_file(FILE*)
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 13 Jul 2009 15:27:53 +0000 (15:27 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 13 Jul 2009 15:27:53 +0000 (15:27 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6480 48e7efb5-ca39-0410-a469-dd3cf9ba447f

ChangeLog
include/xbt/str.h
src/xbt/xbt_str.c

index 083aeea..f8feaa9 100644 (file)
--- 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 <simgrid-devel@lists.gforge.inria.fr>
 
index 333461a..d1cf580 100644 (file)
@@ -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).
index 73279a4..d18a945 100644 (file)
@@ -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;
+}