~sergiusens/libhybris/autotests

« back to all changes in this revision

Viewing changes to hybris/common/properties.c

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo
  • Date: 2013-06-04 07:33:11 UTC
  • Revision ID: package-import@ubuntu.com-20130604073311-20ldi2hm1axkvjl1
Tags: upstream-0.1.0+git20130601+dfb2e26
ImportĀ upstreamĀ versionĀ 0.1.0+git20130601+dfb2e26

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2012 Carsten Munk <carsten.munk@gmail.com>
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 * http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 *
 
16
 */
 
17
 
 
18
#include <stddef.h>
 
19
#include <string.h>
 
20
#include <stdio.h>
 
21
#include <stdlib.h>
 
22
 
 
23
static char *find_key(const char *key)
 
24
{
 
25
        FILE *f = fopen("/system/build.prop", "r");
 
26
        char buf[1024];
 
27
        char *mkey, *value;
 
28
 
 
29
        if (!f)
 
30
                return NULL;
 
31
 
 
32
        while (fgets(buf, 1024, f) != NULL) {
 
33
                if (strchr(buf, '\r'))
 
34
                        *(strchr(buf, '\r')) = '\0';
 
35
                if (strchr(buf, '\n'))
 
36
                        *(strchr(buf, '\n')) = '\0';
 
37
 
 
38
                mkey = strtok(buf, "=");
 
39
 
 
40
                if (!mkey)
 
41
                        continue;
 
42
 
 
43
                value = strtok(NULL, "=");
 
44
                if (!value)
 
45
                        continue;
 
46
 
 
47
                if (strcmp(key, mkey) == 0) {
 
48
                        fclose(f);
 
49
                        return strdup(value);
 
50
                }
 
51
        }
 
52
 
 
53
        fclose(f);
 
54
        return NULL;
 
55
}
 
56
 
 
57
int property_get(const char *key, char *value, const char *default_value)
 
58
{
 
59
        char *ret = NULL; 
 
60
 
 
61
        //printf("property_get: %s\n", key);
 
62
 
 
63
        /* default */
 
64
        ret = find_key(key);
 
65
 
 
66
#if 0
 
67
 if (strcmp(key, "ro.kernel.qemu") == 0)
 
68
 {
 
69
    ret = "0";
 
70
 }  
 
71
 else if (strcmp(key, "ro.hardware") == 0)
 
72
 { 
 
73
    ret = "tenderloin";
 
74
 } 
 
75
 else if (strcmp(key, "ro.product.board") == 0)
 
76
 {
 
77
    ret = "tenderloin";
 
78
 }
 
79
 else if (strcmp(key, "ro.board.platform") == 0)
 
80
 { 
 
81
    ret = "msm8660";
 
82
 }
 
83
 else if (strcmp(key, "ro.arch") == 0)
 
84
 {
 
85
    ret = "armeabi";
 
86
 }
 
87
 else if (strcmp(key, "debug.composition.type") == 0)
 
88
 {
 
89
    ret = "c2d"; 
 
90
 }
 
91
 else if (strcmp(key, "debug.sf.hw") == 0)
 
92
 {
 
93
   ret = "1";
 
94
 }
 
95
 else if (strcmp(key, "debug.gr.numframebuffers") == 0)
 
96
 { 
 
97
   ret = "1"; 
 
98
 }  
 
99
#endif
 
100
        if (ret) {
 
101
                printf("found %s for %s\n", key, ret);
 
102
        }
 
103
        if (ret == NULL) {
 
104
                if (default_value != NULL) {
 
105
                        strcpy(value, default_value);
 
106
                        return strlen(value);
 
107
                }
 
108
                else {
 
109
                        return 0;
 
110
                }
 
111
        }
 
112
        if (ret) {
 
113
                strcpy(value, ret);
 
114
                free(ret);
 
115
                return strlen(value);
 
116
        }
 
117
        else {
 
118
                return 0;
 
119
        }
 
120
}
 
121
 
 
122
int property_set(const char *key, const char *value)
 
123
{
 
124
        printf("property_set: %s %s\n", key, value);
 
125
}
 
126
 
 
127
// vim:ts=4:sw=4:noexpandtab