35#ifdef HAVE_SYS_TYPES_H
36# include <sys/types.h>
51#if defined(HAVE_FSEEKO64) && (SIZEOF_OFF_T < 8)
52# define fopen(f, m) fopen64((f), (m))
53# define fseek(f, o, w) fseeko64((f), (o), (w))
54#elif defined(HAVE__FSEEKI64)
55# define fseek(f, o, w) _fseeki64((f), (o), (w))
56#elif defined(HAVE_FSEEKO)
57# define fseek(f, o, w) fseeko((f), (o), (w))
61#if defined(HAVE_FSTAT64) && (SIZEOF_OFF_T < 8)
63# define fstat(f,s) fstat64((f), (s))
64#elif defined(HAVE__FSTATI64)
66# define fstat(f,s) _fstati64((f), (s))
71# define S_ISREG(x) ((x) & _S_IFREG)
76# define fileno(f) _fileno((f))
79FILE *
rs_file_open(
char const *filename,
char const *mode,
int force)
84 is_write = mode[0] ==
'w';
86 if (!filename || !strcmp(
"-", filename)) {
89 _setmode(_fileno(stdout), _O_BINARY);
94 _setmode(_fileno(stdin), _O_BINARY);
100 if (!force && is_write) {
101 if ((f = fopen(filename,
"rb"))) {
103 rs_error(
"File exists \"%s\", aborting!", filename);
109 if (!(f = fopen(filename, mode))) {
110 rs_error(
"Error opening \"%s\" for %s: %s", filename,
111 is_write ?
"write" :
"read", strerror(errno));
120 if ((f == stdin) || (f == stdout))
128 if ((fstat(fileno(f), &st) == 0) && (S_ISREG(st.st_mode)))
135 FILE *f = (FILE *)arg;
137 if (fseek(f, pos, SEEK_SET)) {
138 rs_error(
"seek failed: %s", strerror(errno));
141 *len = fread(*buf, 1, *len, f);
144 }
else if (ferror(f)) {
145 rs_error(
"read error: %s", strerror(errno));
148 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.