OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2006 The Android Open Source Project | |
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 #ifndef __CUTILS_PROPERTIES_H | |
18 #define __CUTILS_PROPERTIES_H | |
19 | |
20 #include <sys/cdefs.h> | |
21 #include <stddef.h> | |
22 #ifdef ANDROID | |
23 #include <sys/system_properties.h> | |
24 #else | |
25 #ifndef PROP_NAME_MAX | |
26 #define PROP_NAME_MAX 32 | |
27 #endif | |
28 #ifndef PROP_VALUE_MAX | |
29 #define PROP_VALUE_MAX 92 | |
30 #endif | |
31 #endif | |
32 | |
33 #ifdef __cplusplus | |
34 extern "C" { | |
35 #endif | |
36 | |
37 /* System properties are *small* name value pairs managed by the | |
38 ** property service. If your data doesn't fit in the provided | |
39 ** space it is not appropriate for a system property. | |
40 ** | |
41 ** WARNING: system/bionic/include/sys/system_properties.h also defines | |
42 ** these, but with different names. (TODO: fix that) | |
43 */ | |
44 #define PROPERTY_KEY_MAX PROP_NAME_MAX | |
45 #define PROPERTY_VALUE_MAX PROP_VALUE_MAX | |
46 | |
47 /* property_get: returns the length of the value which will never be | |
48 ** greater than PROPERTY_VALUE_MAX - 1 and will always be zero terminated. | |
49 ** (the length does not include the terminating zero). | |
50 ** | |
51 ** If the property read fails or returns an empty value, the default | |
52 ** value is used (if nonnull). | |
53 */ | |
54 int property_get(const char *key, char *value, const char *default_value); | |
55 | |
56 /* property_set: returns 0 on success, < 0 on failure | |
57 */ | |
58 int property_set(const char *key, const char *value); | |
59 | |
60 int property_list(void (*propfn)(const char *key, const char *value, void *cooki
e), void *cookie); | |
61 | |
62 #if defined(__BIONIC_FORTIFY) | |
63 | |
64 extern int __property_get_real(const char *, char *, const char *) | |
65 __asm__(__USER_LABEL_PREFIX__ "property_get"); | |
66 __errordecl(__property_get_too_small_error, "property_get() called with too smal
l of a buffer"); | |
67 | |
68 __BIONIC_FORTIFY_INLINE | |
69 int property_get(const char *key, char *value, const char *default_value) { | |
70 size_t bos = __bos(value); | |
71 if (bos < PROPERTY_VALUE_MAX) { | |
72 __property_get_too_small_error(); | |
73 } | |
74 return __property_get_real(key, value, default_value); | |
75 } | |
76 | |
77 #endif | |
78 | |
79 #ifdef HAVE_SYSTEM_PROPERTY_SERVER | |
80 /* | |
81 * We have an external property server instead of built-in libc support. | |
82 * Used by the simulator. | |
83 */ | |
84 #define SYSTEM_PROPERTY_PIPE_NAME "/tmp/android-sysprop" | |
85 | |
86 enum { | |
87 kSystemPropertyUnknown = 0, | |
88 kSystemPropertyGet, | |
89 kSystemPropertySet, | |
90 kSystemPropertyList | |
91 }; | |
92 #endif /*HAVE_SYSTEM_PROPERTY_SERVER*/ | |
93 | |
94 | |
95 #ifdef __cplusplus | |
96 } | |
97 #endif | |
98 | |
99 #endif | |
OLD | NEW |