T-Box Basic dev
Loading...
Searching...
No Matches
properties.h
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/* clang-format off */
18#ifndef __CUTILS_PROPERTIES_H
19#define __CUTILS_PROPERTIES_H
20
21#include <sys/cdefs.h>
22#include <stddef.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/* property_get: returns the length of the value which will never be
29** greater than PROP_VALUE_MAX - 1 and will always be zero terminated.
30** (the length does not include the terminating zero).
31**
32** If the property read fails or returns an empty value, the default
33** value is used (if nonnull).
34*/
35int property_get(const char *key, char *value, const char *default_value);
36
37/* property_set: returns 0 on success, < 0 on failure
38*/
39int property_set(const char *key, const char *value);
40
41int property_list(void (*propfn)(const char *key, const char *value, void *cookie), void *cookie);
42
43int property_init(void);
44
45#if defined(__BIONIC_FORTIFY)
46
47extern int __property_get_real(const char *, char *, const char *)
48 __asm__(__USER_LABEL_PREFIX__ "property_get");
49__errordecl(__property_get_too_small_error, "property_get() called with too small of a buffer");
50
51__BIONIC_FORTIFY_INLINE
52int property_get(const char *key, char *value, const char *default_value) {
53 size_t bos = __bos(value);
54 if (bos < PROP_VALUE_MAX) {
55 __property_get_too_small_error();
56 }
57 return __property_get_real(key, value, default_value);
58}
59
60#endif
61
62#ifdef HAVE_SYSTEM_PROPERTY_SERVER
63/*
64 * We have an external property server instead of built-in libc support.
65 * Used by the simulator.
66 */
67#define SYSTEM_PROPERTY_PIPE_NAME "/tmp/android-sysprop"
68
69enum {
70 kSystemPropertyUnknown = 0,
71 kSystemPropertyGet,
72 kSystemPropertySet,
73 kSystemPropertyList
74};
75#endif /*HAVE_SYSTEM_PROPERTY_SERVER*/
76
77
78#ifdef __cplusplus
79}
80#endif
81
82#endif
83/* clang-format on */