I'm writing a shell program for a CS class which needs to implement output redirection by messing around with the file descriptor table like this:
fid = open("output", O_CREAT|O_WRONLY);
close(1); //stdout
dup(fid);
close(fid);
For some reason this will create the file and not write anything to it, but if I execute the program using sudo it functions correctly. Is this some screwy thing having to do with UNIX and permissions or is there something wrong with the program itself?