ConfigFile

Dependents:   ConfigFile_TestProgram StarBoardOrangeExpansion1 StarBoardOrangeExpansion2 Drive2ChoroQ ... more

Files at this revision

API Documentation at this revision

Comitter:
shintamainjp
Date:
Sun Sep 12 07:22:00 2010 +0000
Parent:
0:6b4ba48753b9
Child:
2:d8febae84a45
Commit message:

Changed in this revision

ConfigFile.cpp Show annotated file Show diff for this revision Revisions of this file
ConfigFile.h Show annotated file Show diff for this revision Revisions of this file
--- a/ConfigFile.cpp	Sun Sep 12 07:11:54 2010 +0000
+++ b/ConfigFile.cpp	Sun Sep 12 07:22:00 2010 +0000
@@ -31,12 +31,12 @@
     configlist = NULL;
 }
 
-char *ConfigFile::getValue(char *key) {
+bool ConfigFile::getValue(char *key, char *value, size_t siz) {
     /*
      * Null check.
      */
     if (key == NULL) {
-        return NULL;
+        return false;
     }
 
     /*
@@ -44,13 +44,21 @@
      */
     config_t *p = search(key);
     if (p == NULL) {
-        return NULL;
+        return false;
+    }
+    
+    /*
+     * Check the storage size.
+     */
+    if (siz <= strlen(p->value)) {
+        return false;
     }
 
     /*
-     * Return the value.
+     * Copy the value to the storage.
      */
-    return p->value;
+    strcpy(value, p->value);
+    return true;
 }
 
 bool ConfigFile::setValue(char *key, char *value) {
--- a/ConfigFile.h	Sun Sep 12 07:11:54 2010 +0000
+++ b/ConfigFile.h	Sun Sep 12 07:22:00 2010 +0000
@@ -23,10 +23,11 @@
      * Get a value for a key.
      *
      * @param key A target key name.
-     *
+     * @param value A pointer to a value storage.
+     * @param siz A size of a value storage.
      * @return A value or NULL.
      */
-    char *getValue(char *key);
+    bool getValue(char *key, char *value, size_t siz);
     
     /**
      * Set a set of a key and value.