ifcfg-rh: add svSetValueFull() to support writing empty values

svSetValue() treated the empty word like %NULL.
Handle empty differently from unset.
This commit is contained in:
Thomas Haller 2015-05-20 14:07:57 +02:00
parent 51255d8b64
commit 0348bc9195
2 changed files with 10 additions and 1 deletions

View file

@ -368,6 +368,14 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m
*/
void
svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim)
{
svSetValueFull (s, key, value && value[0] ? value : NULL, verbatim);
}
/* Same as svSetValue() but it preserves empty @value -- contrary to
* svSetValue() for which "" effectively means to remove the value. */
void
svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verbatim)
{
gs_free char *newval_free = NULL;
gs_free char *oldval = NULL;
@ -384,7 +392,7 @@ svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim)
newval = svEscape (value, &newval_free);
oldval = svGetValueFull (s, key, FALSE);
if (!newval || !newval[0]) {
if (!newval) {
/* delete value */
if (oldval) {
/* delete line */

View file

@ -72,6 +72,7 @@ gint64 svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, g
* to the top of the file.
*/
void svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim);
void svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verbatim);
/* Write the current contents iff modified. Returns FALSE on error