Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
#define _GNU_SOURCE
+#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <stdint.h>
struct smb2_context *smb2;
struct smb2_url *url;
struct smb2fh *fh;
- int count;
+ int count, rc = 0;
if (argc < 2) {
usage();
exit(10);
}
- while ((count = smb2_pread(smb2, fh, buf, MAXBUF, pos)) > 0) {
+ while ((count = smb2_pread(smb2, fh, buf, MAXBUF, pos)) != 0) {
+ if (count == -EAGAIN) {
+ continue;
+ }
+ if (count < 0) {
+ fprintf(stderr, "Failed to read file. %s\n",
+ smb2_get_error(smb2));
+ rc = 1;
+ break;
+ }
write(0, buf, count);
pos += count;
};
smb2_destroy_url(url);
smb2_destroy_context(smb2);
- return 0;
+ return rc;
}