糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > linux stat函数源码 glibc源码分析之stat系列函数

linux stat函数源码 glibc源码分析之stat系列函数

时间:2021-03-22 15:53:01

相关推荐

linux stat函数源码 glibc源码分析之stat系列函数

glibc中stat系列函数有stat,fstat,lstat。它们都是系统调用的封装函数。

关于stat的系统调用有oldstat(18),oldfstat(28),oldlstat(84),stat(106),lstat(107),fstat(108),stat64(195),lstat64(196),fstat64(197)。oldstat系列系统调用被stat系列系统调用替代了。stat系列系统调用用于获取文件属性,文件属性为32位,而stat64系列系统调用则用于获取文件属性,文件属性是64位。所以stat系列系统调用不能获取长度超过32位的文件的属性。

stat,fstat,lstat函数在封装是都是使用stat64系列系统调用,而不是使用stat系列系统调用。

查看stat函数的源码:

#undef stat

int

attribute_hidden

__stat (const char *file, struct stat *buf)

{

return __xstat (_STAT_VER, file, buf);

}

weak_hidden_alias (__stat, stat)

函数__stat调用了__xstat 函数。而__xstat 函数定义在sysdeps/unix/sysv/linux/i386/xstat.c文件中。

int

__xstat (int vers, const char *name, struct stat *buf)

{

int result;

if (vers == _STAT_VER_KERNEL)

return INLINE_SYSCALL (stat, 2, name, buf);

{

struct stat64 buf64;

INTERNAL_SYSCALL_DECL (err);

result = INTERNAL_SYSCALL (stat64, err, 2, name, &buf64);

if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result, err)))

return INLINE_SYSCALL_ERROR_RETURN_VALUE (INTERNAL_SYSCALL_ERRNO (result,

err));

else

return __xstat32_conv (vers, &buf64, buf);

}

}

hidden_def (__xstat)

w

如果觉得《linux stat函数源码 glibc源码分析之stat系列函数》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。