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