ssize_t in C?
I previously covered the
size_t type in C, which is used to represent the size of an allocated block of memory. But lots of C functions use a type called
ssize_t. What’s that? What is the extra
ssize_t is the same as
size_t, but is a signed type - read
ssize_t as “signed
ssize_t is able to represent the number
-1, which is returned by several system calls and library functions as a way to indicate error. For example, the
write system calls:
#include <sys/types.h> #include <unistd.h> ssize_t read(int fildes, void *buf, size_t nbyte); ssize_t write(int fildes, const void *buf, size_t nbyte);
I wrote this because I felt like it. This post is not associated with my employer.