Function declaration not seen

Hello,
I'm building neovim [1] on OS X 10.9.2 using clang from XCode 5.1, the
--version output is:
  > clang --version
  Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
  Target: x86_64-apple-darwin13.1.0
  Thread model: posix

When building the repo at the specific revision in [2] I'm getting the
following error when makefile tries to compile src/os/input.c:

### START OF PASTE
[ 95%] Building C object src/CMakeFiles/nvim.dir/os/input.c.o
cd /tmp/neovim-git/build/src && /usr/bin/cc -DHAVE_CONFIG_H -g
-I/opt/local/include -I/tmp/neovim-git/.deps/usr/include
-I/tmp/neovim-git/.deps/usr/include/luajit-2.0
-I/tmp/neovim-git/build/config -I/tmp/neovim-git/src
-I/tmp/neovim-git/src/proto -Werror -Wall -Wextra -pedantic
-Wno-unused-parameter -std=gnu99 -o CMakeFiles/nvim.dir/os/input.c.o
-c /tmp/neovim-git/src/os/input.c
/tmp/neovim-git/src/os/input.c:194:3: error: implicit declaration of
function 'settmode' is invalid in C99
[-Werror,-Wimplicit-function-declaration]
  settmode(TMODE_COOK);
  ^
/tmp/neovim-git/src/os/input.c:194:3: note: did you mean 'setmode'?
/usr/include/unistd.h:695:7: note: 'setmode' declared here
void *setmode(const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6,
__IPHONE_2_0, __DARWIN_ALIAS(setmode));
         ^
1 error generated.
make[3]: *** [src/CMakeFiles/nvim.dir/os/input.c.o] Error 1
make[2]: *** [src/CMakeFiles/nvim.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [nvim] Error 2
### END OF PASTE

Function void setterm(int) is correctly declared in src/term.h and
defined in src/term.c, also input.c is including src/term.h but if
-I/opt/local/include comes before -I/tmp/neovim-git/src clang cannot
see the setterm() declaration at all, also it suggest that it may be a
typo for seterm() in unistd.h instead.

If I move -I/opt/local/include after -I/tmp/neovim-git/src then
input.c source file is correctly compiled.

Is it correct for clang to not check in directories specified with
following -I args for an exact match for the function prototype?
Is the likeness of seterm() name tricking clang?

Best regards

[1] http://neovim.org/
[2] https://github.com/neovim/neovim/tree/54782ecf

Hello,
I'm building neovim [1] on OS X 10.9.2 using clang from XCode 5.1, the
--version output is:
  > clang --version
  Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
  Target: x86_64-apple-darwin13.1.0
  Thread model: posix

When building the repo at the specific revision in [2] I'm getting the
following error when makefile tries to compile src/os/input.c:

### START OF PASTE
[ 95%] Building C object src/CMakeFiles/nvim.dir/os/input.c.o
cd /tmp/neovim-git/build/src && /usr/bin/cc -DHAVE_CONFIG_H -g
-I/opt/local/include -I/tmp/neovim-git/.deps/usr/include
-I/tmp/neovim-git/.deps/usr/include/luajit-2.0
-I/tmp/neovim-git/build/config -I/tmp/neovim-git/src
-I/tmp/neovim-git/src/proto -Werror -Wall -Wextra -pedantic
-Wno-unused-parameter -std=gnu99 -o CMakeFiles/nvim.dir/os/input.c.o
-c /tmp/neovim-git/src/os/input.c
/tmp/neovim-git/src/os/input.c:194:3: error: implicit declaration of
function 'settmode' is invalid in C99
[-Werror,-Wimplicit-function-declaration]
  settmode(TMODE_COOK);
  ^
/tmp/neovim-git/src/os/input.c:194:3: note: did you mean 'setmode'?
/usr/include/unistd.h:695:7: note: 'setmode' declared here
void *setmode(const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6,
__IPHONE_2_0, __DARWIN_ALIAS(setmode));
         ^
1 error generated.
make[3]: *** [src/CMakeFiles/nvim.dir/os/input.c.o] Error 1
make[2]: *** [src/CMakeFiles/nvim.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [nvim] Error 2
### END OF PASTE

Function void setterm(int) is correctly declared in src/term.h and
defined in src/term.c, also input.c is including src/term.h but if
-I/opt/local/include comes before -I/tmp/neovim-git/src clang cannot
see the setterm() declaration at all, also it suggest that it may be a
typo for seterm() in unistd.h instead.

If I move -I/opt/local/include after -I/tmp/neovim-git/src then
input.c source file is correctly compiled.

Is it correct for clang to not check in directories specified with
following -I args for an exact match for the function prototype?
Is the likeness of seterm() name tricking clang?

If there's a term.h in /opt/local/include, and input.c says

  #include "term.h"

then it's correct for Clang to find that one. #include only includes one
file, not all files on all include paths with the specified name.

There is a term.h in /opt/local/include/ indeed, this was the most obvious
explanation and yet it didn't come to my mind.

Thanks for the heads-up.