Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix three compile warnings #221

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions alsactl/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
13 changes: 11 additions & 2 deletions amidi/amidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions axfer/xfer-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down