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
Solved

executable file

Posted on 1998-11-05
6
194 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

860 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