🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

2 basic questions

Started by
0 comments, last by Null and Void 16 years, 8 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?
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".

This topic is closed to new replies.

Advertisement