aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flash_otp_write.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/flash_otp_write.c b/flash_otp_write.c
index 56769ec..3515eee 100644
--- a/flash_otp_write.c
+++ b/flash_otp_write.c
@@ -16,6 +16,23 @@
#include <common.h>
#include <mtd/mtd-user.h>
+ssize_t xread(int fd, void *buf, size_t count)
+{
+ ssize_t ret, done = 0;
+
+retry:
+ ret = read(fd, buf + done, count - done);
+ if (ret < 0)
+ return ret;
+
+ done += ret;
+
+ if (ret == 0 /* EOF */ || done == count)
+ return done;
+ else
+ goto retry;
+}
+
int main(int argc,char *argv[])
{
int fd, val, ret, size, wrote, len;
@@ -67,7 +84,7 @@ int main(int argc,char *argv[])
len = 256;
wrote = 0;
- while ((size = read(0, buf, len))) {
+ while ((size = xread(0, buf, len))) {
if (size < 0) {
perror("read()");
return errno;