The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
Elliott Hughes | 203e13d | 2016-07-22 14:56:18 -0700 | [diff] [blame] | 28 | |
Elliott Hughes | dd6763a | 2018-10-04 16:35:13 -0700 | [diff] [blame^] | 29 | #pragma once |
| 30 | |
| 31 | /** |
| 32 | * @file sys/param.h |
| 33 | * @brief Various macros. |
| 34 | */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | |
| 36 | #include <limits.h> |
Yabin Cui | 2d8f9b5 | 2015-02-09 13:58:28 -0800 | [diff] [blame] | 37 | #include <linux/param.h> |
Elliott Hughes | 203e13d | 2016-07-22 14:56:18 -0700 | [diff] [blame] | 38 | #include <sys/cdefs.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 39 | |
Elliott Hughes | dd6763a | 2018-10-04 16:35:13 -0700 | [diff] [blame^] | 40 | /** The unit of `st_blocks` in `struct stat`. */ |
Elliott Hughes | 1f1a51a | 2016-03-31 17:05:30 -0700 | [diff] [blame] | 41 | #define DEV_BSIZE 512 |
| 42 | |
Elliott Hughes | dd6763a | 2018-10-04 16:35:13 -0700 | [diff] [blame^] | 43 | /** A historical name for PATH_MAX. */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 44 | #define MAXPATHLEN PATH_MAX |
Elliott Hughes | dd6763a | 2018-10-04 16:35:13 -0700 | [diff] [blame^] | 45 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 46 | #define MAXSYMLINKS 8 |
| 47 | |
Elliott Hughes | c2f082f | 2013-12-12 15:31:35 -0800 | [diff] [blame] | 48 | #ifndef howmany |
| 49 | #define howmany(x, y) (((x)+((y)-1))/(y)) |
| 50 | #endif |
| 51 | #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) |
Elliott Hughes | c2f082f | 2013-12-12 15:31:35 -0800 | [diff] [blame] | 52 | |
Elliott Hughes | dd6763a | 2018-10-04 16:35:13 -0700 | [diff] [blame^] | 53 | /** Returns true if the argument is a power of two. */ |
| 54 | #define powerof2(x) ((((x)-1)&(x))==0) |
| 55 | |
| 56 | /** Returns the lesser of its two arguments. */ |
Elliott Hughes | c2f082f | 2013-12-12 15:31:35 -0800 | [diff] [blame] | 57 | #define MIN(a,b) (((a)<(b))?(a):(b)) |
Elliott Hughes | dd6763a | 2018-10-04 16:35:13 -0700 | [diff] [blame^] | 58 | /** Returns the greater of its two arguments. */ |
Elliott Hughes | c2f082f | 2013-12-12 15:31:35 -0800 | [diff] [blame] | 59 | #define MAX(a,b) (((a)>(b))?(a):(b)) |