Whitespace fixes in firmware/common/structec.c
Change-Id: I2a6c5d5bd0c5b8fb516e167df74dc1f18508d702
This commit is contained in:
parent
c4bf2e3cfd
commit
08724860a8
1 changed files with 23 additions and 24 deletions
|
@ -30,32 +30,32 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the struct endianess with the instructions provided.
|
* Convert the struct endianess with the instructions provided.
|
||||||
*
|
*
|
||||||
* For example:
|
* For example:
|
||||||
* struct test {
|
* struct test {
|
||||||
* long par1;
|
* long par1;
|
||||||
* short par2;
|
* short par2;
|
||||||
* short par3;
|
* short par3;
|
||||||
* };
|
* };
|
||||||
*
|
*
|
||||||
* structec_convert(instance_of_test, "lss", sizeof(struct test), true);
|
* structec_convert(instance_of_test, "lss", sizeof(struct test), true);
|
||||||
*
|
*
|
||||||
* Structures to be converted must be properly padded.
|
* Structures to be converted must be properly padded.
|
||||||
*
|
*
|
||||||
* @param structure Pointer to the struct being converted.
|
* @param structure Pointer to the struct being converted.
|
||||||
* @param ecinst Instructions how to do the endianess conversion.
|
* @param ecinst Instructions how to do the endianess conversion.
|
||||||
* @param count Number of structures to write
|
* @param count Number of structures to write
|
||||||
* @param enable Conversion is not made unless this is true.
|
* @param enable Conversion is not made unless this is true.
|
||||||
*/
|
*/
|
||||||
void structec_convert(void *structure, const char *ecinst,
|
void structec_convert(void *structure, const char *ecinst,
|
||||||
long count, bool enable)
|
long count, bool enable)
|
||||||
{
|
{
|
||||||
const char *ecinst_ring = ecinst;
|
const char *ecinst_ring = ecinst;
|
||||||
char *buf = (char *)structure;
|
char *buf = (char *)structure;
|
||||||
|
|
||||||
if (!enable)
|
if (!enable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (count > 0)
|
while (count > 0)
|
||||||
{
|
{
|
||||||
switch (*ecinst_ring)
|
switch (*ecinst_ring)
|
||||||
|
@ -66,7 +66,7 @@ void structec_convert(void *structure, const char *ecinst,
|
||||||
buf++;
|
buf++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Swap 2 bytes. */
|
/* Swap 2 bytes. */
|
||||||
case 's':
|
case 's':
|
||||||
{
|
{
|
||||||
|
@ -84,7 +84,7 @@ void structec_convert(void *structure, const char *ecinst,
|
||||||
buf += 4;
|
buf += 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip N bytes, idea taken from metadata.c */
|
/* Skip N bytes, idea taken from metadata.c */
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
@ -94,7 +94,7 @@ void structec_convert(void *structure, const char *ecinst,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ecinst_ring++;
|
ecinst_ring++;
|
||||||
if (*ecinst_ring == '\0')
|
if (*ecinst_ring == '\0')
|
||||||
{
|
{
|
||||||
|
@ -107,14 +107,14 @@ void structec_convert(void *structure, const char *ecinst,
|
||||||
/**
|
/**
|
||||||
* Determines the size of a struct in bytes by using endianess correction
|
* Determines the size of a struct in bytes by using endianess correction
|
||||||
* string format.
|
* string format.
|
||||||
*
|
*
|
||||||
* @param ecinst endianess correction string.
|
* @param ecinst endianess correction string.
|
||||||
* @return length of the struct in bytes.
|
* @return length of the struct in bytes.
|
||||||
*/
|
*/
|
||||||
static size_t structec_size(const char *ecinst)
|
static size_t structec_size(const char *ecinst)
|
||||||
{
|
{
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
switch (*ecinst)
|
switch (*ecinst)
|
||||||
|
@ -122,18 +122,18 @@ static size_t structec_size(const char *ecinst)
|
||||||
case 'c': size += 1; break;
|
case 'c': size += 1; break;
|
||||||
case 's': size += 2; break;
|
case 's': size += 2; break;
|
||||||
case 'l': size += 4; break;
|
case 'l': size += 4; break;
|
||||||
default:
|
default:
|
||||||
if (isdigit(*ecinst))
|
if (isdigit(*ecinst))
|
||||||
size += (*ecinst - '0');
|
size += (*ecinst - '0');
|
||||||
}
|
}
|
||||||
} while (*(++ecinst) != '\0');
|
} while (*(++ecinst) != '\0');
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads endianess corrected structure members from the given file.
|
* Reads endianess corrected structure members from the given file.
|
||||||
*
|
*
|
||||||
* @param fd file descriptor of the file being read.
|
* @param fd file descriptor of the file being read.
|
||||||
* @param buf endianess corrected data is placed here.
|
* @param buf endianess corrected data is placed here.
|
||||||
* @param scount the number of struct members to read.
|
* @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)
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
size_t member_size = structec_size(ecinst);
|
size_t member_size = structec_size(ecinst);
|
||||||
|
|
||||||
ret = read(fd, buf, scount * member_size);
|
ret = read(fd, buf, scount * member_size);
|
||||||
structec_convert(buf, ecinst, scount, ec);
|
structec_convert(buf, ecinst, scount, ec);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes endianess corrected structure members to the given file.
|
* Writes endianess corrected structure members to the given file.
|
||||||
*
|
*
|
||||||
* @param fd file descriptor of the file being written to.
|
* @param fd file descriptor of the file being written to.
|
||||||
* @param buf endianess corrected data is read here.
|
* @param buf endianess corrected data is read here.
|
||||||
* @param scount the number of struct members to write.
|
* @param scount the number of struct members to write.
|
||||||
* @param ecinst endianess correction string.
|
* @param ecinst endianess correction string.
|
||||||
* @param ec if true, endianess correction is enabled.
|
* @param ec if true, endianess correction is enabled.
|
||||||
*/
|
*/
|
||||||
ssize_t ecwrite(int fd, const void *buf, size_t scount,
|
ssize_t ecwrite(int fd, const void *buf, size_t scount,
|
||||||
const char *ecinst, bool ec)
|
const char *ecinst, bool ec)
|
||||||
{
|
{
|
||||||
char tmp[MAX_STRUCT_SIZE];
|
char tmp[MAX_STRUCT_SIZE];
|
||||||
|
@ -171,20 +171,19 @@ ssize_t ecwrite(int fd, const void *buf, size_t scount,
|
||||||
const char *p = (const char *)buf;
|
const char *p = (const char *)buf;
|
||||||
int maxamount = (int)(MAX_STRUCT_SIZE / member_size);
|
int maxamount = (int)(MAX_STRUCT_SIZE / member_size);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < (long)scount; i += maxamount)
|
for (i = 0; i < (long)scount; i += maxamount)
|
||||||
{
|
{
|
||||||
long amount = MIN((int)scount-i, maxamount);
|
long amount = MIN((int)scount-i, maxamount);
|
||||||
|
|
||||||
memcpy(tmp, p, member_size * amount);
|
memcpy(tmp, p, member_size * amount);
|
||||||
structec_convert(tmp, ecinst, amount, true);
|
structec_convert(tmp, ecinst, amount, true);
|
||||||
write(fd, tmp, amount * member_size);
|
write(fd, tmp, amount * member_size);
|
||||||
p += member_size * amount;
|
p += member_size * amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
return scount * member_size;
|
return scount * member_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return write(fd, buf, scount * member_size);
|
return write(fd, buf, scount * member_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue