LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-11-2004, 06:24 PM   #1
jdruin
Member
 
Registered: Jul 2003
Location: Louisville aka Derby City
Distribution: WinXP SP2 and SP3, W2K Server, Ubuntu
Posts: 313

Rep: Reputation: 30
How do i know which .h file the compiler is using?


I am trying to learn Linux by looking at source code and writing some of my own. Thank goodness its open source. Anyway, Iwant to knwo where the .h and .c files are located. For example, to find unistd.h, I did a

find / -name unistd.h

The shell responded with:

/usr/lib/bcc/include/bsd/unistd.h
/usr/lib/bcc/include/unistd.h
/usr/lib/dietlibc/include/unistd.h
/usr/lib/bcc/include/bsd/unistd.h
/usr/lib/bcc/include/unistd.h
/usr/lib/dietlibc/include/unistd.hfind: /usr/share/ssl/CA: Permission denied
/usr/include/asm/unistd.h
/usr/include/linux/unistd.h
/usr/include/sys/unistd.h
/usr/include/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-alpha/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-arm/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-cris/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-i386/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-ia64/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-m68k/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-mips/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-mips64/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-parisc/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-ppc/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-ppc64/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-s390/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-s390x/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-sh/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-sparc/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-sparc64/unistd.h
/usr/src/linux-2.4.20-31.9/include/asm-x86_64/unistd.h
/usr/src/linux-2.4.20-31.9/include/linux/unistd.h


There are too many answers for me to know which is the file being used when I run the code

#include <unistd.h>

How do I know which file is being used?
 
Old 11-11-2004, 07:01 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Unless you have a horribly mutated installation, the preprocessor grabs the files from /usr/include/ (e.g. #include <stdio.h> is the same as #include "/usr/include/stdio.h")
 
Old 11-11-2004, 07:22 PM   #3
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
You can also use -v on the gcc command line to see what it's using... mine says this:
Quote:
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc-lib/i486-linux/3.3.4/include
/usr/include
(You have to hunt for this output among the rest of the stuff it prints out). The file it loads will be the first one it finds looking through those directories in order.
 
Old 11-11-2004, 07:36 PM   #4
jdruin
Member
 
Registered: Jul 2003
Location: Louisville aka Derby City
Distribution: WinXP SP2 and SP3, W2K Server, Ubuntu
Posts: 313

Original Poster
Rep: Reputation: 30
Thanks!

Mine output

#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/include
/usr/include

Does this mean it used the file in /usr/local/include ?
 
Old 11-11-2004, 08:01 PM   #5
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
If and only if there is a file called unistd.h in that directory. Otherwise it will look in each directory until it finds one. You should be suspicious of any unistd.h file in either of those first two directories.
 
Old 11-12-2004, 06:57 AM   #6
jdruin
Member
 
Registered: Jul 2003
Location: Louisville aka Derby City
Distribution: WinXP SP2 and SP3, W2K Server, Ubuntu
Posts: 313

Original Poster
Rep: Reputation: 30
<quote>You should be suspicious of any unistd.h file in either of those first two directories.</quote>

Why would I be suspicious?
 
Old 11-12-2004, 04:11 PM   #7
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Because a file as basic as unistd would usually be in /usr/include, and if there was a copy in one of those other directories, it would be used first, and could potentially contain exploit code. It would be a strange form of attack, and quite unlikely (I think), but possible. Many projects you might compile from source would make use of unistd.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
checking for C compiler default output... configure: error: C compiler cannot create fiorejm Linux - Software 6 11-12-2009 12:35 PM
changing compiler for a software in configure file cdsnithi Linux - Software 1 06-27-2005 02:35 PM
Compiler conundrum: Which came first, a compiler, or it's source code? fr0zen Programming 21 01-29-2004 04:31 AM
large file support compiler with other tools!? chuanyung Programming 0 01-20-2004 03:51 AM
GNU libc installation to setup cross compiler env - kernel header file TOO OLD !! tanch00 Linux - Software 1 02-06-2002 02:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration