加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

#define __REDIRECT_NTH在unistd.h中做了什么?

发布时间:2020-12-16 09:31:22 所属栏目:百科 来源:网络整理
导读:GNU unistd.h有一点魔力: /* Move FD's file position to OFFSET bytes from the beginning of the file (if WHENCE is SEEK_SET),the current position (if WHENCE is SEEK_CUR),or the end of the file (if WHENCE is SEEK_END). Return the new file pos
GNU unistd.h有一点魔力:

/* Move FD's file position to OFFSET bytes from the
   beginning of the file (if WHENCE is SEEK_SET),the current position (if WHENCE is SEEK_CUR),or the end of the file (if WHENCE is SEEK_END).
   Return the new file position.  */
#ifndef __USE_FILE_OFFSET64
extern __off_t lseek (int __fd,__off_t __offset,int __whence) __THROW;                                                                    
#else
# ifdef __REDIRECT_NTH
extern __off64_t __REDIRECT_NTH (lseek,(int __fd,__off64_t __offset,int __whence),lseek64);                                                                                                    
# else
#  define lseek lseek64
# endif
#endif
#ifdef __USE_LARGEFILE64
extern __off64_t lseek64 (int __fd,int __whence) __THROW;                                                              
#endif

__REDIRECT_NTH是什么意思?

解决方法

有关REDIRECT_NTH含义的更多细节:宏生成一个函数声明,告诉编译器在编译器的ELF输出中使用该函数的特定符号.默认情况下,编译器将ELF符号“lseek”用于名为“lseek”的C函数(或者,在某些系统上使用“_lseek”).此宏扩展为代码,告诉编译器使用符号“lseek64”.所以C代码有一个名为“lseek”的函数,但是当你查看目标代码时(例如用程序’nm’),你会看到“lseek64”.

这样做的目的是该函数在二进制级别确实是lseek64 – 它处理64位文件偏移.但是源代码已声明它想要将其称为lseek,因为后向源兼容性原因(这就是_FILE_OFFSET_BITS = 64所说的).

如果源程序想要通过该名称调用lseek64,并且让lseek引用旧的32位版本,则它必须定义_LARGEFILE64_SOURCE而不是_FILE_OFFSET_BITS = 64.

顺便说一句,“REDIRECT_NTH”中的“NTH”指的是“no throw”,它是宏生成的函数声明的属性.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读