Arpeda
12-05-2004, 23:25
Ciao a tutti,
stavo provando la sendfile confrontando i tempi di trasferiemtno di un file rispetto alla copia "normale" (prima copia in un buffer e poi nel file di destinazione) ma la sendfile mi ritorna EINVAL. Questo è il codice incrimnato:
int main (int argc, char* argv[])
{
int read_fd;
int write_fd;
struct stat stat_buf;
off_t offset = 0;
/* Open the input file. */
read_fd = open (argv[1], O_RDONLY);
/* Stat the input file to obtain its size. */
fstat (read_fd, &stat_buf);
/* Open the ouput file for writing, with the same permissions as the
source file. */
write_fd = open (argv[2], O_WRONLY | O_CREAT, stat_buf.st_mode);
/* Blast the bytes from one file to the other. */
if (sendfile (write_fd, read_fd, &offset, stat_buf.st_size) < 0) {
if (errno == EBADF)
printf("EBADF\n");
if (errno == EAGAIN)
printf("EAGAIN\n");
if (errno == EINVAL)
printf("EINVAL\n");
if (errno == ENOMEM)
printf("ENOMEM\n");
if (errno == EIO)
printf("EIO\n");
if (errno == EFAULT)
printf("EFAULT\n");
perror("ERROR");
}
/* Close up. */
close (read_fd);
close (write_fd);
return 0;
}
L'esempio è preso da advanced linux programming ... avete qualche idea?
Ciao
Arpeda
stavo provando la sendfile confrontando i tempi di trasferiemtno di un file rispetto alla copia "normale" (prima copia in un buffer e poi nel file di destinazione) ma la sendfile mi ritorna EINVAL. Questo è il codice incrimnato:
int main (int argc, char* argv[])
{
int read_fd;
int write_fd;
struct stat stat_buf;
off_t offset = 0;
/* Open the input file. */
read_fd = open (argv[1], O_RDONLY);
/* Stat the input file to obtain its size. */
fstat (read_fd, &stat_buf);
/* Open the ouput file for writing, with the same permissions as the
source file. */
write_fd = open (argv[2], O_WRONLY | O_CREAT, stat_buf.st_mode);
/* Blast the bytes from one file to the other. */
if (sendfile (write_fd, read_fd, &offset, stat_buf.st_size) < 0) {
if (errno == EBADF)
printf("EBADF\n");
if (errno == EAGAIN)
printf("EAGAIN\n");
if (errno == EINVAL)
printf("EINVAL\n");
if (errno == ENOMEM)
printf("ENOMEM\n");
if (errno == EIO)
printf("EIO\n");
if (errno == EFAULT)
printf("EFAULT\n");
perror("ERROR");
}
/* Close up. */
close (read_fd);
close (write_fd);
return 0;
}
L'esempio è preso da advanced linux programming ... avete qualche idea?
Ciao
Arpeda