34 #ifdef HAVE_SYS_FILE_H
35 # include <sys/file.h>
37 #ifdef HAVE_SYS_STAT_H
38 # include <sys/stat.h>
48 #if defined(HAVE_FSEEKO64) && (SIZEOF_OFF_T < 8)
49 # define fopen(f, m) fopen64((f), (m))
50 # define fseek(f, o, w) fseeko64((f), (o), (w))
51 #elif defined(HAVE__FSEEKI64)
52 # define fseek(f, o, w) _fseeki64((f), (o), (w))
53 #elif defined(HAVE_FSEEKO)
54 # define fseek(f, o, w) fseeko((f), (o), (w))
58 #if defined(HAVE_FSTAT64) && (SIZEOF_OFF_T < 8)
60 # define fstat(f,s) fstat64((f), (s))
61 #elif defined(HAVE__FSTATI64)
62 # define stat _stati64
63 # define fstat(f,s) _fstati64((f), (s))
68 # define S_ISREG(x) ((x) & _S_IFREG)
72 #if !defined(HAVE_FILENO) && defined(HAVE__FILENO)
73 # define fileno(f) _fileno((f))
83 FILE *rs_file_open(
char const *filename,
char const *mode,
int force)
88 is_write = mode[0] ==
'w';
90 if (!filename || !strcmp(
"-", filename)) {
93 _setmode(_fileno(stdout), _O_BINARY);
98 _setmode(_fileno(stdin), _O_BINARY);
104 if (!force && is_write) {
105 if ((f = fopen(filename,
"rb"))) {
107 rs_error(
"File exists \"%s\", aborting!", filename);
113 if (!(f = fopen(filename, mode))) {
114 rs_error(
"Error opening \"%s\" for %s: %s", filename,
115 is_write ?
"write" :
"read", strerror(errno));
122 int rs_file_close(FILE *f)
124 if ((f == stdin) || (f == stdout))
129 void rs_get_filesize(FILE *f, rs_long_t *size)
132 if (size && (fstat(fileno(f), &st) == 0) && (S_ISREG(st.st_mode))) {
140 FILE *f = (FILE *)arg;
142 if (fseek(f, pos, SEEK_SET)) {
143 rs_error(
"seek failed: %s", strerror(errno));
147 got = fread(*buf, 1, *len, f);
149 rs_error(
"read error: %s", strerror(errno));
151 }
else if (got == 0) {
152 rs_error(
"unexpected eof on fd%d", fileno(f));
Error in file or network IO.
Public header for librsync.
rs_result
Return codes from nonblocking rsync operations.
Unexpected end of input file, perhaps due to a truncated file or dropped network connection.
rs_result rs_file_copy_cb(void *arg, rs_long_t pos, size_t *len, void **buf)
rs_copy_cb that reads from a stdio file.