Debian Codegraph @

listings/chapter-8/write_journal_entry.c

raw
1 /***********************************************************************
2 * Code listing from "Advanced Linux Programming," by CodeSourcery LLC *
3 * Copyright (C) 2001 by New Riders Publishing *
4 * See COPYRIGHT for license information. *
5 ***********************************************************************/
6
7 #include <fcntl.h>
8 #include <string.h>
9 #include <sys/stat.h>
10 #include <sys/types.h>
11 #include <unistd.h>
12
13 const char* journal_filename = "journal.log";
14
15 void write_journal_entry (char* entry)
16 {
17 int fd = open (journal_filename, O_WRONLY | O_CREAT | O_APPEND, 0660);
18 write (fd, entry, strlen (entry));
19 write (fd, "\n", 1);
20 fsync (fd);
21 close (fd);
22 }