Ça fonctionne pour moi si je donne à l'utilisateur les droits nécessaires sur le fichier:
int main (int argc, char *argv[])
{
const char filepath[] = "/tmp/toto.txt";
int fd1 = open(filepath, O_RDWR|O_CREAT,
S_IRUSR);
if(fd1 != -1) {
int fd2;
write(fd1, "Bonjour", 7);
if((fd2 = open(filepath, O_RDONLY)) != -1) {
char buf[12];
buf[read(fd2, buf, 7)] = 0;
printf("%s\n", buf);
close(fd2);
}
else printf("Impossible de reouvrir le fichier\n");
close(fd1);
remove(filepath);
}
else printf("Impossible d'ouvrir le fichier\n");
return 0;
}
C++ (@++)