Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ConfigFile by
Revision 1:f02e081afe42, committed 2010-09-12
- 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.
