Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=cfpm.git;a=commitdiff;h=f9c5a3c14aec79ffbcb850b21032f2bbd2e77ba8

commit f9c5a3c14aec79ffbcb850b21032f2bbd2e77ba8
Author: James Buren <r...@frugalware.org>
Date:   Thu Oct 29 11:48:12 2009 -0500

Config.c
* add draft of config_parse()
* convert size to num

diff --git a/src/Config.c b/src/Config.c
index 51a5a36..c86b2d6 100644
--- a/src/Config.c
+++ b/src/Config.c
@@ -20,7 +20,7 @@ struct Config {
char *path;
char *err;
char *buf;
-  size_t size;
+  size_t num;
Pair *data;
};

@@ -37,13 +37,60 @@ Config *config_create(const char *path) {

cfg->buf = NULL;

-  cfg->size = 0;
+  cfg->num = 0;

cfg->data = NULL;

return cfg;
}

+static bool _config_parse_fill_buffer(Config *cfg) {
+  int file;
+  struct stat stats;
+  bool ret;
+
+  assert((cfg != NULL));
+
+  file = open(cfg->path,O_RDONLY);
+
+  if(file == -1) {
+    ret = false;
+    goto Bail;
+  }
+
+  if(fstat(file,&stats) == -1) {
+    ret = false;
+    goto Bail;
+  }
+
+  cfg->num = stats.st_size;
+
+  cfg->buf = xalloc(char,cfg->num);
+
+  if(read(file,cfg->buf,cfg->num) == -1) {
+    ret = false;
+    goto Bail;
+  }
+
+  ret = true;
+
+  Bail:
+
+  if(file != -1)
+    close(file);
+
+  return ret;
+}
+
+bool config_parse(Config *cfg) {
+  assert((cfg != NULL));
+
+  if(_config_parse_fill_buffer(cfg) == false)
+    return false;
+
+  return true;
+}
+
void config_destroy(Config *cfg) {
assert((cfg != NULL));
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to