1 /* 2 * SPDX-FileCopyrightText: 2015-2022 The Apache Software Foundation (ASF) 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * SPDX-FileContributor: 2019-2022 Espressif Systems (Shanghai) CO LTD 7 */ 8 /* 9 * Licensed to the Apache Software Foundation (ASF) under one 10 * or more contributor license agreements. See the NOTICE file 11 * distributed with this work for additional information 12 * regarding copyright ownership. The ASF licenses this file 13 * to you under the Apache License, Version 2.0 (the 14 * "License"); you may not use this file except in compliance 15 * with the License. You may obtain a copy of the License at 16 * 17 * http://www.apache.org/licenses/LICENSE-2.0 18 * 19 * Unless required by applicable law or agreed to in writing, 20 * software distributed under the License is distributed on an 21 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 22 * KIND, either express or implied. See the License for the 23 * specific language governing permissions and limitations 24 * under the License. 25 */ 26 27 #ifndef H_OS_UTIL_ 28 #define H_OS_UTIL_ 29 30 /* Helpers to pass integers as pointers and vice-versa */ 31 #define POINTER_TO_UINT(p) ((unsigned int) ((uintptr_t) (p))) 32 #define UINT_TO_POINTER(u) ((void *) ((uintptr_t) (u))) 33 #define POINTER_TO_INT(p) ((int) ((intptr_t) (p))) 34 #define INT_TO_POINTER(u) ((void *) ((intptr_t) (u))) 35 36 /* Helper to retrieve pointer to "parent" object in structure */ 37 #define CONTAINER_OF(ptr, type, field) \ 38 ((type *)(((char *)(ptr)) - offsetof(type, field))) 39 40 /* Helper to calculate number of elements in array */ 41 #ifndef ARRAY_SIZE 42 #define ARRAY_SIZE(array) \ 43 (sizeof(array) / sizeof((array)[0])) 44 #endif 45 #endif 46