Add a safe wrapper for write and fix some warnings
1. Add a function writeall and make swrite wrap that function. Use either writeall or swrite, depending on whether we want to exit on errors or not. 2. Fix warnings when compiling with a higher optimisation level. (CFLAGS ?= -pipe -O3 -march=native -mtune=native -freorder-blocks-and-partition) Signed-off-by: hwangcc <hwangcc@csie.nctu.edu.tw>
This commit is contained in:
@ -778,14 +778,9 @@ static char *migrate_config(char *input, off_t size) {
|
||||
|
||||
/* write the whole config file to the pipe, the script will read everything
|
||||
* immediately */
|
||||
int written = 0;
|
||||
int ret;
|
||||
while (written < size) {
|
||||
if ((ret = write(writepipe[1], input + written, size - written)) < 0) {
|
||||
warn("Could not write to pipe");
|
||||
return NULL;
|
||||
}
|
||||
written += ret;
|
||||
if (writeall(writepipe[1], input, size) == -1) {
|
||||
warn("Could not write to pipe");
|
||||
return NULL;
|
||||
}
|
||||
close(writepipe[1]);
|
||||
|
||||
@ -795,7 +790,7 @@ static char *migrate_config(char *input, off_t size) {
|
||||
/* read the script’s output */
|
||||
int conv_size = 65535;
|
||||
char *converted = malloc(conv_size);
|
||||
int read_bytes = 0;
|
||||
int read_bytes = 0, ret;
|
||||
do {
|
||||
if (read_bytes == conv_size) {
|
||||
conv_size += 65535;
|
||||
|
Reference in New Issue
Block a user