Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does #define __REDIRECT_NTH do in unistd.h?

Tags:

c

unistd.h

GNU unistd.h has this bit of magic:

/* 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, __off64_t __offset, int __whence) __THROW;                                                              
#endif

What does __REDIRECT_NTH mean?

like image 981
vy32 Avatar asked Dec 19 '10 02:12

vy32


People also ask

What does the fox say Meaning?

Speaking of the meaning of the song, Vegard characterizes it as coming from "a genuine wonder of what the fox says, because we didn't know". Although interpreted by some commentators as a reference to the furry fandom, the brothers have stated they did not know about its existence when producing "The Fox".

How can I find a song by the sound?

On your phone, touch and hold the Home button or say "Hey Google." Ask "What's this song?" Play a song or hum, whistle, or sing the melody of a song. Hum, whistle, or sing: Google Assistant will identify potential matches for the song.

Is what does the fox say a book?

Now, the brothers have taken their fun lyrics and have paired them with Svein Nyhus's playful illustrations for a whole new take on the fox's unique way of speaking. What Does the Fox Say? is Ylvis's first picture book. Learn more at Ylvis.com.


2 Answers

More detail on what REDIRECT_NTH means: The macro generates a function declaration that tells the compiler to use a specific symbol for the function in the compiler's ELF output. By default, the compiler uses the ELF symbol "lseek" for a C function named "lseek" (or, on some systems, "_lseek"). This macro expands to code that tells the compiler to use the symbol "lseek64" instead. So the C code has a function named "lseek", but when you look in the object code (e.g. with program 'nm'), you see "lseek64".

The purpose of that is that the function really is lseek64 at a binary level - it deals in 64 bit file offsets. But the source code has declared that it wants to call it lseek, for backward source compatibility reasons (that's what _FILE_OFFSET_BITS=64 says).

If the source program wants to call lseek64 by that name, and have lseek refer to the old 32 bit version, it must define _LARGEFILE64_SOURCE and not _FILE_OFFSET_BITS=64.

By the way, the "NTH" in "REDIRECT_NTH" refers to "no throw," which is an attribute of the function declaration the macro generates.

like image 191
giraffedata Avatar answered Oct 27 '22 04:10

giraffedata


It is a macro in the namespace reserved to the implementation. It only appears on your platform; it does whatever is appropriate on your platform because the implementation decided it is correct.

If you can't find out easily, you probably shouldn't be using it directly. Even if you can find out, there's a good chance you should not be using it directly.

That said, it looks as though it arranges for calls to lseek() to be translated to lseek64(), presumably to provide support for large files (bigger than 2 GiB) on 32-bit machines (or under the 32-bit system API on your 64-bit machine).

like image 42
Jonathan Leffler Avatar answered Oct 27 '22 04:10

Jonathan Leffler