system_properties.h revision 11cd02dfb91661c65134cac258cf5924270e9d2
111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * Copyright (C) 2008 The Android Open Source Project 311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * All rights reserved. 411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * 511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * Redistribution and use in source and binary forms, with or without 611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * modification, are permitted provided that the following conditions 711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * are met: 811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * * Redistributions of source code must retain the above copyright 911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * notice, this list of conditions and the following disclaimer. 1011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * * Redistributions in binary form must reproduce the above copyright 1111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * notice, this list of conditions and the following disclaimer in 1211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * the documentation and/or other materials provided with the 1311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * distribution. 1411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * 1511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 1911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 2011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 2111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 2211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 2311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 2511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * SUCH DAMAGE. 2711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 2811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 2911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#ifndef _INCLUDE_SYS_SYSTEM_PROPERTIES_H 3011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define _INCLUDE_SYS_SYSTEM_PROPERTIES_H 3111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 3211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#include <sys/cdefs.h> 3311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 3411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert__BEGIN_DECLS 3511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 3611cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef struct prop_info prop_info; 3711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 3811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PROP_NAME_MAX 32 3911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PROP_VALUE_MAX 92 4011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 4111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* Look up a system property by name, copying its value and a 4211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** \0 terminator to the provided pointer. The total bytes 4311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** copied will be no greater than PROP_VALUE_MAX. Returns 4411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** the string length of the value. A property that is not 4511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** defined is identical to a property with a length 0 value. 4611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 4711cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint __system_property_get(const char *name, char *value); 4811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 4911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* Set a system property by name. 5011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert**/ 5111cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint __system_property_set(const char *key, const char *value); 5211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 5311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* Return a pointer to the system property named name, if it 5411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** exists, or NULL if there is no such property. Use 5511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** __system_property_read() to obtain the string value from 5611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** the returned prop_info pointer. 5711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** 5811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** It is safe to cache the prop_info pointer to avoid future 5911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** lookups. These returned pointers will remain valid for 6011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** the lifetime of the system. 6111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 6211cd02dfb91661c65134cac258cf5924270e9d2Dan Albertconst prop_info *__system_property_find(const char *name); 6311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 6411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* Read the value of a system property. Returns the length 6511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** of the value. Copies the value and \0 terminator into 6611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** the provided value pointer. Total length (including 6711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** terminator) will be no greater that PROP_VALUE_MAX. 6811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** 6911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** If name is nonzero, up to PROP_NAME_MAX bytes will be 7011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** copied into the provided name pointer. The name will 7111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** be \0 terminated. 7211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 7311cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint __system_property_read(const prop_info *pi, char *name, char *value); 7411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 7511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* Return a prop_info for the nth system property, or NULL if 7611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** there is no nth property. Use __system_property_read() to 7711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** read the value of this property. 7811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** 7911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** Please do not call this method. It only exists to provide 8011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** backwards compatibility to NDK apps. Its implementation 8111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** is inefficient and order of results may change from call 8211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** to call. 8311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 8411cd02dfb91661c65134cac258cf5924270e9d2Dan Albertconst prop_info *__system_property_find_nth(unsigned n); 8511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 8611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* Pass a prop_info for each system property to the provided 8711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** callback. Use __system_property_read() to read the value 8811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** of this property. 8911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** 9011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** This method is for inspecting and debugging the property 9111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** system. Please use __system_property_find() instead. 9211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** 9311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** Order of results may change from call to call. This is 9411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert** not a bug. 9511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 9611cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint __system_property_foreach( 9711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert void (*propfn)(const prop_info *pi, void *cookie), 9811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert void *cookie); 9911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 10011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert__END_DECLS 10111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 10211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#endif 103