fcntl.h options and values

the following code should write the values of the AND and OR values of the fcntl.h options. It compiles, but won't create an ./a.out file instead it creates an "fcntl.h.gch" file in the directory inwhich the file is saved and is apparently a write only file since I can't open because I dont "have the permissions to access the file". Anybody who could shed some light on this for me would be greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <fcntl.h>

void display_flags(char *, unsigned int);
void binary_print(unsigned int);

int main(int argc, char *argv[])
	 {
	display_flags("O_RDONLY\t\t", O_RDONLY);
	display_flags("O_WRONLY\t\t", O_WRONLY);
	display_flags("O_RDWR\t\t\t", O_RDWR);
	printf("\n");
	display_flags("O_APPEND\t\t", O_APPEND);
	display_flags("O_TRUNC\t\t\t", O_TRUNC);
	display_flags("O_CREAT\t\t\t", O_CREAT);
	printf("\n");
	display_flags("O_WRONLY | O_APPEND | O_CREAT", O_WRONLY | O_APPEND | O_CREAT);
	}

void display_flags(char *label, unsigned int value)
	 {
	printf("%s\t: %d\t:", label, value);
	binary_print(value);
	printf("\n");
	}
void binary_print(unsigned int value)
	 {
	unsigned int mask = 0xff000000;	//start with a mask for the highest byte.
	unsigned int shift = 256*256*256;	//start with a shift for the highest byte.
	unsigned int byte, byte_iterator, bit_iterator;
	
	for(byte_iterator = 0; byte_iterator < 4; byte_iterator++) {
		byte = (value & mask) / shift;	//Isolate each byte
		printf(" ");
		for(bit_iterator = 0; bit_iterator < 8; bit_iterator++) {	//print the bits bytes
			if(byte & 0x80)	//if the highest bit in the byte isnt 0,
				printf("1");	//Print a 1
			else
				printf("0");	//otherwise, print a 0
			byte *= 2;		//move all the bits to the left by 1.
		}
		mask /= 256;		//move bits in mask right by 8
		shift /= 256;		//move bits in shift right by 8
	}
}
you probably do not have write (and/or execute) permissions
in the directory where you are compiling.

You probably do not know unix very well.

Try studying the manual pages of the chmod command

Actually I had accidentally saved the file as a .h and compiled it as such. thus creating the fcntl.H.GCH, and I suppose if you were so proficient in Linux you would have noticed this file format as well huh?

But yes, I had previously don all the chmod and chown commands to make sure had access to this file prior to posting it here.
Topic archived. No new replies allowed.