i want to write a code which determines whether a file is executable or relocatable.....i have try this code but its now working ...


#include<stdio.h>
#include<elf.h>
int main()
{
int fd;
elf32_ehdr myhdr;
fd=open("abc.c");
if (myhdr.e_type==ET_RELl)
{
printf(:relocatable");
if (myhdr.e_type==ET_EXEC)
printf(executable");


else
printf(:other type");

return(0);
}

>>fd=open("abc.c");

That file is neither object file or executable file. Its a C script file. On MS-Windows you can easily tell the difference between object and executable by its file extension. On *nix executable files do not normally have extensions, but you can identify them by the file permissions mask. And with that you would not know the difference between a compiled executable program or a shell script, which is just a text file.