34#ifdef HAVE_SYS_TYPES_H
35# include <sys/types.h>
50#if defined(HAVE_FSEEKO64) && (SIZEOF_OFF_T < 8)
51# define fopen(f, m) fopen64((f), (m))
52# define fseek(f, o, w) fseeko64((f), (o), (w))
53#elif defined(HAVE__FSEEKI64)
54# define fseek(f, o, w) _fseeki64((f), (o), (w))
55#elif defined(HAVE_FSEEKO)
56# define fseek(f, o, w) fseeko((f), (o), (w))
60#if defined(HAVE_FSTAT64) && (SIZEOF_OFF_T < 8)
62# define fstat(f,s) fstat64((f), (s))
63#elif defined(HAVE__FSTATI64)
65# define fstat(f,s) _fstati64((f), (s))
70# define S_ISREG(x) ((x) & _S_IFREG)
75# define fileno(f) _fileno((f))
78FILE *rs_file_open(
char const *filename,
char const *mode,
int force)
83 is_write = mode[0] ==
'w';
85 if (!filename || !strcmp(
"-", filename)) {
88 _setmode(_fileno(stdout), _O_BINARY);
93 _setmode(_fileno(stdin), _O_BINARY);
99 if (!force && is_write) {
100 if ((f = fopen(filename,
"rb"))) {
102 rs_error(
"File exists \"%s\", aborting!", filename);
108 if (!(f = fopen(filename, mode))) {
109 rs_error(
"Error opening \"%s\" for %s: %s", filename,
110 is_write ?
"write" :
"read", strerror(errno));
117int rs_file_close(FILE *f)
119 if ((f == stdin) || (f == stdout))
124rs_long_t rs_file_size(FILE *f)
127 if ((fstat(fileno(f), &st) == 0) && (S_ISREG(st.st_mode)))
132rs_result rs_file_copy_cb(
void *arg, rs_long_t pos,
size_t *len,
void **buf)
134 FILE *f = (FILE *)arg;
136 if (fseek(f, pos, SEEK_SET)) {
137 rs_error(
"seek failed: %s", strerror(errno));
140 *len = fread(*buf, 1, *len, f);
143 }
else if (ferror(f)) {
144 rs_error(
"read error: %s", strerror(errno));
147 rs_error(
"unexpected eof on fd%d", fileno(f));
Public header for librsync.
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.