fix for Mac OS X
authorCyprien Laplace <cyprien@cypou.net>
Sun, 15 Feb 2015 22:03:21 +0000 (17:03 -0500)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Mon, 14 Sep 2015 13:48:22 +0000 (15:48 +0200)
Two small fixes to let lpcprog work on OS X Yosemite:
- initialize errno to 0 before strtoul() and errno testing
- pad the parts structure as OSX seems to align the size of the
  structure on 64-bit boundary, which made it think there were 10
  values to read instead of 9

parts.c
parts.h

diff --git a/parts.c b/parts.c
index ce114ea..2033aee 100644 (file)
--- a/parts.c
+++ b/parts.c
@@ -58,7 +58,7 @@ struct part_desc* find_part_in_file(uint64_t dev_id, char* parts_file_name)
                        goto out_err_1;
                }
                line++; /* Store current line number to help parts description file correction */
-               if (buf[0] == '#') {
+               if (buf[0] == '#' || buf[0] == '\n') {
                        /* skip comments */
                        continue;
                }
@@ -94,6 +94,7 @@ struct part_desc* find_part_in_file(uint64_t dev_id, char* parts_file_name)
                nval = ((sizeof(struct part_desc) - offsetof(struct part_desc, flash_base)) / sizeof(uint32_t));
                part_values = &(part->flash_base); /* Use a table to read the data, we do not care of what the data is */
                for (i = 0; i < nval; i++) {
+                       errno = 0;
                        part_values[i] = strtoul((endp + 1), &endp, 0);
                        if ((part_values[i] == 0) && (errno == EINVAL)) {
                                printf("Malformed parts description file at line %d, error reading value %d\n", line, i);
diff --git a/parts.h b/parts.h
index ede171d..168dd99 100644 (file)
--- a/parts.h
+++ b/parts.h
@@ -32,6 +32,7 @@
 struct part_desc {
        uint64_t part_id;
        char* name;
+       uint32_t pad;
        /* Flash */
        uint32_t flash_base;
        uint32_t flash_size;