Ssize_t and size_t
Track the Linux source code to get the following macros:
# Ifndef _ size_t
# DEFINE _ size_t
Typedef _ kernel_size_t size_t;
# Endif
# Ifndef _ ssize_t
# DEFINE _ ssize_t
Typedef _ kernel_ssize_t ssize_t;
# Endif
Different platforms have different definitions:
/* 64-bit */
Typedef unsigned long _ kernel_size_t;
Typedef long _ kernel_ssize_t;
/* Linux 32 bit */
Typedef unsigned int _ kernel_size_t;
Typedef int _ kernel_ssize_t;
This is the actual definition of two types, literally:
Ssize_t = signed size_t
Usage location:
Size_t is generally used for the length of non-negative values such as the buffer size;
For Image
Ssize_t (* read) (struct file *, char _ User *, size_t, loff_t *);
Ssize_t (* write) (struct file *, const char _ User *, size_t, loff_t *);
Ssize_t (* aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t );
Ssize_t (* aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t );
If the <0 function is returned for failure, ssize_t is used;
Ssize_t (* read) (struct file *, char _ User *, size_t, loff_t *);
Another similar type: loff_t
Definition:
# If defined (_ gnuc __)
Typedef _ kernel_loff_t loff_t;
# Endif
Is a long type.
# Ifdef _ gnuc __
Typedef long _ kernel_loff_t;
# Endif
More: http://blog.csdn.net/lalor/article/details/7426184
Size_t and ssize_t