Hi ,
could you plese advise ,I have some problem with the ssize_t sendfile function.
ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);
the error:
Lesson_4_1A_Home_work.c:84:24: error: expected declaration specifiers or ... before string constant
Lesson_4_1A_Home_work.c:84:37: error: expected declaration specifiers or ... before string constant
Lesson_4_1A_Home_work.c:84:63: error: expected declaration specifiers or ... before strlen
Code:
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <sys/sendfile.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h> //used for exit()
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <error.h>
//prototypes
/*******************************************************************************/
int main()
{
#define WorkPATH "//home//ilan/Embedded_linux//Lesson-4_IO_Routines_and_File_descriptors//Home_work//My_solution//a.txt"
#define NewWorkPATH "//home//ilan/Embedded_linux//Lesson-4_IO_Routines_and_File_descriptors//Home_work//My_solution//NEWa.txt"
int fd,length=0;
int fdnew;
int size;
char read_buffer[80];
char write_buffer[]="dddddddddddddddddddddddddddddddddd";
char write_buffernew[]="Hi new file";
off_t offset = 0; /* byte offset used by sendfile */
//open the file, if it doesn't exist create it with the following permission access
fd = open (WorkPATH,/* O_RDONLY */ O_WRONLY |O_CREAT,0600);
if (fd == -1)
{
/* The open failed. Print an error message and exit. */
printf("error opening file: \n");
exit(-1);
}
fdnew = open (NewWorkPATH,/* O_RDONLY */ O_WRONLY |O_CREAT,0600);
if (fdnew == -1)
{
/* The open failed. Print an error message and exit. */
printf("error opening file: \n");
exit(-1);
}
/* Read the size of the data in the file. */
//Use the systems calls in order to read from $path via read only permissions
read (fd, read_buffer, sizeof (read_buffer));
//Try to write to it ,with the same read only permissions
write (fd, write_buffer, strlen (write_buffer));
printf("The file - a.txt - Content is: \n");
system("cat a.txt\n");
// Close the file descriptor,
close (fd);
ssize_t sendfile(NewWorkPATH, WorkPATH, off_t *offset, strlen(write_buffer));
// read (fd, read_buffer, sizeof (read_buffer));
// write (fd, write_buffernew, strlen (write_buffer));
printf("The file -NEWa.txt - Content is: \n");
system("cat NEWa.txt\n");
}