blob: 499b36a9b8758f22a5dfeab12f838782380010ac [file] [log] [blame]
Tom Cherryfd44b9f2017-11-08 14:01:00 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
Tom Cherrye275d6d2017-12-11 23:31:33 -080029#include "system_properties/prop_info.h"
Tom Cherryfd44b9f2017-11-08 14:01:00 -080030
31#include <string.h>
32
Elliott Hughes30088842023-09-14 18:35:11 +000033static constexpr const char kLongLegacyError[] =
Tom Cherryfd44b9f2017-11-08 14:01:00 -080034 "Must use __system_property_read_callback() to read";
35static_assert(sizeof(kLongLegacyError) < prop_info::kLongLegacyErrorBufferSize,
36 "Error message for long properties read by legacy libc must fit within 56 chars");
37
38prop_info::prop_info(const char* name, uint32_t namelen, const char* value, uint32_t valuelen) {
39 memcpy(this->name, name, namelen);
40 this->name[namelen] = '\0';
Nick Desaulniers2e65afe2024-11-19 09:27:06 -080041 atomic_store_explicit(&this->serial, valuelen << 24, memory_order_relaxed);
Tom Cherryfd44b9f2017-11-08 14:01:00 -080042 memcpy(this->value, value, valuelen);
43 this->value[valuelen] = '\0';
44}
45
46prop_info::prop_info(const char* name, uint32_t namelen, uint32_t long_offset) {
47 memcpy(this->name, name, namelen);
48 this->name[namelen] = '\0';
49
50 auto error_value_len = sizeof(kLongLegacyError) - 1;
Nick Desaulniers2e65afe2024-11-19 09:27:06 -080051 atomic_store_explicit(&this->serial, error_value_len << 24 | kLongFlag, memory_order_relaxed);
Tom Cherryfd44b9f2017-11-08 14:01:00 -080052 memcpy(this->long_property.error_message, kLongLegacyError, sizeof(kLongLegacyError));
53
54 this->long_property.offset = long_offset;
55}