Fix sparse warnings and add an extra sprinkling of const.
This is more or less the equivalent of Sven-Haegar Koch's fixes in the 1.1 branch.
This commit is contained in:
parent
07ffb1a198
commit
6d08eb1614
35 changed files with 83 additions and 75 deletions
|
@ -27,6 +27,8 @@
|
|||
|
||||
#include "system.h"
|
||||
|
||||
#include "pidfile.h"
|
||||
|
||||
#ifndef HAVE_MINGW
|
||||
/* read_pid
|
||||
*
|
||||
|
@ -34,7 +36,7 @@
|
|||
* 0 is returned if either there's no pidfile, it's empty
|
||||
* or no pid can be read.
|
||||
*/
|
||||
pid_t read_pid (char *pidfile)
|
||||
pid_t read_pid (const char *pidfile)
|
||||
{
|
||||
FILE *f;
|
||||
long pid;
|
||||
|
@ -53,7 +55,7 @@ pid_t read_pid (char *pidfile)
|
|||
* table (using /proc) to determine if the process already exists. If
|
||||
* so the pid is returned, otherwise 0.
|
||||
*/
|
||||
pid_t check_pid (char *pidfile)
|
||||
pid_t check_pid (const char *pidfile)
|
||||
{
|
||||
pid_t pid = read_pid(pidfile);
|
||||
|
||||
|
@ -79,7 +81,7 @@ pid_t check_pid (char *pidfile)
|
|||
* Writes the pid to the specified file. If that fails 0 is
|
||||
* returned, otherwise the pid.
|
||||
*/
|
||||
pid_t write_pid (char *pidfile)
|
||||
pid_t write_pid (const char *pidfile)
|
||||
{
|
||||
FILE *f;
|
||||
int fd;
|
||||
|
@ -124,7 +126,7 @@ pid_t write_pid (char *pidfile)
|
|||
* Remove the the specified file. The result from unlink(2)
|
||||
* is returned
|
||||
*/
|
||||
int remove_pid (char *pidfile)
|
||||
int remove_pid (const char *pidfile)
|
||||
{
|
||||
return unlink (pidfile);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* 0 is returned if either there's no pidfile, it's empty
|
||||
* or no pid can be read.
|
||||
*/
|
||||
pid_t read_pid (char *pidfile);
|
||||
extern pid_t read_pid (const char *pidfile);
|
||||
|
||||
/* check_pid
|
||||
*
|
||||
|
@ -34,19 +34,19 @@ pid_t read_pid (char *pidfile);
|
|||
* table (using /proc) to determine if the process already exists. If
|
||||
* so 1 is returned, otherwise 0.
|
||||
*/
|
||||
pid_t check_pid (char *pidfile);
|
||||
extern pid_t check_pid (const char *pidfile);
|
||||
|
||||
/* write_pid
|
||||
*
|
||||
* Writes the pid to the specified file. If that fails 0 is
|
||||
* returned, otherwise the pid.
|
||||
*/
|
||||
pid_t write_pid (char *pidfile);
|
||||
extern pid_t write_pid (const char *pidfile);
|
||||
|
||||
/* remove_pid
|
||||
*
|
||||
* Remove the the specified file. The result from unlink(2)
|
||||
* is returned
|
||||
*/
|
||||
int remove_pid (char *pidfile);
|
||||
extern int remove_pid (const char *pidfile);
|
||||
#endif
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
#include "../src/logger.h"
|
||||
#include "utils.h"
|
||||
|
||||
const char hexadecimals[] = "0123456789ABCDEF";
|
||||
static const char hexadecimals[] = "0123456789ABCDEF";
|
||||
|
||||
int charhex2bin(char c) {
|
||||
static int charhex2bin(char c) {
|
||||
if(isdigit(c))
|
||||
return c - '0';
|
||||
else
|
||||
|
@ -67,7 +67,7 @@ const char *winerror(int err) {
|
|||
}
|
||||
#endif
|
||||
|
||||
unsigned int bitfield_to_int(void *bitfield, size_t size) {
|
||||
unsigned int bitfield_to_int(const void *bitfield, size_t size) {
|
||||
unsigned int value = 0;
|
||||
if(size > sizeof value)
|
||||
size = sizeof value;
|
||||
|
|
|
@ -40,6 +40,6 @@ extern const char *winerror(int);
|
|||
#define sockinprogress(x) ((x) == EINPROGRESS)
|
||||
#endif
|
||||
|
||||
extern unsigned int bitfield_to_int(void *bitfield, size_t size);
|
||||
extern unsigned int bitfield_to_int(const void *bitfield, size_t size);
|
||||
|
||||
#endif /* __TINC_UTILS_H__ */
|
||||
|
|
|
@ -16,7 +16,7 @@ extern int xalloc_exit_failure;
|
|||
extern char *const xalloc_msg_memory_exhausted;
|
||||
|
||||
/* FIXME: describe */
|
||||
extern void (*xalloc_fail_func) ();
|
||||
extern void (*xalloc_fail_func) (int);
|
||||
|
||||
void *xmalloc PARAMS ((size_t n)) __attribute__ ((__malloc__));
|
||||
void *xmalloc_and_zero PARAMS ((size_t n)) __attribute__ ((__malloc__));
|
||||
|
|
|
@ -56,7 +56,7 @@ int xalloc_exit_failure = EXIT_FAILURE;
|
|||
char *const xalloc_msg_memory_exhausted = "Memory exhausted";
|
||||
|
||||
/* FIXME: describe */
|
||||
void (*xalloc_fail_func) (int) = 0;
|
||||
void (*xalloc_fail_func) (int) = NULL;
|
||||
|
||||
static void
|
||||
xalloc_fail (int size)
|
||||
|
@ -70,13 +70,12 @@ xalloc_fail (int size)
|
|||
/* Allocate N bytes of memory dynamically, with error checking. */
|
||||
|
||||
void *
|
||||
xmalloc (n)
|
||||
size_t n;
|
||||
xmalloc (size_t n)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = malloc (n);
|
||||
if (p == 0)
|
||||
if (p == NULL)
|
||||
xalloc_fail ((int)n);
|
||||
return p;
|
||||
}
|
||||
|
@ -84,13 +83,12 @@ xmalloc (n)
|
|||
/* Allocate N bytes of memory dynamically, and set it all to zero. */
|
||||
|
||||
void *
|
||||
xmalloc_and_zero (n)
|
||||
size_t n;
|
||||
xmalloc_and_zero (size_t n)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = malloc (n);
|
||||
if (p == 0)
|
||||
if (p == NULL)
|
||||
xalloc_fail ((int)n);
|
||||
memset (p, '\0', n);
|
||||
return p;
|
||||
|
@ -101,12 +99,10 @@ xmalloc_and_zero (n)
|
|||
If P is NULL, run xmalloc. */
|
||||
|
||||
void *
|
||||
xrealloc (p, n)
|
||||
void *p;
|
||||
size_t n;
|
||||
xrealloc (void *p, size_t n)
|
||||
{
|
||||
p = realloc (p, n);
|
||||
if (p == 0)
|
||||
if (p == NULL)
|
||||
xalloc_fail (n);
|
||||
return p;
|
||||
}
|
||||
|
@ -134,7 +130,7 @@ xcalloc (n, s)
|
|||
void *p;
|
||||
|
||||
p = calloc (n, s);
|
||||
if (p == 0)
|
||||
if (p == NULL)
|
||||
xalloc_fail ();
|
||||
return p;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue