ssize_t 在 Linux 中定义在哪里?

Cac*_*ito 17 c linux types posix include

操作系统:Debian 9 (Linux 4.9)

编译器:GCC 8.2

目前我包括<stddef.h>size_t定义在哪里)和<stdint.h>(定义了大多数整数类型),但我仍然没有ssize_t.

它在哪里定义?

And*_*nle 14

ssize_t中定义sys/types.h

根据POSIX 文档

姓名

sys/types.h - 数据类型

概要

#include <sys/types.h>
Run Code Online (Sandbox Code Playgroud)

描述

标题至少应定义以下类型:

...

ssize_t

    用于字节计数或错误指示。


Cac*_*ito 7

从版本 5.9 开始,Linux 手册页记录了系统数据类型,以便您可以轻松地集中找到这些信息。

\n

只需输入man ssize_t

\n
ssize_t(3type)      Linux Programmer\xe2\x80\x99s Manual     ssize_t(3type)\n\nNAME\n       ssize_t - count of bytes or an error indication\n\nLIBRARY\n       Standard C library (libc)\n\nSYNOPSIS\n       #include <sys/types.h>\n\n       typedef /* ... */ ssize_t;\n\nDESCRIPTION\n       Used  for  a  count of bytes or an error indication.  Ac\xe2\x80\x90\n       cording to POSIX, it shall be a signed integer type capa\xe2\x80\x90\n       ble  of  storing  values  at  least  in  the  range  [-1,\n       SSIZE_MAX],  and  the implementation shall support one or\n       more programming environments where the width of  ssize_t\n       is no greater than the width of the type long.\n\n       Glibc  and  most  other  implementations provide a length\n       modifier for ssize_t for the printf(3) and  the  scanf(3)\n       families  of functions, which is z; resulting commonly in\n       %zd or %zi for printing ssize_t values.  Although z works\n       for ssize_t on most implementations, portable POSIX  pro\xe2\x80\x90\n       grams  should  avoid  using it\xe2\x80\x94for example, by converting\n       the value to intmax_t and using its length modifier (j).\n\nVERSIONS\n       <aio.h>, <mqueue.h>,  and  <sys/socket.h>  define  ssize_t\n       since POSIX.1\xe2\x80\x902008.\n\nCONFORMING TO\n       POSIX.1\xe2\x80\x902001 and later.\n\nNOTES\n       The  following  headers  also provide this type: <aio.h>,\n       <monetary.h>,   <mqueue.h>,    <stdio.h>,    <sys/msg.h>,\n       <sys/socket.h>, <sys/uio.h>, and <unistd.h>.\n\nSEE ALSO\n       read(2),   readlink(2),   readv(2),   recv(2),   send(2),\n       write(2), ptrdiff_t(3type), size_t(3type)\n\nLinux                      2022\xe2\x80\x9006\xe2\x80\x9017             ssize_t(3type)\n
Run Code Online (Sandbox Code Playgroud)\n

如果您只是想要ssize_t,您应该包含它<sys/types.h>,这是它的规范标头,并且可能是提供的最轻的标头ssize_t。但是,它是由记录的任何标头提供的,因此如果您碰巧还需要在其他标头之一中定义,则可以仅包含该其他标头。

\n

  • 我使用的是 Ubuntu 20.04。`man ssize_t` 只是向我显示以下内容:`没有手动输入 ssize_t`。 (2认同)
  • 如果您有兴趣升级您的手册页(这是一个非常安全且可逆的操作),那么从源代码执行此操作很简单:`git clone git://git.kernel.org/pub/scm/docs/man- pages/man-pages.git &amp;&amp; cd man-pages &amp;&amp; make install`. 您可以“make uninstall”来恢复安装并恢复正常(您的系统手册页不会被覆盖,因为它使用“&lt;/usr/local/share/man/&gt;”进行安装)。只需按照自述文件进行操作即可。 (2认同)