The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1988 The Regents of the University of California. |
| 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 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. Neither the name of the University nor the names of its contributors |
| 14 | * may be used to endorse or promote products derived from this software |
| 15 | * without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | * |
| 29 | * @(#)limits.h 5.9 (Berkeley) 4/3/91 |
| 30 | */ |
| 31 | |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 32 | #pragma once |
| 33 | |
| 34 | /** |
| 35 | * @file limits.h |
| 36 | * @brief Constants relating to implementation limits. |
| 37 | * |
| 38 | * This file is included via `#include_next` from the clang header of the same |
| 39 | * name that provides all the limits that the compiler is responsible for, |
| 40 | * primarily those relating to integer types defined by the C standard. |
| 41 | * This file defines the additional limits defined by POSIX. |
| 42 | */ |
| 43 | |
| 44 | /* |
| 45 | * The Android build system has bionic _before_ the clang headers, |
| 46 | * so although the claim above that clang does an `#include_next` |
| 47 | * of this file is true for the NDK, it's not true for the OS, |
| 48 | * and we need to paper over that difference here until/unless |
| 49 | * the OS build changes. |
| 50 | */ |
| 51 | #if __has_include_next(<limits.h>) |
| 52 | #include_next <limits.h> |
| 53 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 54 | |
| 55 | #include <sys/cdefs.h> |
| 56 | |
Elliott Hughes | 9af7490 | 2016-11-29 18:06:34 -0800 | [diff] [blame] | 57 | /* Historically bionic exposed the content of <float.h> from <limits.h> and <sys/limits.h> too. */ |
| 58 | #include <float.h> |
| 59 | |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 60 | /* Many of the POSIX limits come from the kernel. */ |
Elliott Hughes | 9af7490 | 2016-11-29 18:06:34 -0800 | [diff] [blame] | 61 | #include <linux/limits.h> |
| 62 | |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 63 | /* |
| 64 | * bionic always exposed these alternative names, |
| 65 | * but clang's <limits.h> considers them GNU extensions, |
| 66 | * and may or may not have defined them. |
| 67 | */ |
| 68 | #ifndef LONG_LONG_MIN |
| 69 | /** Non-portable synonym; use LLONG_MIN directly instead. */ |
| 70 | #define LONG_LONG_MIN LLONG_MIN |
Elliott Hughes | 47eb527 | 2024-10-15 19:57:00 +0000 | [diff] [blame] | 71 | #endif |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 72 | #ifndef LONG_LONG_MAX |
| 73 | /** Non-portable synonym; use LLONG_MAX directly instead. */ |
| 74 | #define LONG_LONG_MAX LLONG_MAX |
| 75 | #endif |
| 76 | #ifndef ULONG_LONG_MAX |
| 77 | /** Non-portable synonym; use ULLONG_MAX directly instead. */ |
| 78 | #define ULONG_LONG_MAX ULLONG_MAX |
| 79 | #endif |
| 80 | |
| 81 | /** Maximum number of positional arguments in a printf()/scanf() format string. */ |
| 82 | #define NL_ARGMAX 9 |
| 83 | /** Maximum number of bytes in a $LANG name. */ |
| 84 | #define NL_LANGMAX 14 |
| 85 | /** Irrelevant with Android's <nl_types.h>. */ |
| 86 | #define NL_MSGMAX 32767 |
| 87 | /** Obsolete; removed from POSIX. */ |
| 88 | #define NL_NMAX 1 |
| 89 | /** Irrelevant with Android's <nl_types.h>. */ |
| 90 | #define NL_SETMAX 255 |
| 91 | /** Irrelevant with Android's <nl_types.h>. */ |
| 92 | #define NL_TEXTMAX 255 |
| 93 | |
| 94 | /** Obsolete; removed from POSIX. */ |
| 95 | #define PASS_MAX 128 |
| 96 | /** Obsolete; removed from POSIX. */ |
| 97 | #define TMP_MAX 308915776 |
| 98 | |
| 99 | /** Number of bits in a `long` (POSIX). */ |
| 100 | #if __LP64__ |
| 101 | #define LONG_BIT 64 |
| 102 | #else |
| 103 | #define LONG_BIT 32 |
| 104 | #endif |
| 105 | /** Number of bits in a "word" of `int` (POSIX). */ |
Elliott Hughes | 19d7685 | 2017-10-18 13:27:01 -0700 | [diff] [blame] | 106 | #define WORD_BIT 32 |
Elliott Hughes | 9af7490 | 2016-11-29 18:06:34 -0800 | [diff] [blame] | 107 | |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 108 | /** Maximum value of a uid_t. */ |
| 109 | #define UID_MAX UINT_MAX |
| 110 | /** Maximum value of a gid_t. */ |
| 111 | #define GID_MAX UINT_MAX |
| 112 | /** Maximum value of a size_t. */ |
Elliott Hughes | eae2849 | 2024-10-16 19:52:11 +0000 | [diff] [blame] | 113 | #define SIZE_T_MAX ULONG_MAX |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 114 | /** Maximum value of a ssize_t. */ |
Elliott Hughes | eae2849 | 2024-10-16 19:52:11 +0000 | [diff] [blame] | 115 | #define SSIZE_MAX LONG_MAX |
Elliott Hughes | eae2849 | 2024-10-16 19:52:11 +0000 | [diff] [blame] | 116 | |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 117 | /** Maximum number of bytes in a multibyte character. */ |
Elliott Hughes | 69f05d2 | 2014-06-05 20:10:09 -0700 | [diff] [blame] | 118 | #define MB_LEN_MAX 4 |
Elliott Hughes | 1b0dc40 | 2014-04-01 17:16:59 -0700 | [diff] [blame] | 119 | |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 120 | /** Default process priority. */ |
Elliott Hughes | 19d7685 | 2017-10-18 13:27:01 -0700 | [diff] [blame] | 121 | #define NZERO 20 |
| 122 | |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 123 | /** Maximum number of struct iovec that can be passed in a single readv()/writev(). */ |
Elliott Hughes | f2d7d41 | 2016-07-27 15:24:47 -0700 | [diff] [blame] | 124 | #define IOV_MAX 1024 |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 125 | |
| 126 | /** Maximum value for a semaphore. */ |
Elliott Hughes | 04303f5 | 2014-09-18 16:11:59 -0700 | [diff] [blame] | 127 | #define SEM_VALUE_MAX 0x3fffffff |
| 128 | |
Elliott Hughes | b266f65 | 2024-04-09 15:41:10 +0000 | [diff] [blame] | 129 | /** Do not use: prefer getline() or asprintf() rather than hard-coding an arbitrary size. */ |
| 130 | #define LINE_MAX _POSIX2_LINE_MAX |
| 131 | |
Elliott Hughes | a186b2e | 2014-09-22 14:49:07 -0700 | [diff] [blame] | 132 | /* POSIX says these belong in <unistd.h> but BSD has some in <limits.h>. */ |
Elliott Hughes | 5704c42 | 2016-01-25 18:06:24 -0800 | [diff] [blame] | 133 | #include <bits/posix_limits.h> |
Elliott Hughes | a186b2e | 2014-09-22 14:49:07 -0700 | [diff] [blame] | 134 | |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 135 | /** Maximum length of a hostname returned by gethostname(). */ |
Yongqin Liu | 0589777 | 2014-10-29 14:47:47 +0800 | [diff] [blame] | 136 | #define HOST_NAME_MAX _POSIX_HOST_NAME_MAX |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 137 | |
| 138 | /** Maximum length of a login name. */ |
Elliott Hughes | 06bd586 | 2017-07-28 16:27:49 -0700 | [diff] [blame] | 139 | #define LOGIN_NAME_MAX 256 |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 140 | |
| 141 | /** Maximum length of terminal device name. */ |
Elliott Hughes | 06bd586 | 2017-07-28 16:27:49 -0700 | [diff] [blame] | 142 | #define TTY_NAME_MAX 32 |
Elliott Hughes | 9af7490 | 2016-11-29 18:06:34 -0800 | [diff] [blame] | 143 | |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 144 | /** Maximum number of attempts to destroy thread-specific data when a thread exits. */ |
| 145 | #define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS |
Elliott Hughes | 7d3c6cd | 2024-04-18 22:02:38 +0000 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * The number of calls to pthread_key_create() without intervening calls to |
| 149 | * pthread_key_delete() that are guaranteed to succeed. See pthread_key_create() |
| 150 | * for more details and ways to avoid hitting this limit. |
| 151 | */ |
Elliott Hughes | 9af7490 | 2016-11-29 18:06:34 -0800 | [diff] [blame] | 152 | #define PTHREAD_KEYS_MAX 128 |
Elliott Hughes | 7d3c6cd | 2024-04-18 22:02:38 +0000 | [diff] [blame] | 153 | |
Elliott Hughes | 36f97ca | 2024-10-28 19:28:07 +0000 | [diff] [blame] | 154 | /** bionic has no fixed limit on the number of threads. */ |
Elliott Hughes | 9af7490 | 2016-11-29 18:06:34 -0800 | [diff] [blame] | 155 | #undef PTHREAD_THREADS_MAX |