Check return codes on some write() calls
This commit is contained in:
parent
f72af0713e
commit
ebaa1ca210
|
@ -31,7 +31,7 @@ char *r2_asmjs_cmd(void *kore, const char *cmd) {
|
|||
}
|
||||
|
||||
static void wget_cb(const char *f) {
|
||||
r_core_cmdf (core, "o %s", f);
|
||||
r_core_cmdf (core, "\"o %s\"", f);
|
||||
}
|
||||
|
||||
void r2_asmjs_openurl(void *kore, const char *url) {
|
||||
|
@ -45,8 +45,13 @@ void r2_asmjs_openurl(void *kore, const char *url) {
|
|||
}
|
||||
#else
|
||||
static void r2cmd(int in, int out, const char *cmd) {
|
||||
write (out, cmd, strlen (cmd) + 1);
|
||||
write (out, "\n", 1);
|
||||
size_t cmd_len = strlen (cmd) + 1;
|
||||
if (write (out, cmd, cmd_len) != cmd_len) {
|
||||
return;
|
||||
}
|
||||
if (write (out, "\n", 1) != 1) {
|
||||
return;
|
||||
}
|
||||
int bufsz = (1024 * 64);
|
||||
unsigned char *buf = malloc (bufsz);
|
||||
if (!buf) {
|
||||
|
@ -54,13 +59,16 @@ static void r2cmd(int in, int out, const char *cmd) {
|
|||
}
|
||||
while (1) {
|
||||
int n = read (in, buf, bufsz);
|
||||
if (n != bufsz) {
|
||||
break;
|
||||
}
|
||||
buf[bufsz - 1] = '\0';
|
||||
int len = strlen ((const char *)buf);
|
||||
n = len;
|
||||
if (n < 1) {
|
||||
break;
|
||||
}
|
||||
write (1, buf, n);
|
||||
n = write (1, buf, n);
|
||||
if (n != bufsz) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -109,7 +109,9 @@ bool test_r_buf_file(void) {
|
|||
// Prepare file
|
||||
int fd = r_file_mkstemp ("", &filename);
|
||||
mu_assert_neq ((ut64)fd, (ut64)-1, "mkstemp failed...");
|
||||
write (fd, content, length);
|
||||
if (write (fd, content, length) != length) {
|
||||
return false;
|
||||
}
|
||||
close (fd);
|
||||
|
||||
b = r_buf_new_file (filename, O_RDWR, 0);
|
||||
|
@ -152,20 +154,22 @@ bool test_r_buf_mmap(void) {
|
|||
// Prepare file
|
||||
int fd = r_file_mkstemp ("", &filename);
|
||||
mu_assert_neq ((long long)fd, -1LL, "mkstemp failed...");
|
||||
write (fd, content, length);
|
||||
if (write (fd, content, length) != length) {
|
||||
return false;
|
||||
}
|
||||
close (fd);
|
||||
|
||||
b = r_buf_new_mmap (filename, R_PERM_RW);
|
||||
mu_assert_notnull (b, "r_buf_new_mmap failed");
|
||||
|
||||
if (test_buf (b) != MU_PASSED) {
|
||||
unlink(filename);
|
||||
unlink (filename);
|
||||
mu_fail ("test failed");
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
r_buf_free (b);
|
||||
unlink(filename);
|
||||
unlink (filename);
|
||||
free (filename);
|
||||
mu_end;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue