Advertisement

2 basic questions

Started by October 30, 2007 07:18 AM
0 comments, last by Null and Void 16 years, 11 months ago
2 basic questions: 1) is the a function in glibc to find out if a file is an executable ? 2) is it possible to store the gcc output (errors/warnings) in a file?
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".

This topic is closed to new replies.

Advertisement