mirror of
https://git.zap.org.au/git/trader.git
synced 2024-10-27 18:20:13 -04:00
Add the restrict keyword where appropriate
This commit is contained in:
parent
6ee474e438
commit
b3f1820418
11
src/utils.c
11
src/utils.c
@ -199,7 +199,7 @@ char *game_filename (int gamenum)
|
|||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
// err_exit: Print an error and exit
|
// err_exit: Print an error and exit
|
||||||
|
|
||||||
void err_exit (const char *format, ...)
|
void err_exit (const char *restrict format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ void err_exit (const char *format, ...)
|
|||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
// errno_exit: Print an error message (using errno) and exit
|
// errno_exit: Print an error message (using errno) and exit
|
||||||
|
|
||||||
void errno_exit (const char *format, ...)
|
void errno_exit (const char *restrict format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
int saved_errno = errno;
|
int saved_errno = errno;
|
||||||
@ -399,7 +399,7 @@ ssize_t l_strfmon (char *restrict s, size_t maxsize,
|
|||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
// scramble: Scramble (encrypt) the buffer
|
// scramble: Scramble (encrypt) the buffer
|
||||||
|
|
||||||
char *scramble (int key, char *buf, int bufsize)
|
char *scramble (int key, char *restrict buf, int bufsize)
|
||||||
{
|
{
|
||||||
/* The algorithm used here is reversable: scramble(scramble(...))
|
/* The algorithm used here is reversable: scramble(scramble(...))
|
||||||
will (or, at least, should!) return the same as the original
|
will (or, at least, should!) return the same as the original
|
||||||
@ -410,9 +410,8 @@ char *scramble (int key, char *buf, int bufsize)
|
|||||||
if (buf != NULL && key != 0) {
|
if (buf != NULL && key != 0) {
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
unsigned char k = ~key;
|
unsigned char k = ~key;
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < bufsize && *p != '\0'; i++, k++, p++) {
|
for (int i = 0; i < bufsize && *p != '\0'; i++, k++, p++) {
|
||||||
char c = *p;
|
char c = *p;
|
||||||
char r = c ^ k; // Simple encryption: XOR on a moving key
|
char r = c ^ k; // Simple encryption: XOR on a moving key
|
||||||
|
|
||||||
@ -430,7 +429,7 @@ char *scramble (int key, char *buf, int bufsize)
|
|||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
// unscramble: Unscramble (decrypt) the buffer
|
// unscramble: Unscramble (decrypt) the buffer
|
||||||
|
|
||||||
char *unscramble (int key, char *buf, int bufsize)
|
char *unscramble (int key, char *restrict buf, int bufsize)
|
||||||
{
|
{
|
||||||
return scramble(key, buf, bufsize);
|
return scramble(key, buf, bufsize);
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ extern char *game_filename (int gamenum);
|
|||||||
with the user string as a second argument), NOT passed in as the format
|
with the user string as a second argument), NOT passed in as the format
|
||||||
itself.
|
itself.
|
||||||
*/
|
*/
|
||||||
extern void err_exit (const char *format, ...)
|
extern void err_exit (const char *restrict format, ...)
|
||||||
__attribute__((noreturn, format (printf, 1, 2)));
|
__attribute__((noreturn, format (printf, 1, 2)));
|
||||||
|
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ extern void err_exit (const char *format, ...)
|
|||||||
colons nor the trailing end-line character. The format may be NULL if
|
colons nor the trailing end-line character. The format may be NULL if
|
||||||
no intermediate message is needed.
|
no intermediate message is needed.
|
||||||
*/
|
*/
|
||||||
extern void errno_exit (const char *format, ...)
|
extern void errno_exit (const char *restrict format, ...)
|
||||||
__attribute__((noreturn, format (printf, 1, 2)));
|
__attribute__((noreturn, format (printf, 1, 2)));
|
||||||
|
|
||||||
|
|
||||||
@ -278,7 +278,7 @@ extern ssize_t l_strfmon (char *restrict s, size_t maxsize,
|
|||||||
and after encryption. At most bufsize bytes are encrypted; buf is
|
and after encryption. At most bufsize bytes are encrypted; buf is
|
||||||
returned as the result.
|
returned as the result.
|
||||||
*/
|
*/
|
||||||
extern char *scramble (int key, char *buf, int bufsize);
|
extern char *scramble (int key, char *restrict buf, int bufsize);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -297,7 +297,7 @@ extern char *scramble (int key, char *buf, int bufsize);
|
|||||||
will any encrypted character map back to these values). At most
|
will any encrypted character map back to these values). At most
|
||||||
bufsize bytes are decrypted; buf is returned as the result.
|
bufsize bytes are decrypted; buf is returned as the result.
|
||||||
*/
|
*/
|
||||||
extern char *unscramble (int key, char *buf, int bufsize);
|
extern char *unscramble (int key, char *restrict buf, int bufsize);
|
||||||
|
|
||||||
|
|
||||||
#endif /* included_UTILS_H */
|
#endif /* included_UTILS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user