Where is ssize_t defined in Linux?
Since version 5.9, the Linux man-pages document system data types, so that you can find this information easily in a centralized manner.
Just type man ssize_t
:
ssize_t(3type) Linux Programmer’s Manual ssize_t(3type)
NAME
ssize_t - count of bytes or an error indication
LIBRARY
Standard C library (libc)
SYNOPSIS
#include <sys/types.h>
typedef /* ... */ ssize_t;
DESCRIPTION
Used for a count of bytes or an error indication. Ac‐
cording to POSIX, it shall be a signed integer type capa‐
ble of storing values at least in the range [-1,
SSIZE_MAX], and the implementation shall support one or
more programming environments where the width of ssize_t
is no greater than the width of the type long.
Glibc and most other implementations provide a length
modifier for ssize_t for the printf(3) and the scanf(3)
families of functions, which is z; resulting commonly in
%zd or %zi for printing ssize_t values. Although z works
for ssize_t on most implementations, portable POSIX pro‐
grams should avoid using it—for example, by converting
the value to intmax_t and using its length modifier (j).
VERSIONS
<aio.h>, <mqueue.h>, and <sys/socket.h> define ssize_t
since POSIX.1‐2008.
CONFORMING TO
POSIX.1‐2001 and later.
NOTES
The following headers also provide this type: <aio.h>,
<monetary.h>, <mqueue.h>, <stdio.h>, <sys/msg.h>,
<sys/socket.h>, <sys/uio.h>, and <unistd.h>.
SEE ALSO
read(2), readlink(2), readv(2), recv(2), send(2),
write(2), ptrdiff_t(3type), size_t(3type)
Linux 2022‐06‐17 ssize_t(3type)
If you just want ssize_t
, you should include <sys/types.h>
, which is its canonical header, and probably the lightest one that provides ssize_t
. However, it is provided by any of the headers documented, so if you happen to also need a definition in one of those other headers, you can include that other header only.
ssize_t
is defined in sys/types.h
.
Per the POSIX documentation:
NAME
sys/types.h - data types
SYNOPSIS
#include <sys/types.h>
DESCRIPTION
The header shall define at least the following types:
...
ssize_t
Used for a count of bytes or an error indication.