• Advertisement
Sign in to follow this  

2 basic questions

This topic is 3829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Quote:
Original post by attahollander
1) is the a function in glibc to find out if a file is an executable ?

To find out if a file (or directory) has execute permissions would be stat.

#include <sys/stat.h>
#include <stdio.h>

int main(void) {
const char path[] = "/tmp/somefile";
struct stat buf;

if(stat(path, &buf)) {
printf("Error calling stat.\n");
return 1;
}

printf("%s is executable by:\n\tuser: %s\n\tgroup: %s\n\tothers: %s\n",
path,
(buf.st_mode & S_IXUSR) ? "yes" : "no",
(buf.st_mode & S_IXGRP) ? "yes" : "no",
(buf.st_mode & S_IXOTH) ? "yes" : "no");

return 0;
}




Quote:
Original post by attahollander
2) is it possible to store the gcc output (errors/warnings) in a file?

It depends on your shell, but most support redirection of the form "command &> /tmp/outputfile". You can also redirect just errors with "command 2> /tmp/outputfile".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement