tools: iio: Send error messages to stderr

This patch indends to make some cleanup and send printf
error messages to stderr. The changes were performed with coccinelle
for failure messages and manual for other cases, such as wrong usage
messages.

Signed-off-by: Cristina Opriceana <cristina.opriceana@gmail.com>
Reviewed-by: Hartmut Knaack <knaack.h@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
Cristina Opriceana
2015-07-17 18:43:42 +03:00
committed by Jonathan Cameron
parent 34cbea1908
commit d9abc615ea
4 changed files with 59 additions and 47 deletions

View File

@@ -215,8 +215,8 @@ static void print_event(struct iio_event_data *event)
bool diff = IIO_EVENT_CODE_EXTRACT_DIFF(event->id);
if (!event_is_known(event)) {
printf("Unknown event: time: %lld, id: %llx\n",
event->timestamp, event->id);
fprintf(stderr, "Unknown event: time: %lld, id: %llx\n",
event->timestamp, event->id);
return;
}
@@ -251,7 +251,7 @@ int main(int argc, char **argv)
int fd, event_fd;
if (argc <= 1) {
printf("Usage: %s <device_name>\n", argv[0]);
fprintf(stderr, "Usage: %s <device_name>\n", argv[0]);
return -1;
}
@@ -277,14 +277,14 @@ int main(int argc, char **argv)
fd = open(chrdev_name, 0);
if (fd == -1) {
ret = -errno;
fprintf(stdout, "Failed to open %s\n", chrdev_name);
fprintf(stderr, "Failed to open %s\n", chrdev_name);
goto error_free_chrdev_name;
}
ret = ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd);
if (ret == -1 || event_fd == -1) {
ret = -errno;
fprintf(stdout, "Failed to retrieve event fd\n");
fprintf(stderr, "Failed to retrieve event fd\n");
if (close(fd) == -1)
perror("Failed to close character device file");
@@ -300,7 +300,7 @@ int main(int argc, char **argv)
ret = read(event_fd, &event, sizeof(event));
if (ret == -1) {
if (errno == EAGAIN) {
printf("nothing available\n");
fprintf(stderr, "nothing available\n");
continue;
} else {
ret = -errno;
@@ -310,7 +310,7 @@ int main(int argc, char **argv)
}
if (ret != sizeof(event)) {
printf("Reading event failed!\n");
fprintf(stderr, "Reading event failed!\n");
ret = -EIO;
break;
}