dont append to the end but seek END:VCALENDAR
This commit is contained in:
parent
3cab08dbf3
commit
72dbf969f5
@ -21,11 +21,6 @@ main.o: main.c
|
|||||||
all:
|
all:
|
||||||
gcc -Wall *.c
|
gcc -Wall *.c
|
||||||
|
|
||||||
.PHONY:debug
|
|
||||||
debug:
|
|
||||||
gcc -Wall -g *.c
|
|
||||||
gdb a.out
|
|
||||||
|
|
||||||
.PHONY:run
|
.PHONY:run
|
||||||
run:
|
run:
|
||||||
gcc -Wall *.c
|
gcc -Wall *.c
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
void insert_event(char *file_name) {
|
void insert_event(char *file_name) {
|
||||||
int myfd = open(file_name, O_APPEND | O_WRONLY);
|
int myfd = open(file_name, O_RDWR);
|
||||||
|
|
||||||
char summary_buf[256] = "SUMMARY:";
|
char summary_buf[256] = "SUMMARY:";
|
||||||
|
|
||||||
@ -24,10 +24,34 @@ void insert_event(char *file_name) {
|
|||||||
summary_buf[strlen(summary_buf)-1] = '\r';
|
summary_buf[strlen(summary_buf)-1] = '\r';
|
||||||
summary_buf[strlen(summary_buf)] = '\n';
|
summary_buf[strlen(summary_buf)] = '\n';
|
||||||
|
|
||||||
|
seek_cal_end(myfd);
|
||||||
write(myfd, "BEGIN:VEVENT\r\n", strlen("BEGIN:VEVENT\r\n"));
|
write(myfd, "BEGIN:VEVENT\r\n", strlen("BEGIN:VEVENT\r\n"));
|
||||||
write(myfd, summary_buf, strlen(summary_buf));
|
write(myfd, summary_buf, strlen(summary_buf));
|
||||||
|
write(myfd, "END:VCALENDAR\r\n", strlen("END:VCALENDAR\r\n"));
|
||||||
|
|
||||||
close(myfd);
|
close(myfd);
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void seek_cal_end(int fd) {
|
||||||
|
char search_string[] = "END:VCALENDAR";
|
||||||
|
int j = 0;
|
||||||
|
char char_reader = '\0';
|
||||||
|
|
||||||
|
lseek(fd, -1, SEEK_END);
|
||||||
|
|
||||||
|
while(read(fd, &char_reader, 1)) {
|
||||||
|
// no need to compare to the null terminator of the search_string
|
||||||
|
if (char_reader == search_string[strlen(search_string)-j-1]) {
|
||||||
|
j++;
|
||||||
|
} else {
|
||||||
|
j = 0;
|
||||||
|
}
|
||||||
|
if (j == (strlen(search_string))) {
|
||||||
|
lseek(fd, -1, SEEK_CUR);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
lseek(fd, -2, SEEK_CUR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void insert_event(char *file_name);
|
void insert_event(char *file_name);
|
||||||
|
void seek_cal_end(int fd);
|
||||||
|
Loading…
Reference in New Issue
Block a user