Path: blob/21.2-virgl/include/android_stub/cutils/properties.h
4547 views
/*1* Copyright (C) 2006 The Android Open Source Project2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/1516#pragma once1718#include <sys/cdefs.h>19#include <stddef.h>20#include <stdint.h>2122#if __has_include(<sys/system_properties.h>)23#include <sys/system_properties.h>24#else25#define PROP_VALUE_MAX 9226#endif2728#ifdef __cplusplus29extern "C" {30#endif3132//33// Deprecated.34//35// See <android-base/properties.h> for better API.36//3738#define PROPERTY_KEY_MAX PROP_NAME_MAX39#define PROPERTY_VALUE_MAX PROP_VALUE_MAX4041/* property_get: returns the length of the value which will never be42** greater than PROPERTY_VALUE_MAX - 1 and will always be zero terminated.43** (the length does not include the terminating zero).44**45** If the property read fails or returns an empty value, the default46** value is used (if nonnull).47*/48int property_get(const char* key, char* value, const char* default_value);4950/* property_get_bool: returns the value of key coerced into a51** boolean. If the property is not set, then the default value is returned.52**53* The following is considered to be true (1):54** "1", "true", "y", "yes", "on"55**56** The following is considered to be false (0):57** "0", "false", "n", "no", "off"58**59** The conversion is whitespace-sensitive (e.g. " off" will not be false).60**61** If no property with this key is set (or the key is NULL) or the boolean62** conversion fails, the default value is returned.63**/64int8_t property_get_bool(const char *key, int8_t default_value);6566/* property_get_int64: returns the value of key truncated and coerced into a67** int64_t. If the property is not set, then the default value is used.68**69** The numeric conversion is identical to strtoimax with the base inferred:70** - All digits up to the first non-digit characters are read71** - The longest consecutive prefix of digits is converted to a long72**73** Valid strings of digits are:74** - An optional sign character + or -75** - An optional prefix indicating the base (otherwise base 10 is assumed)76** -- 0 prefix is octal77** -- 0x / 0X prefix is hex78**79** Leading/trailing whitespace is ignored. Overflow/underflow will cause80** numeric conversion to fail.81**82** If no property with this key is set (or the key is NULL) or the numeric83** conversion fails, the default value is returned.84**/85int64_t property_get_int64(const char *key, int64_t default_value);8687/* property_get_int32: returns the value of key truncated and coerced into an88** int32_t. If the property is not set, then the default value is used.89**90** The numeric conversion is identical to strtoimax with the base inferred:91** - All digits up to the first non-digit characters are read92** - The longest consecutive prefix of digits is converted to a long93**94** Valid strings of digits are:95** - An optional sign character + or -96** - An optional prefix indicating the base (otherwise base 10 is assumed)97** -- 0 prefix is octal98** -- 0x / 0X prefix is hex99**100** Leading/trailing whitespace is ignored. Overflow/underflow will cause101** numeric conversion to fail.102**103** If no property with this key is set (or the key is NULL) or the numeric104** conversion fails, the default value is returned.105**/106int32_t property_get_int32(const char *key, int32_t default_value);107108/* property_set: returns 0 on success, < 0 on failure109*/110int property_set(const char *key, const char *value);111112int property_list(void (*propfn)(const char *key, const char *value, void *cookie), void *cookie);113114#if defined(__BIONIC_FORTIFY)115#define __property_get_err_str "property_get() called with too small of a buffer"116117#if defined(__clang__)118119/* Some projects use -Weverything; diagnose_if is clang-specific. */120#pragma clang diagnostic push121#pragma clang diagnostic ignored "-Wgcc-compat"122int property_get(const char* key, char* value, const char* default_value)123__clang_error_if(__bos(value) != __BIONIC_FORTIFY_UNKNOWN_SIZE &&124__bos(value) < PROPERTY_VALUE_MAX,125__property_get_err_str);126#pragma clang diagnostic pop127128#else /* defined(__clang__) */129130extern int __property_get_real(const char *, char *, const char *)131__asm__(__USER_LABEL_PREFIX__ "property_get");132__errordecl(__property_get_too_small_error, __property_get_err_str);133134__BIONIC_FORTIFY_INLINE135int property_get(const char *key, char *value, const char *default_value) {136size_t bos = __bos(value);137if (bos < PROPERTY_VALUE_MAX) {138__property_get_too_small_error();139}140return __property_get_real(key, value, default_value);141}142143#endif /* defined(__clang__) */144145#undef __property_get_err_str146#endif /* defined(__BIONIC_FORTIFY) */147148#ifdef __cplusplus149}150#endif151152153