diff --git a/alsactl/utils.c b/alsactl/utils.c index d8cbf5355..fd9e71d65 100644 --- a/alsactl/utils.c +++ b/alsactl/utils.c @@ -84,19 +84,45 @@ void initfailed(int cardnumber, const char *reason, int exitcode) int fp; char *str; char sexitcode[16]; - + ssize_t bytes_written; + if (statefile == NULL) - return; + return; if (snd_card_get_name(cardnumber, &str) < 0) - return; + return; sprintf(sexitcode, "%i", exitcode); fp = open(statefile, O_WRONLY|O_CREAT|O_APPEND, 0644); - (void)write(fp, str, strlen(str)); - (void)write(fp, ":", 1); - (void)write(fp, reason, strlen(reason)); - (void)write(fp, ":", 1); - (void)write(fp, sexitcode, strlen(sexitcode)); - (void)write(fp, "\n", 1); + + bytes_written = write(fp, str, strlen(str)); + if (bytes_written != strlen(str)) { + // Handle error + } + + bytes_written = write(fp, ":", 1); + if (bytes_written != 1) { + // Handle error + } + + bytes_written = write(fp, reason, strlen(reason)); + if (bytes_written != strlen(reason)) { + // Handle error + } + + bytes_written = write(fp, ":", 1); + if (bytes_written != 1) { + // Handle error + } + + bytes_written = write(fp, sexitcode, strlen(sexitcode)); + if (bytes_written != strlen(sexitcode)) { + // Handle error + } + + bytes_written = write(fp, "\n", 1); + if (bytes_written != 1) { + // Handle error + } + close(fp); free(str); } diff --git a/amidi/amidi.c b/amidi/amidi.c index ae2143c21..d67dffbb0 100644 --- a/amidi/amidi.c +++ b/amidi/amidi.c @@ -728,9 +728,18 @@ int main(int argc, char *argv[]) if (length == 0) continue; read += length; + + ssize_t bytes_written; + + if (receive_file != -1) { + bytes_written = write(receive_file, buf, length); + if (bytes_written != length) { + // handle the error, e.g., print an error message or break the loop + error("write() failed: %s", strerror(errno)); + break; + } + } - if (receive_file != -1) - write(receive_file, buf, length); if (dump) { for (i = 0; i < length; ++i) print_byte(buf[i], &ts); diff --git a/axfer/xfer-options.c b/axfer/xfer-options.c index 3740b1665..bb26bbda4 100644 --- a/axfer/xfer-options.c +++ b/axfer/xfer-options.c @@ -66,12 +66,12 @@ static int allocate_paths(struct xfer_context *xfer, char *const *paths, xfer->path_count = count; if (stdio) { - xfer->paths[0] = strndup("-", PATH_MAX); + xfer->paths[0] = strndup("-", strlen("-")); if (xfer->paths[0] == NULL) return -ENOMEM; } else { for (i = 0; i < count; ++i) { - xfer->paths[i] = strndup(paths[i], PATH_MAX); + xfer->paths[i] = strndup(paths[i], strlen(paths[i])); if (xfer->paths[i] == NULL) return -ENOMEM; }