37#ifdef HAVE_SYS_TYPES_H
38# include <sys/types.h>
53#if defined(HAVE_FSEEKO64) && (SIZEOF_OFF_T < 8)
54# define fopen(f, m) fopen64((f), (m))
55# define fseek(f, o, w) fseeko64((f), (o), (w))
56#elif defined(HAVE__FSEEKI64)
57# define fseek(f, o, w) _fseeki64((f), (o), (w))
58#elif defined(HAVE_FSEEKO)
59# define fseek(f, o, w) fseeko((f), (o), (w))
63#if defined(HAVE_FSTAT64) && (SIZEOF_OFF_T < 8)
65# define fstat(f,s) fstat64((f), (s))
66#elif defined(HAVE__FSTATI64)
68# define fstat(f,s) _fstati64((f), (s))
73# define S_ISREG(x) ((x) & _S_IFREG)
78# define fileno(f) _fileno((f))
81FILE *
rs_file_open(
char const *filename,
char const *mode,
int force)
86 is_write = mode[0] ==
'w';
88 if (!filename || !strcmp(
"-", filename)) {
91 _setmode(_fileno(stdout), _O_BINARY);
96 _setmode(_fileno(stdin), _O_BINARY);
102 if (!force && is_write) {
103 if ((f = fopen(filename,
"rb"))) {
105 rs_error(
"File exists \"%s\", aborting!", filename);
111 if (!(f = fopen(filename, mode))) {
112 rs_error(
"Error opening \"%s\" for %s: %s", filename,
113 is_write ?
"write" :
"read", strerror(errno));
122 if ((f == stdin) || (f == stdout))
130 if ((fstat(fileno(f), &st) == 0) && (S_ISREG(st.st_mode)))
137 FILE *f = (FILE *)arg;
139 if (fseek(f, pos, SEEK_SET)) {
140 rs_error(
"seek failed: %s", strerror(errno));
143 *len = fread(*buf, 1, *len, f);
146 }
else if (ferror(f)) {
147 rs_error(
"read error: %s", strerror(errno));
150 rs_error(
"unexpected eof on fd%d", fileno(f));
Public header for librsync.
LIBRSYNC_EXPORT int rs_file_close(FILE *file)
Close a file with special handling for stdin or stdout.
LIBRSYNC_EXPORT FILE * rs_file_open(char const *filename, char const *mode, int force)
Open a file with special handling for stdin or stdout.
LIBRSYNC_EXPORT rs_long_t rs_file_size(FILE *file)
Get the size of a file.
rs_result
Return codes from nonblocking rsync operations.
@ RS_DONE
Completed successfully.
@ RS_INPUT_ENDED
Unexpected end of input file, perhaps due to a truncated file or dropped network connection.
@ RS_IO_ERROR
Error in file or network IO.
LIBRSYNC_EXPORT 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.