Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void append_to_file(char *filename, char *line, size_t len)
- {
- off_t off;
- int written, closed;
- int fd = open(filename, O_RDWR);
- if (fd == -1) {
- printf("Error opening file: %s\n", filename);
- printf("Error: %s\n", strerror(errno));
- return;
- }
- off = lseek(fd, 0, SEEK_END);
- if (off == -1) {
- printf("Error seeking file: %s\n", filename);
- printf("Error: %s\n", strerror(errno));
- close(fd);
- return;
- }
- written = write(fd, line, len);
- if (written == -1) {
- printf("Error writing to file: %s\n", filename);
- printf("Error: %s\n", strerror(errno));
- }
- closed = close(fd);
- if (closed == -1) {
- printf("Error closing file: %s\n", filename);
- printf("Error: %s\n", strerror(errno));
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement