4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #if !defined(NO_VCONF_BUXTON_FALLBACK)
31 #include "ail_vconf.h"
33 #define VCONFTOOL "/usr/bin/vconftool"
34 #define CMD_VCONF_GET_STR VCONFTOOL " -q get '%s'"
35 #define CMD_VCONF_SET_STR VCONFTOOL " -q set -t string '%s' '%s' -f"
39 Reads the content of the input 'stream' (it should be a text without nul
40 characters) in a feshly allocated buffer, using allocations of 'block_size'
43 Returns the read string or NULL in case of error.
45 static char *_pread_(FILE *stream, size_t block_size)
54 if (ferror(stream) != 0) {
58 /* allocate enough memory */
59 /* assert(length <= alloc) */
60 if (length >= alloc) {
62 string = realloc(result, alloc + 1); /* one more for ending null */
69 /* assert(length < alloc) */
70 /* assert(result != NULL); */
72 if (feof(stream) != 0) {
76 length += fread(result + length, 1, alloc - length, stream);
81 Runs the command given by 'cmddef' and its arguments formated as printf.
83 The resulting output stream of the command is return as a freshly allocated
86 Retruns 0 in case of success or -1 in case of error.
88 static int _ail_vconf_exec_(char **readen, const char *cmddef, ...)
97 result = vasprintf(&command, cmddef, ap);
101 stream = popen(command, "r");
102 if (stream != NULL) {
103 *readen = _pread_(stream, 1024);
104 if (pclose(stream) != -1 && *readen != NULL) {
114 vconf_get_str with fallback to the command vconftool.
116 char *ail_vconf_get_str(const char *keyname)
123 result = vconf_get_str(keyname);
124 if (result == NULL) {
125 status = _ail_vconf_exec_(&data, CMD_VCONF_GET_STR, keyname);
127 /* the string data is of the form 'key, value = ...\n' */
128 result = strstr(data, " = ");
129 if (result != NULL) {
130 /* skips the prefix " = " */
132 /* remove trailing '\n' */
133 length = strlen(result);
134 if (length > 0 && result[length-1] == '\n') {
135 result[length-1] = 0;
137 /* get the final result */
138 result = strdup(result);
147 vconf_set_str with fallback to the command vconftool.
149 int ail_vconf_set_str(const char *keyname, const char *strval)
154 result = vconf_set_str(keyname, strval);
156 result = _ail_vconf_exec_(&data, CMD_VCONF_SET_STR, keyname, strval);