ssize_t与size_t的区别: http://bbs.edu118.com/forum.php?mod=viewthread&tid=547&fromuid=231
跟踪linux源码得到以下宏:
#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
在不同平台上,其具有不同的定义:
/* sparc 64 bit */
typedef unsigned long __kernel_size_t;
typedef long __kernel_ssize_t;
/* sparc 32 bit */
typedef unsigned int __kernel_size_t;
typedef int __kernel_ssize_t;
这就是两个类型的实际定义,从字面上意思来说:
Ssize_t = signed size_t
使用位置:
在对于缓冲区大小等等非负值的长度时一般使用 size_t;
而对于像
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);
可能失败返回< 0的函数时,则使用ssize_t;
ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
另外相似的一个类型: loff_t
定义如下:
#if defined(__GNUC__)
typedef __kernel_loff_t loff_t;
#endif
是一个long long 类型
#ifdef __GNUC__
typedef long long __kernel_loff_t;
#endif
|