Solved

executable file

Posted on 1998-11-05
6
196 Views
Last Modified: 2010-04-15
In a C program, How it is possible to know that a particular file is executable?
0
Comment
Question by:navin_agrawal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:MatthewL
ID: 1254063
Are you just interested in the actual file name or the file structure?

if filename then you could use command line arguments since the first argument is the filename.  Then you could use strtok or strstr to point to the "." and pull in the extension.

if structure, then my reference says that the first word of an executable file should be EXE program identifier.  It lists this value as being 5A4DH.  It's not clear to me if this is a sample value or always the case.

Matt
0
 
LVL 10

Expert Comment

by:rbr
ID: 1254064
It depends on your OS. Which OS do you use?
0
 
LVL 4

Expert Comment

by:siabod
ID: 1254065
That's always the case for a EXE
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:navin_agrawal
ID: 1254066
Let me be specific in telling the things. Following assumptions are made:

OS: Unix
File Name: /usr/home/stc/friend
Language: C

main ()
{
      char file_name[][] = "/usr/home/stc/friend"

      Here I want to know whether the file in file_name variable is executable or not. How to do this?
} /* end of mail () */
0
 
LVL 3

Expert Comment

by:braveheart
ID: 1254067
You'll have more luck posting in the UNIX Programming topic area.
0
 
LVL 10

Accepted Solution

by:
rbr earned 100 total points
ID: 1254068
#include <sys/stat.h>
#include <unistd.h>
main ()
{
char file_name[]="/usr/home/stc/friend"

struct stat stat_buf;

stat (file_name,&stat_buf);

if (stat_buf.st_mode & S_IXUSR)
printf ("Execute by user");
if (stat_buf.st_mode & S_IXGRP)
printf ("Execute by group");
if (stat_buf.st_mode & S_IXOTH)
printf ("Execute by others");
}

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question