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