Δημοσιεύτηκε: 21 Οκτ 2012, 21:10
Δε νομίζω ότι υπάρχει πρόβλημα στο άνοιγμα του αρχείου.
Για παράδειγμα, το παρακάτω κομμάτι κώδικα κάνει κάθε φορά append στο τέλος του αρχείου :
Για παράδειγμα, το παρακάτω κομμάτι κώδικα κάνει κάθε φορά append στο τέλος του αρχείου :
- Κώδικας: Επιλογή όλων
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
int fd;
char buffer[10];
buffer[0] = 'b';
buffer[1] = 'l';
buffer[2] = 'a';
buffer[3] = 'h';
buffer[4] = '\n';
fd = open(path_to_file , O_RDWR|O_CREAT|O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
if (fd == -1) {
printf("File not found.\n");
return -1;
}
write(fd, buffer, 5);
close(fd);
buffer[0] = '1';
buffer[1] = '2';
buffer[2] = '3';
buffer[3] = '4';
buffer[4] = '\n';
fd = open(path_to_file , O_RDWR|O_CREAT|O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
if (fd == -1) {
printf("File not found.\n");
return -1;
}
write(fd, buffer, 5);
close(fd);
}