aboutsummaryrefslogtreecommitdiffstats
path: root/tools/iio/iio_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/iio/iio_utils.c')
-rw-r--r--tools/iio/iio_utils.c51
1 files changed, 30 insertions, 21 deletions
diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
index e177f4022d40..c3f9e37333e7 100644
--- a/tools/iio/iio_utils.c
+++ b/tools/iio/iio_utils.c
@@ -140,7 +140,8 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
140 sysfsfp = fopen(filename, "r"); 140 sysfsfp = fopen(filename, "r");
141 if (!sysfsfp) { 141 if (!sysfsfp) {
142 ret = -errno; 142 ret = -errno;
143 printf("failed to open %s\n", filename); 143 fprintf(stderr, "failed to open %s\n",
144 filename);
144 goto error_free_filename; 145 goto error_free_filename;
145 } 146 }
146 147
@@ -152,11 +153,13 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
152 &padint, shift); 153 &padint, shift);
153 if (ret < 0) { 154 if (ret < 0) {
154 ret = -errno; 155 ret = -errno;
155 printf("failed to pass scan type description\n"); 156 fprintf(stderr,
157 "failed to pass scan type description\n");
156 goto error_close_sysfsfp; 158 goto error_close_sysfsfp;
157 } else if (ret != 5) { 159 } else if (ret != 5) {
158 ret = -EIO; 160 ret = -EIO;
159 printf("scan type description didn't match\n"); 161 fprintf(stderr,
162 "scan type description didn't match\n");
160 goto error_close_sysfsfp; 163 goto error_close_sysfsfp;
161 } 164 }
162 165
@@ -170,7 +173,8 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
170 *is_signed = (signchar == 's'); 173 *is_signed = (signchar == 's');
171 if (fclose(sysfsfp)) { 174 if (fclose(sysfsfp)) {
172 ret = -errno; 175 ret = -errno;
173 printf("Failed to close %s\n", filename); 176 fprintf(stderr, "Failed to close %s\n",
177 filename);
174 goto error_free_filename; 178 goto error_free_filename;
175 } 179 }
176 180
@@ -454,7 +458,8 @@ int build_channel_array(const char *device_dir,
454 sysfsfp = fopen(filename, "r"); 458 sysfsfp = fopen(filename, "r");
455 if (!sysfsfp) { 459 if (!sysfsfp) {
456 ret = -errno; 460 ret = -errno;
457 printf("failed to open %s\n", filename); 461 fprintf(stderr, "failed to open %s\n",
462 filename);
458 free(filename); 463 free(filename);
459 goto error_cleanup_array; 464 goto error_cleanup_array;
460 } 465 }
@@ -568,7 +573,7 @@ int find_type_by_name(const char *name, const char *type)
568 573
569 dp = opendir(iio_dir); 574 dp = opendir(iio_dir);
570 if (!dp) { 575 if (!dp) {
571 printf("No industrialio devices available\n"); 576 fprintf(stderr, "No industrialio devices available\n");
572 return -ENODEV; 577 return -ENODEV;
573 } 578 }
574 579
@@ -581,11 +586,13 @@ int find_type_by_name(const char *name, const char *type)
581 ret = sscanf(ent->d_name + strlen(type), "%d", &number); 586 ret = sscanf(ent->d_name + strlen(type), "%d", &number);
582 if (ret < 0) { 587 if (ret < 0) {
583 ret = -errno; 588 ret = -errno;
584 printf("failed to read element number\n"); 589 fprintf(stderr,
590 "failed to read element number\n");
585 goto error_close_dir; 591 goto error_close_dir;
586 } else if (ret != 1) { 592 } else if (ret != 1) {
587 ret = -EIO; 593 ret = -EIO;
588 printf("failed to match element number\n"); 594 fprintf(stderr,
595 "failed to match element number\n");
589 goto error_close_dir; 596 goto error_close_dir;
590 } 597 }
591 598
@@ -664,7 +671,7 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val,
664 sysfsfp = fopen(temp, "w"); 671 sysfsfp = fopen(temp, "w");
665 if (!sysfsfp) { 672 if (!sysfsfp) {
666 ret = -errno; 673 ret = -errno;
667 printf("failed to open %s\n", temp); 674 fprintf(stderr, "failed to open %s\n", temp);
668 goto error_free; 675 goto error_free;
669 } 676 }
670 677
@@ -685,7 +692,7 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val,
685 sysfsfp = fopen(temp, "r"); 692 sysfsfp = fopen(temp, "r");
686 if (!sysfsfp) { 693 if (!sysfsfp) {
687 ret = -errno; 694 ret = -errno;
688 printf("failed to open %s\n", temp); 695 fprintf(stderr, "failed to open %s\n", temp);
689 goto error_free; 696 goto error_free;
690 } 697 }
691 698
@@ -703,8 +710,9 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val,
703 } 710 }
704 711
705 if (test != val) { 712 if (test != val) {
706 printf("Possible failure in int write %d to %s/%s\n", 713 fprintf(stderr,
707 val, basedir, filename); 714 "Possible failure in int write %d to %s/%s\n",
715 val, basedir, filename);
708 ret = -1; 716 ret = -1;
709 } 717 }
710 } 718 }
@@ -750,7 +758,7 @@ static int _write_sysfs_string(const char *filename, const char *basedir,
750 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 758 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
751 759
752 if (!temp) { 760 if (!temp) {
753 printf("Memory allocation failed\n"); 761 fprintf(stderr, "Memory allocation failed\n");
754 return -ENOMEM; 762 return -ENOMEM;
755 } 763 }
756 764
@@ -761,7 +769,7 @@ static int _write_sysfs_string(const char *filename, const char *basedir,
761 sysfsfp = fopen(temp, "w"); 769 sysfsfp = fopen(temp, "w");
762 if (!sysfsfp) { 770 if (!sysfsfp) {
763 ret = -errno; 771 ret = -errno;
764 printf("Could not open %s\n", temp); 772 fprintf(stderr, "Could not open %s\n", temp);
765 goto error_free; 773 goto error_free;
766 } 774 }
767 775
@@ -782,7 +790,7 @@ static int _write_sysfs_string(const char *filename, const char *basedir,
782 sysfsfp = fopen(temp, "r"); 790 sysfsfp = fopen(temp, "r");
783 if (!sysfsfp) { 791 if (!sysfsfp) {
784 ret = -errno; 792 ret = -errno;
785 printf("Could not open file to verify\n"); 793 fprintf(stderr, "Could not open file to verify\n");
786 goto error_free; 794 goto error_free;
787 } 795 }
788 796
@@ -800,9 +808,10 @@ static int _write_sysfs_string(const char *filename, const char *basedir,
800 } 808 }
801 809
802 if (strcmp(temp, val) != 0) { 810 if (strcmp(temp, val) != 0) {
803 printf("Possible failure in string write of %s " 811 fprintf(stderr,
804 "Should be %s written to %s/%s\n", temp, val, 812 "Possible failure in string write of %s "
805 basedir, filename); 813 "Should be %s written to %s/%s\n", temp, val,
814 basedir, filename);
806 ret = -1; 815 ret = -1;
807 } 816 }
808 } 817 }
@@ -856,7 +865,7 @@ int read_sysfs_posint(const char *filename, const char *basedir)
856 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 865 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
857 866
858 if (!temp) { 867 if (!temp) {
859 printf("Memory allocation failed"); 868 fprintf(stderr, "Memory allocation failed");
860 return -ENOMEM; 869 return -ENOMEM;
861 } 870 }
862 871
@@ -903,7 +912,7 @@ int read_sysfs_float(const char *filename, const char *basedir, float *val)
903 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 912 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
904 913
905 if (!temp) { 914 if (!temp) {
906 printf("Memory allocation failed"); 915 fprintf(stderr, "Memory allocation failed");
907 return -ENOMEM; 916 return -ENOMEM;
908 } 917 }
909 918
@@ -950,7 +959,7 @@ int read_sysfs_string(const char *filename, const char *basedir, char *str)
950 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 959 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
951 960
952 if (!temp) { 961 if (!temp) {
953 printf("Memory allocation failed"); 962 fprintf(stderr, "Memory allocation failed");
954 return -ENOMEM; 963 return -ENOMEM;
955 } 964 }
956 965