Commit 22423c53 authored by Federico Vaga's avatar Federico Vaga

sw:lib: bugfix, handle error conditions

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 9cdd4133
......@@ -487,7 +487,9 @@ int trtl_cpu_load_application_raw(struct trtl_dev *trtl,
{
struct trtl_desc *wdesc = (struct trtl_desc *)trtl;
char path[TRTL_DEVICE_PATH_LEN];
int fd, i = 0;
int fd;
ssize_t ret;
size_t i = 0;
snprintf(path, TRTL_DEVICE_PATH_LEN, "%s/%s-cpu-%02d",
wdesc->path, wdesc->name, index);
......@@ -496,12 +498,16 @@ int trtl_cpu_load_application_raw(struct trtl_dev *trtl,
return -1;
lseek(fd, offset, SEEK_SET);
do {
i += write(fd, code, length);
} while (i < length);
errno = ENOMEM;
while (i < length) {
ret = write(fd, code, length);
if (ret <= 0)
break;
i += ret;
}
close(fd);
return i;
return ret <= 0 ? ret : i;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment