+ int ret=0;
+ int last_f=0;
+ int last_b=0;
+
+ off_t last=-1, last2=-1;
+ off_t orig = lseek(fd, 0, SEEK_CUR);
+ int orig_f = current_file;
+ int orig_b = current_block;
+
+ current_block=0;
+ seek_file();
+
+ do {
+ if (!atEOF) {
+ last2 = last;
+ last = lseek(fd, 0, SEEK_CUR);
+ last_f = current_file;
+ last_b = current_block;
+ Dmsg5(dbglevel, "EOF=%i last=%lli orig=%lli %i:%i\n",
+ atEOF, last, orig, current_file, current_block);
+ }
+ ret = fsr(1);
+ } while ((lseek(fd, 0, SEEK_CUR) < orig) && (ret == 0));
+
+ if (last2 > 0 && atEOF) { /* we take the previous position */
+ lseek(fd, last2, SEEK_SET);
+ current_file = last_f;
+ current_block = last_b - 1;
+ Dmsg3(dbglevel, "set offset2=%lli %i:%i\n",
+ last, current_file, current_block);
+
+ } else if (last > 0) {
+ lseek(fd, last, SEEK_SET);
+ current_file = last_f;
+ current_block = last_b;
+ Dmsg3(dbglevel, "set offset=%lli %i:%i\n",
+ last, current_file, current_block);
+ } else {
+ lseek(fd, orig, SEEK_SET);
+ current_file = orig_f;
+ current_block = orig_b;