Remove long_u: put_bytes(): Refactor.

Remove all long_u instances due to put_bytes() function.

First, function signature is changed this way:
- nr  : long_u --> uintmax_t
    uintmax_t is chosen so that invocations can use any unsigned integer
    type (including size_t) without needing to cast.
- len : int    --> unsigned int
    This is to pass the size in bytes of the previous param, thus an
    unsigned int is enough. All invocations use positive integer
    literals, so change is safe without the need for casts.

Then, function implementation is adapted accordingly.

Last, all invocation points are refactored this way:
- Refactor types to minimize casts.
- Inline declarations (C99 style) in containing function.

All this changes were done with -Wconversion temporarily activated for
spell.c and undo.c, so that we can assert changes are type-safe and do
not introduce any warnings to that respect.
This commit is contained in:
Eliseo Martínez
2014-12-21 12:36:16 +01:00
parent 59985523b8
commit d2745a59f8
3 changed files with 161 additions and 194 deletions

View File

@@ -501,15 +501,12 @@ char *read_string(FILE *fd, size_t cnt)
return (char *)str;
}
/*
* Write a number to file "fd", MSB first, in "len" bytes.
*/
int put_bytes(FILE *fd, long_u nr, int len)
/// Write a number to file "fd", MSB first, in "len" bytes.
/// @return OK/FAIL.
int put_bytes(FILE *fd, uintmax_t number, unsigned int len)
{
int i;
for (i = len - 1; i >= 0; --i)
if (putc((int)(nr >> (i * 8)), fd) == EOF)
for (unsigned int i = len - 1; i < len; --i)
if (putc((int)(number >> (i * 8)), fd) == EOF)
return FAIL;
return OK;
}