use constant pointers when possible
It is a good practice to constify pointers when their dereferenced data is not modified within the functions or its descendants. git-svn-id: https://svn.musicpd.org/mpd/trunk@7234 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
83e937320b
commit
623a86f389
14
src/listen.c
14
src/listen.c
@ -67,7 +67,7 @@ static void redirect_stdin(void)
|
|||||||
FATAL("dup2 stdin: %s\n", strerror(errno));
|
FATAL("dup2 stdin: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int establishListen(struct sockaddr *addrp, socklen_t addrlen)
|
static int establishListen(const struct sockaddr *addrp, socklen_t addrlen)
|
||||||
{
|
{
|
||||||
int pf;
|
int pf;
|
||||||
int sock;
|
int sock;
|
||||||
@ -121,7 +121,7 @@ static int establishListen(struct sockaddr *addrp, socklen_t addrlen)
|
|||||||
|
|
||||||
static void parseListenConfigParam(unsigned int port, ConfigParam * param)
|
static void parseListenConfigParam(unsigned int port, ConfigParam * param)
|
||||||
{
|
{
|
||||||
struct sockaddr *addrp;
|
const struct sockaddr *addrp;
|
||||||
socklen_t addrlen;
|
socklen_t addrlen;
|
||||||
struct sockaddr_in sin4;
|
struct sockaddr_in sin4;
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
@ -141,14 +141,14 @@ static void parseListenConfigParam(unsigned int port, ConfigParam * param)
|
|||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
if (useIpv6) {
|
if (useIpv6) {
|
||||||
sin6.sin6_addr = in6addr_any;
|
sin6.sin6_addr = in6addr_any;
|
||||||
addrp = (struct sockaddr *)&sin6;
|
addrp = (const struct sockaddr *)&sin6;
|
||||||
addrlen = sizeof(struct sockaddr_in6);
|
addrlen = sizeof(struct sockaddr_in6);
|
||||||
if (establishListen(addrp, addrlen) < 0)
|
if (establishListen(addrp, addrlen) < 0)
|
||||||
BINDERROR();
|
BINDERROR();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
sin4.sin_addr.s_addr = INADDR_ANY;
|
sin4.sin_addr.s_addr = INADDR_ANY;
|
||||||
addrp = (struct sockaddr *)&sin4;
|
addrp = (const struct sockaddr *)&sin4;
|
||||||
addrlen = sizeof(struct sockaddr_in);
|
addrlen = sizeof(struct sockaddr_in);
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
if ((establishListen(addrp, addrlen) < 0) && !useIpv6) {
|
if ((establishListen(addrp, addrlen) < 0) && !useIpv6) {
|
||||||
@ -173,14 +173,14 @@ static void parseListenConfigParam(unsigned int port, ConfigParam * param)
|
|||||||
param->value, param->line);
|
param->value, param->line);
|
||||||
}
|
}
|
||||||
memcpy((char *)&sin6.sin6_addr.s6_addr,
|
memcpy((char *)&sin6.sin6_addr.s6_addr,
|
||||||
(char *)he->h_addr, he->h_length);
|
(const char *)he->h_addr, he->h_length);
|
||||||
addrp = (struct sockaddr *)&sin6;
|
addrp = (const struct sockaddr *)&sin6;
|
||||||
addrlen = sizeof(struct sockaddr_in6);
|
addrlen = sizeof(struct sockaddr_in6);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
memcpy((char *)&sin4.sin_addr.s_addr,
|
memcpy((char *)&sin4.sin_addr.s_addr,
|
||||||
(char *)he->h_addr, he->h_length);
|
(const char *)he->h_addr, he->h_length);
|
||||||
addrp = (struct sockaddr *)&sin4;
|
addrp = (struct sockaddr *)&sin4;
|
||||||
addrlen = sizeof(struct sockaddr_in);
|
addrlen = sizeof(struct sockaddr_in);
|
||||||
break;
|
break;
|
||||||
|
@ -74,15 +74,15 @@ void pcm_volumeChange(char *buffer, int bufferSize, AudioFormat * format,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pcm_add(char *buffer1, char *buffer2, size_t bufferSize1,
|
static void pcm_add(char *buffer1, const char *buffer2, size_t bufferSize1,
|
||||||
size_t bufferSize2, int vol1, int vol2,
|
size_t bufferSize2, int vol1, int vol2,
|
||||||
AudioFormat * format)
|
const AudioFormat * format)
|
||||||
{
|
{
|
||||||
mpd_sint32 temp32;
|
mpd_sint32 temp32;
|
||||||
mpd_sint8 *buffer8_1 = (mpd_sint8 *) buffer1;
|
mpd_sint8 *buffer8_1 = (mpd_sint8 *) buffer1;
|
||||||
mpd_sint8 *buffer8_2 = (mpd_sint8 *) buffer2;
|
const mpd_sint8 *buffer8_2 = (const mpd_sint8 *) buffer2;
|
||||||
mpd_sint16 *buffer16_1 = (mpd_sint16 *) buffer1;
|
mpd_sint16 *buffer16_1 = (mpd_sint16 *) buffer1;
|
||||||
mpd_sint16 *buffer16_2 = (mpd_sint16 *) buffer2;
|
const mpd_sint16 *buffer16_2 = (const mpd_sint16 *) buffer2;
|
||||||
|
|
||||||
switch (format->bits) {
|
switch (format->bits) {
|
||||||
case 16:
|
case 16:
|
||||||
@ -129,8 +129,8 @@ static void pcm_add(char *buffer1, char *buffer2, size_t bufferSize1,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pcm_mix(char *buffer1, char *buffer2, size_t bufferSize1,
|
void pcm_mix(char *buffer1, const char *buffer2, size_t bufferSize1,
|
||||||
size_t bufferSize2, AudioFormat * format, float portion1)
|
size_t bufferSize2, const AudioFormat * format, float portion1)
|
||||||
{
|
{
|
||||||
int vol1;
|
int vol1;
|
||||||
float s = sin(M_PI_2 * portion1);
|
float s = sin(M_PI_2 * portion1);
|
||||||
@ -351,8 +351,8 @@ static char *pcm_convertChannels(mpd_sint8 channels, char *inBuffer,
|
|||||||
return outBuffer;
|
return outBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *pcm_convertTo16bit(mpd_sint8 bits, char *inBuffer, size_t inSize,
|
static char *pcm_convertTo16bit(mpd_sint8 bits, const char *inBuffer,
|
||||||
size_t *outSize)
|
size_t inSize, size_t *outSize)
|
||||||
{
|
{
|
||||||
static char *buf;
|
static char *buf;
|
||||||
static size_t len;
|
static size_t len;
|
||||||
@ -378,8 +378,7 @@ static char *pcm_convertTo16bit(mpd_sint8 bits, char *inBuffer, size_t inSize,
|
|||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
*outSize = inSize;
|
*outSize = inSize;
|
||||||
outBuffer = inBuffer;
|
return inBuffer;
|
||||||
break;
|
|
||||||
case 24:
|
case 24:
|
||||||
/* put dithering code from mp3_decode here */
|
/* put dithering code from mp3_decode here */
|
||||||
default:
|
default:
|
||||||
@ -390,7 +389,7 @@ static char *pcm_convertTo16bit(mpd_sint8 bits, char *inBuffer, size_t inSize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* outFormat bits must be 16 and channels must be 1 or 2! */
|
/* outFormat bits must be 16 and channels must be 1 or 2! */
|
||||||
size_t pcm_convertAudioFormat(AudioFormat * inFormat, char *inBuffer,
|
size_t pcm_convertAudioFormat(AudioFormat * inFormat, const char *inBuffer,
|
||||||
size_t inSize, AudioFormat * outFormat,
|
size_t inSize, AudioFormat * outFormat,
|
||||||
char *outBuffer, ConvState *convState)
|
char *outBuffer, ConvState *convState)
|
||||||
{
|
{
|
||||||
@ -427,8 +426,8 @@ size_t pcm_convertAudioFormat(AudioFormat * inFormat, char *inBuffer,
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t pcm_sizeOfConvBuffer(AudioFormat * inFormat, size_t inSize,
|
size_t pcm_sizeOfConvBuffer(const AudioFormat * inFormat, size_t inSize,
|
||||||
AudioFormat * outFormat)
|
const AudioFormat * outFormat)
|
||||||
{
|
{
|
||||||
const double ratio = (double)outFormat->sampleRate /
|
const double ratio = (double)outFormat->sampleRate /
|
||||||
(double)inFormat->sampleRate;
|
(double)inFormat->sampleRate;
|
||||||
|
@ -45,13 +45,13 @@ typedef struct _ConvState {
|
|||||||
void pcm_volumeChange(char *buffer, int bufferSize, AudioFormat * format,
|
void pcm_volumeChange(char *buffer, int bufferSize, AudioFormat * format,
|
||||||
int volume);
|
int volume);
|
||||||
|
|
||||||
void pcm_mix(char *buffer1, char *buffer2, size_t bufferSize1,
|
void pcm_mix(char *buffer1, const char *buffer2, size_t bufferSize1,
|
||||||
size_t bufferSize2, AudioFormat * format, float portion1);
|
size_t bufferSize2, const AudioFormat * format, float portion1);
|
||||||
|
|
||||||
size_t pcm_convertAudioFormat(AudioFormat * inFormat, char *inBuffer,
|
size_t pcm_convertAudioFormat(AudioFormat * inFormat, const char *inBuffer,
|
||||||
size_t inSize, AudioFormat * outFormat,
|
size_t inSize, AudioFormat * outFormat,
|
||||||
char *outBuffer, ConvState *convState);
|
char *outBuffer, ConvState *convState);
|
||||||
|
|
||||||
size_t pcm_sizeOfConvBuffer(AudioFormat * inFormat, size_t inSize,
|
size_t pcm_sizeOfConvBuffer(const AudioFormat * inFormat, size_t inSize,
|
||||||
AudioFormat * outFormat);
|
const AudioFormat * outFormat);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user