Solved

executable file

Posted on 1998-11-05
6
187 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
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
New! My Passport Wireless Pro Wi-Fi Mobile Storage

Portable wireless storage to offload, edit, and stream anywhere.

High-capacity, wireless mobile storage designed to accompany professional photographers and videographers in the field to easily offload, edit and stream captured photos and high-definition videos.

 

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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 and use switch statements in the C programming language.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now