HelloI am trying to figure out why I am getting an error (-1) when tryingto write to a file.
Hereis the function - I did not include the rest of the code - not sureif I am leaving anything else out - I assumed it was a writepermission issue?
Code:
#defineDATAFILE "/var/chance.data" //File to store userdata
voidregister_new_player() { int fd;
printf("-=-={New Player Registration } =-=-\n");
printf("Enteryour name: ");
input_name();
player.uid= getuid();
player.highscore= player.credits = 100;
fd= open(DATAFILE, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR);
if(fd= -1)
fatal("in register_new_player() while opening file");
write(fd,&player, sizeof(struct user));
close(fd);
printf("\nWelcometo the Game of Chance %s\n", player.name);
printf("Youhave been given %u credits.\n", player.credits);
}
Hereare my file/folder Permissions
PHP Code:
folder:/var:rwxrwxrwt root:root
file:/var/chance.data:-rwxrw---- root:user
Imodified the permission for chance.data manually in attempt tofix.
originalpermissions
PHP Code:
-rw-------root:user
PHP Code:
./game_of_chance:rwsrwxr-x root:root
game_of_chance.c:-rw-rw-r-- user:user
Result
Code:
user@ubuntu:~/examples$./game_of_chance
-=-={New Player Registration } =-=-
Enteryour name: test
[!!]Fatal Error in register_new_player() while opening file:Success
user@ubuntu:~/examples$