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"
32 #include "ail_private.h"
34 #define VCONFTOOL "/usr/bin/vconftool"
35 #define CMD_VCONF_GET_STR VCONFTOOL " -q get '%s'"
36 #define CMD_VCONF_SET_STR VCONFTOOL " -q set -t string '%s' '%s' -f"
40 Reads the content of the input 'stream' (it should be a text without nul
41 characters) in a feshly allocated buffer, using allocations of 'block_size'
44 Returns the read string or NULL in case of error.
46 static char *_pread_(FILE *stream, size_t block_size)
55 if (ferror(stream) != 0) {
59 /* allocate enough memory */
60 /* assert(length <= alloc) */
61 if (length >= alloc) {
63 string = realloc(result, alloc + 1); /* one more for ending null */
70 /* assert(length < alloc) */
71 /* assert(result != NULL); */
73 if (feof(stream) != 0) {
77 length += fread(result + length, 1, alloc - length, stream);
82 Runs the command given by 'cmddef' and its arguments formated as printf.
84 The resulting output stream of the command is return as a freshly allocated
87 Retruns 0 in case of success or -1 in case of error.
89 static int _ail_vconf_exec_(char **readen, const char *cmddef, ...)
98 result = vasprintf(&command, cmddef, ap);
102 stream = popen(command, "r");
103 if (stream != NULL) {
104 *readen = _pread_(stream, 1024);
105 if (pclose(stream) != -1 && *readen != NULL) {
115 vconf_get_str with fallback to the command vconftool.
117 EXPORT_API char *ail_vconf_get_str(const char *keyname)
124 result = vconf_get_str(keyname);
125 if (result == NULL) {
126 status = _ail_vconf_exec_(&data, CMD_VCONF_GET_STR, keyname);
128 /* the string data is of the form 'key, value = ...\n' */
129 result = strstr(data, " = ");
130 if (result != NULL) {
131 /* skips the prefix " = " */
133 /* remove trailing '\n' */
134 length = strlen(result);
135 if (length > 0 && result[length-1] == '\n') {
136 result[length-1] = 0;
138 /* get the final result */
139 result = strdup(result);
148 vconf_set_str with fallback to the command vconftool.
150 EXPORT_API int ail_vconf_set_str(const char *keyname, const char *strval)
155 result = vconf_set_str(keyname, strval);
157 result = _ail_vconf_exec_(&data, CMD_VCONF_SET_STR, keyname, strval);