summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2015-02-24 16:21:59 -0500
committerFranklin Wei <frankhwei536@gmail.com>2015-02-24 16:21:59 -0500
commit08724860a8682661ee20b68f7478e0cc1e3f4e05 (patch)
tree60f7446bd911abe60dcea956d2eaa4fad6c5a15d
parentc4bf2e3cfde6215727387530124a1b70ef6f60c5 (diff)
downloadrockbox-08724860a8682661ee20b68f7478e0cc1e3f4e05.tar.gz
rockbox-08724860a8682661ee20b68f7478e0cc1e3f4e05.zip
Whitespace fixes in firmware/common/structec.c
Change-Id: I2a6c5d5bd0c5b8fb516e167df74dc1f18508d702
-rw-r--r--firmware/common/structec.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/firmware/common/structec.c b/firmware/common/structec.c
index 5ee4f05c1f..3f220b0762 100644
--- a/firmware/common/structec.c
+++ b/firmware/common/structec.c
@@ -30,32 +30,32 @@
30 30
31/** 31/**
32 * Convert the struct endianess with the instructions provided. 32 * Convert the struct endianess with the instructions provided.
33 * 33 *
34 * For example: 34 * For example:
35 * struct test { 35 * struct test {
36 * long par1; 36 * long par1;
37 * short par2; 37 * short par2;
38 * short par3; 38 * short par3;
39 * }; 39 * };
40 * 40 *
41 * structec_convert(instance_of_test, "lss", sizeof(struct test), true); 41 * structec_convert(instance_of_test, "lss", sizeof(struct test), true);
42 * 42 *
43 * Structures to be converted must be properly padded. 43 * Structures to be converted must be properly padded.
44 * 44 *
45 * @param structure Pointer to the struct being converted. 45 * @param structure Pointer to the struct being converted.
46 * @param ecinst Instructions how to do the endianess conversion. 46 * @param ecinst Instructions how to do the endianess conversion.
47 * @param count Number of structures to write 47 * @param count Number of structures to write
48 * @param enable Conversion is not made unless this is true. 48 * @param enable Conversion is not made unless this is true.
49 */ 49 */
50void structec_convert(void *structure, const char *ecinst, 50void structec_convert(void *structure, const char *ecinst,
51 long count, bool enable) 51 long count, bool enable)
52{ 52{
53 const char *ecinst_ring = ecinst; 53 const char *ecinst_ring = ecinst;
54 char *buf = (char *)structure; 54 char *buf = (char *)structure;
55 55
56 if (!enable) 56 if (!enable)
57 return; 57 return;
58 58
59 while (count > 0) 59 while (count > 0)
60 { 60 {
61 switch (*ecinst_ring) 61 switch (*ecinst_ring)
@@ -66,7 +66,7 @@ void structec_convert(void *structure, const char *ecinst,
66 buf++; 66 buf++;
67 break; 67 break;
68 } 68 }
69 69
70 /* Swap 2 bytes. */ 70 /* Swap 2 bytes. */
71 case 's': 71 case 's':
72 { 72 {
@@ -84,7 +84,7 @@ void structec_convert(void *structure, const char *ecinst,
84 buf += 4; 84 buf += 4;
85 break; 85 break;
86 } 86 }
87 87
88 /* Skip N bytes, idea taken from metadata.c */ 88 /* Skip N bytes, idea taken from metadata.c */
89 default: 89 default:
90 { 90 {
@@ -94,7 +94,7 @@ void structec_convert(void *structure, const char *ecinst,
94 break; 94 break;
95 } 95 }
96 } 96 }
97 97
98 ecinst_ring++; 98 ecinst_ring++;
99 if (*ecinst_ring == '\0') 99 if (*ecinst_ring == '\0')
100 { 100 {
@@ -107,14 +107,14 @@ void structec_convert(void *structure, const char *ecinst,
107/** 107/**
108 * Determines the size of a struct in bytes by using endianess correction 108 * Determines the size of a struct in bytes by using endianess correction
109 * string format. 109 * string format.
110 * 110 *
111 * @param ecinst endianess correction string. 111 * @param ecinst endianess correction string.
112 * @return length of the struct in bytes. 112 * @return length of the struct in bytes.
113 */ 113 */
114static size_t structec_size(const char *ecinst) 114static size_t structec_size(const char *ecinst)
115{ 115{
116 size_t size = 0; 116 size_t size = 0;
117 117
118 do 118 do
119 { 119 {
120 switch (*ecinst) 120 switch (*ecinst)
@@ -122,18 +122,18 @@ static size_t structec_size(const char *ecinst)
122 case 'c': size += 1; break; 122 case 'c': size += 1; break;
123 case 's': size += 2; break; 123 case 's': size += 2; break;
124 case 'l': size += 4; break; 124 case 'l': size += 4; break;
125 default: 125 default:
126 if (isdigit(*ecinst)) 126 if (isdigit(*ecinst))
127 size += (*ecinst - '0'); 127 size += (*ecinst - '0');
128 } 128 }
129 } while (*(++ecinst) != '\0'); 129 } while (*(++ecinst) != '\0');
130 130
131 return size; 131 return size;
132} 132}
133 133
134/** 134/**
135 * Reads endianess corrected structure members from the given file. 135 * Reads endianess corrected structure members from the given file.
136 * 136 *
137 * @param fd file descriptor of the file being read. 137 * @param fd file descriptor of the file being read.
138 * @param buf endianess corrected data is placed here. 138 * @param buf endianess corrected data is placed here.
139 * @param scount the number of struct members to read. 139 * @param scount the number of struct members to read.
@@ -144,23 +144,23 @@ ssize_t ecread(int fd, void *buf, size_t scount, const char *ecinst, bool ec)
144{ 144{
145 ssize_t ret; 145 ssize_t ret;
146 size_t member_size = structec_size(ecinst); 146 size_t member_size = structec_size(ecinst);
147 147
148 ret = read(fd, buf, scount * member_size); 148 ret = read(fd, buf, scount * member_size);
149 structec_convert(buf, ecinst, scount, ec); 149 structec_convert(buf, ecinst, scount, ec);
150 150
151 return ret; 151 return ret;
152} 152}
153 153
154/** 154/**
155 * Writes endianess corrected structure members to the given file. 155 * Writes endianess corrected structure members to the given file.
156 * 156 *
157 * @param fd file descriptor of the file being written to. 157 * @param fd file descriptor of the file being written to.
158 * @param buf endianess corrected data is read here. 158 * @param buf endianess corrected data is read here.
159 * @param scount the number of struct members to write. 159 * @param scount the number of struct members to write.
160 * @param ecinst endianess correction string. 160 * @param ecinst endianess correction string.
161 * @param ec if true, endianess correction is enabled. 161 * @param ec if true, endianess correction is enabled.
162 */ 162 */
163ssize_t ecwrite(int fd, const void *buf, size_t scount, 163ssize_t ecwrite(int fd, const void *buf, size_t scount,
164 const char *ecinst, bool ec) 164 const char *ecinst, bool ec)
165{ 165{
166 char tmp[MAX_STRUCT_SIZE]; 166 char tmp[MAX_STRUCT_SIZE];
@@ -171,20 +171,19 @@ ssize_t ecwrite(int fd, const void *buf, size_t scount,
171 const char *p = (const char *)buf; 171 const char *p = (const char *)buf;
172 int maxamount = (int)(MAX_STRUCT_SIZE / member_size); 172 int maxamount = (int)(MAX_STRUCT_SIZE / member_size);
173 int i; 173 int i;
174 174
175 for (i = 0; i < (long)scount; i += maxamount) 175 for (i = 0; i < (long)scount; i += maxamount)
176 { 176 {
177 long amount = MIN((int)scount-i, maxamount); 177 long amount = MIN((int)scount-i, maxamount);
178 178
179 memcpy(tmp, p, member_size * amount); 179 memcpy(tmp, p, member_size * amount);
180 structec_convert(tmp, ecinst, amount, true); 180 structec_convert(tmp, ecinst, amount, true);
181 write(fd, tmp, amount * member_size); 181 write(fd, tmp, amount * member_size);
182 p += member_size * amount; 182 p += member_size * amount;
183 } 183 }
184 184
185 return scount * member_size; 185 return scount * member_size;
186 } 186 }
187 187
188 return write(fd, buf, scount * member_size); 188 return write(fd, buf, scount * member_size);
189} 189}
190