Module: xenomai-forge
Branch: next
Commit: 273dc2c1d09e2c24377ed239072a7cb45d9c0f22
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=273dc2c1d09e2c24377ed239072a7cb45d9c0f22

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Apr 11 11:46:21 2014 +0200

copperplate/registry: introduce fsobstack_grow_file() helper

---

 include/copperplate/registry-obstack.h |    3 +++
 lib/copperplate/registry.c             |   26 ++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/include/copperplate/registry-obstack.h 
b/include/copperplate/registry-obstack.h
index a08afef..0fd1e1c 100644
--- a/include/copperplate/registry-obstack.h
+++ b/include/copperplate/registry-obstack.h
@@ -54,6 +54,9 @@ extern "C" {
 int fsobstack_grow_format(struct fsobstack *o,
                          const char *fmt, ...);
 
+int fsobstack_grow_file(struct fsobstack *o,
+                       const char *path);
+
 int fsobstack_grow_syncobj_grant(struct fsobstack *o,
                                 struct syncobj *sobj,
                                 struct fsobstack_syncops *ops);
diff --git a/lib/copperplate/registry.c b/lib/copperplate/registry.c
index ef6aa45..fe8153a 100644
--- a/lib/copperplate/registry.c
+++ b/lib/copperplate/registry.c
@@ -822,6 +822,32 @@ int fsobstack_grow_format(struct fsobstack *o, const char 
*fmt, ...)
        return -ENOMEM;
 }
 
+int fsobstack_grow_file(struct fsobstack *o, const char *path)
+{
+       int len = 0;
+       FILE *fp;
+       int c;
+       
+       fp = fopen(path, "r");
+       if (fp == NULL)
+               return -errno;
+
+       for (;;) {
+               c = fgetc(fp);
+               if (c == EOF) {
+                       if (ferror(fp))
+                               len = -errno;
+                       break;
+               }
+               obstack_1grow(&o->obstack, c);
+               len++;
+       }
+
+       fclose(fp);
+
+       return len;
+}
+
 ssize_t fsobstack_pull(struct fsobstack *o, char *buf, size_t size)
 {
        size_t len;


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to