blob: cb175637fe011b48b964392cad0807065b5698ea [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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 Hughes36f97ca2024-10-28 19:28:07 +000032#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 Project1dc9e472009-03-03 19:28:35 -080054
55#include <sys/cdefs.h>
56
Elliott Hughes9af74902016-11-29 18:06:34 -080057/* Historically bionic exposed the content of <float.h> from <limits.h> and <sys/limits.h> too. */
58#include <float.h>
59
Elliott Hughes36f97ca2024-10-28 19:28:07 +000060/* Many of the POSIX limits come from the kernel. */
Elliott Hughes9af74902016-11-29 18:06:34 -080061#include <linux/limits.h>
62
Elliott Hughesa4264a02025-03-25 08:32:31 -070063/** Maximum buffer size for getentropy(). */
64#define GETENTROPY_MAX 256
65
Elliott Hughes36f97ca2024-10-28 19:28:07 +000066/** Maximum number of positional arguments in a printf()/scanf() format string. */
67#define NL_ARGMAX 9
68/** Maximum number of bytes in a $LANG name. */
69#define NL_LANGMAX 14
70/** Irrelevant with Android's <nl_types.h>. */
71#define NL_MSGMAX 32767
72/** Obsolete; removed from POSIX. */
73#define NL_NMAX 1
74/** Irrelevant with Android's <nl_types.h>. */
75#define NL_SETMAX 255
76/** Irrelevant with Android's <nl_types.h>. */
77#define NL_TEXTMAX 255
78
79/** Obsolete; removed from POSIX. */
80#define PASS_MAX 128
81/** Obsolete; removed from POSIX. */
82#define TMP_MAX 308915776
83
84/** Number of bits in a `long` (POSIX). */
85#if __LP64__
86#define LONG_BIT 64
87#else
88#define LONG_BIT 32
89#endif
90/** Number of bits in a "word" of `int` (POSIX). */
Elliott Hughes19d76852017-10-18 13:27:01 -070091#define WORD_BIT 32
Elliott Hughes9af74902016-11-29 18:06:34 -080092
Elliott Hughes36f97ca2024-10-28 19:28:07 +000093/** Maximum value of a uid_t. */
94#define UID_MAX UINT_MAX
95/** Maximum value of a gid_t. */
96#define GID_MAX UINT_MAX
97/** Maximum value of a size_t. */
Elliott Hugheseae28492024-10-16 19:52:11 +000098#define SIZE_T_MAX ULONG_MAX
Elliott Hughes36f97ca2024-10-28 19:28:07 +000099/** Maximum value of a ssize_t. */
Elliott Hugheseae28492024-10-16 19:52:11 +0000100#define SSIZE_MAX LONG_MAX
Elliott Hugheseae28492024-10-16 19:52:11 +0000101
Elliott Hughes9bb08642025-01-28 07:29:11 -0800102/**
103 * POSIX 2024's name for NSIG.
104 * See the NSIG documentation for an explanation and warnings.
105 */
106#define NSIG_MAX 65
107
Elliott Hughes36f97ca2024-10-28 19:28:07 +0000108/** Maximum number of bytes in a multibyte character. */
Elliott Hughes69f05d22014-06-05 20:10:09 -0700109#define MB_LEN_MAX 4
Elliott Hughes1b0dc402014-04-01 17:16:59 -0700110
Elliott Hughes36f97ca2024-10-28 19:28:07 +0000111/** Default process priority. */
Elliott Hughes19d76852017-10-18 13:27:01 -0700112#define NZERO 20
113
Elliott Hughes36f97ca2024-10-28 19:28:07 +0000114/** Maximum number of struct iovec that can be passed in a single readv()/writev(). */
Elliott Hughesf2d7d412016-07-27 15:24:47 -0700115#define IOV_MAX 1024
Elliott Hughes36f97ca2024-10-28 19:28:07 +0000116
117/** Maximum value for a semaphore. */
Elliott Hughes04303f52014-09-18 16:11:59 -0700118#define SEM_VALUE_MAX 0x3fffffff
119
Elliott Hughesb266f652024-04-09 15:41:10 +0000120/** Do not use: prefer getline() or asprintf() rather than hard-coding an arbitrary size. */
121#define LINE_MAX _POSIX2_LINE_MAX
122
Elliott Hughesa186b2e2014-09-22 14:49:07 -0700123/* POSIX says these belong in <unistd.h> but BSD has some in <limits.h>. */
Elliott Hughes5704c422016-01-25 18:06:24 -0800124#include <bits/posix_limits.h>
Elliott Hughesa186b2e2014-09-22 14:49:07 -0700125
Elliott Hughes36f97ca2024-10-28 19:28:07 +0000126/** Maximum length of a hostname returned by gethostname(). */
Yongqin Liu05897772014-10-29 14:47:47 +0800127#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
Elliott Hughes36f97ca2024-10-28 19:28:07 +0000128
129/** Maximum length of a login name. */
Elliott Hughes06bd5862017-07-28 16:27:49 -0700130#define LOGIN_NAME_MAX 256
Elliott Hughes36f97ca2024-10-28 19:28:07 +0000131
132/** Maximum length of terminal device name. */
Elliott Hughes06bd5862017-07-28 16:27:49 -0700133#define TTY_NAME_MAX 32
Elliott Hughes9af74902016-11-29 18:06:34 -0800134
Elliott Hughes36f97ca2024-10-28 19:28:07 +0000135/** Maximum number of attempts to destroy thread-specific data when a thread exits. */
136#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS
Elliott Hughes7d3c6cd2024-04-18 22:02:38 +0000137
138/**
139 * The number of calls to pthread_key_create() without intervening calls to
140 * pthread_key_delete() that are guaranteed to succeed. See pthread_key_create()
141 * for more details and ways to avoid hitting this limit.
142 */
Elliott Hughes9af74902016-11-29 18:06:34 -0800143#define PTHREAD_KEYS_MAX 128
Elliott Hughes7d3c6cd2024-04-18 22:02:38 +0000144
Elliott Hughes36f97ca2024-10-28 19:28:07 +0000145/** bionic has no fixed limit on the number of threads. */
Elliott Hughes9af74902016-11-29 18:06:34 -0800146#undef PTHREAD_THREADS_MAX