Commit 79382483 authored by Led's avatar Led

0.12.0rc4

parent 72609e68
ver 0.12.0 (2006/??/??)
* New audio output code which supports:
* A plugin-like architecture
* Non-libao ("native") outputs:
* ALSA
* OSS
* OS X
* Sun
* Media MVP
* PulseAudio
* Shout (Icecast or Shoutcast)
* Playing through multiple outputs at once
* Enabling/disabling outputs while MPD is running
* Saving output state (enabled/disabled) to the state_file
* OggFLAC support
* Musepack support
* Gapless MP3 playback
* MP3 ReplayGain support (using ID3v2 tags only)
* Support for MP2 files if MP3 support is enabled
* Composer, Performer, Comment, and Disc metadata support
* New outputs command for listing available audio outputs
* New enableoutput and disableoutput commands for enabling/disabling outputs
* New plchangesposid command for a stripped down version of plchanges
* New addid command for adding to the playlist and returning a song ID
* New commands and notcommands commands for checking available commands
* Can now specify any supported metadata type or "any" in search, find, and list
* New volume_normalization parameter for enabling Audio Compress normalization
* New metadata_to_use parameter for choosing supported metadata types
* New pid_file parameter for saving the MPD process ID to the specified file
* The db_file parameter is now required
* The port parameter is now optional (defaults to 6600)
* Can specify bind_to_address multiple times
* New --kill argument for killing MPD if pid_file is specified
* Removed --update-db argument (use the update function in your client instead)
* New mpdconf.example
* New mpd.conf man page
* Removed bundled libmad and libid3tag
* Lots of bug fixes, cleaned up code, and performance improvements
ver 0.11.5 (2004/11/1)
1) New id3v1_ecnoding config option to configure the id3v1 tag encoding (patch from dottemag)
1) New id3v1_encoding config option to configure the id3v1 tag encoding (patch from dottedmag)
2) Strip '\r' from m3u playlists (thank you windows)
3) Use random() instead of rand() for playlist randomizing
4) Fix a bug trying skipping some commented lines in m3u playlist files
......
Music Player Daemon (MPD) - INSTALL
Requirements
------------
Optional Output Dependencies
----------------------------
libao - http://www.vorbis.com/download_unix.psp
(This comes with most/all distributions. Make sure you have both
the ao libs and development packages for your distribution installed.
For Red Hat 8.0, the necessary packages are: libao and libao-devel)
You will need at least one of these to compile MPD.
zlib - http://www.gzip.org/zlib
(This comes with all distributions. Make sure you have bot the zlib libs
and development packages for your distribution installed. For Red hat,
the necessary packages are: zlib and zlib-devel)
Most of these are available as packages on major distributions. Be sure to
install both the library package as well as the development package.
Optional
--------
AO - http://www.xiph.org/ao/
A portable library that abstracts many audio output types as one API. Should
be used only if there is no native plugin available or if the native plugin
doesn't work. You will need libao.
ALSA - http://www.alsa-project.org/
The Advanced Linux Sound Architecture. Recommended audio output if you use
Linux. You will need libasound.
PulseAudio - http://www.pulseaudio.org/
An advanced sound daemon. You will need libpulse.
libshout - http://www.icecast.org/
For streaming to an Icecast or Shoutcast server.
Optional Input Dependencies
---------------------------
You will need at least one of these to compile MPD.
Most of these are available as packages on major distributions. Be sure to
install both the library package as well as the development package.
MAD - http://www.underbit.com/products/mad/
For MP3 support. You will need libmad, and optionally libid3tag if you want
ID3 tag support.
Ogg Vorbis - http://www.xiph.org/ogg/vorbis/
(This comes with most/all distributions. Make sure you have both the
ogg and vorbis libs as well as the development packages for your
distribution installed. For Red Hat 8.0, the necessary packages are:
libogg, libogg-devel, libvorbis, and libvorbis-devel).
For Ogg Vorbis support. You will need libogg and libvorbis.
FLAC - http://flac.sourceforge.net/
For FLAC support. You will need version 1.1.0 or higher of libflac.
Flac - http://flac.sf.net
For Flac support, you need Flac 1.1.0 or greater.
OggFLAC - http://www.xiph.org/ogg/vorbis/ and http://flac.sourceforge.net/
For OggFLAC support. You will need liboggflac, which can be built from the
FLAC sources if libogg is already installed.
FAAD2 - http://faac.sf.net
For MP4/AAC support.
Audio File - http://www.68k.org/~michael/audiofile/
For WAVE, AIFF, and AU support. You will need libaudiofile.
Audiofile - http://www.68k.org/~michael/audiofile/
For wave, aiff, and au support.
FAAD2 - http://www.audiocoding.com/
For MP4/AAC support. You will need libmp4ff.
libmikmod - http://mikmod.raphnet.net/
For Mod support.
libmpcdec - http://www.musepack.net/
For Musepack support.
MikMod - http://mikmod.raphnet.net/
For MOD support. You will need libmikmod.
Download
--------
Get the latest release from of MPD from http://www.musicpd.org
Get the latest release from of MPD from <http://www.musicpd.org/>.
Compile
-------
......@@ -46,6 +69,10 @@ Compile
$ tar zxvf mpd-x.x.x.tar.gz
or
$ tar jxvf mpd-x.x.x.tar.bz2
2) change to directory created
$ cd mpd-x.x.x
......@@ -68,24 +95,6 @@ Run
---
1) run mpd:
<port>: port number daemon listens on (if running as a user, this should be
greater than 1024)
<mp3 directory>: directory containing mp3's
<playlist directory>: directory where playlists will be stored (and .mpddb will
be placed)
<mpd log>: log file for mpd
<mpd err>: error log file for mpd
$ mpd <port> <mp3 directory> <playlist directory> <mpd log> <mpd err>
example where mpd executable is in mpd-x.x.x directory:
$ mpd-x.x.x/mpd 6600 mp3 playlists mpd.log mpd.err
Note: The first time you run mpd, it will "explore" your mp3 directory for
mp3's.
Also, mpd can alternatively use config file. In this case,
run mpd like this:
$ mpd <config file>
......@@ -97,12 +106,14 @@ $ mpd playlists/.mpdconf
A sample config file is included with the source of MPD, mpdconf.example .
Note: The first time you run mpd, it will "explore" your mp3 directory for
mp3's.
Using MPD
---------
You can download a web interface (phpMp) to MPD at
http://www.musicpd.org .
You can download a web interface (phpMp) to MPD at <http://www.musicpd.org/>.
Also, several other clients can be found for MPD at http://www.musicpd.org .
Also, several other clients can be found for MPD at <http://www.musicpd.org/>.
MPD can be interfaced directly using telnet (see COMMANDS, if you are brave).
......@@ -2,7 +2,6 @@
----
*) data structures
*) add 2-3 tree for sorted data structures
*) remove changes made to linked list for TagTracker
*) input plugins
......@@ -23,9 +22,6 @@
*) cleanup input plugins "API"
*) cleanup output plugins "API"
*) input plugins
*) Handle mp1 and mp2 files (including files with mp3 suffixes)
*) add error codes for status->error
*) Cleanup Config File Code
......
Music Player Daemon (MPD) - UPGRADING
Upgrading to 0.12.0
-------------------
The ao_driver and ao_driver_options config parameters have been removed and
replaced with the audio_output config section. You will have to update your
config file to use this instead. See the mpd.conf man page or the new
mpdconf.example for details on specifying audio_output sections.
The db_file parameter is no longer optional. If you did not specify it in your
old config file then you will have to add it in order to run 0.12.0.
Support for OggFLAC and Musepack audio files has been added. Additionally,
scanning of MP3 files has been improved. To make use of these updates it is
highly recommended that you run mpd --create-db to recreate your entire
database.
Upgrading to 0.11.0
-------------------
......
......@@ -7657,7 +7657,8 @@ installed software in a non-standard prefix.
_PKG_TEXT
])],
[$4])
[AC_MSG_RESULT([no])
$4])
elif test $pkg_failed = untried; then
ifelse([$4], , [AC_MSG_FAILURE(dnl
[The pkg-config script could not be found or is too old. Make sure it
......@@ -8074,7 +8075,7 @@ AC_ARG_ENABLE(libFLACtest, [ --disable-libFLACtest Do not try to compile
LIBFLAC_CFLAGS="-I$libFLAC_includes"
elif test "x$libFLAC_prefix" != "x" ; then
LIBFLAC_CFLAGS="-I$libFLAC_prefix/include"
elif test "$prefix" != "xNONE"; then
elif test "x$prefix" != "xNONE"; then
LIBFLAC_CFLAGS="-I$prefix/include"
fi
......@@ -8179,7 +8180,7 @@ AC_ARG_ENABLE(libOggFLACtest, [ --disable-libOggFLACtest Do not try to co
LIBOGGFLAC_CFLAGS="-I$libOggFLAC_includes"
elif test "x$libOggFLAC_prefix" != "x" ; then
LIBOGGFLAC_CFLAGS="-I$libOggFLAC_prefix/include"
elif test "$prefix" != "xNONE"; then
elif test "x$prefix" != "xNONE"; then
LIBOGGFLAC_CFLAGS="-I$prefix/include"
fi
......
......@@ -58,9 +58,6 @@
/* Define to 1 if you have the `FLAC' library (-lFLAC). */
#undef HAVE_LIBFLAC
/* Define to 1 if you have the `vorbisidec' library (-lvorbisidec). */
#undef HAVE_LIBVORBISIDEC
/* Define if locale.h is present */
#undef HAVE_LOCALE
......
dnl AC_INIT(src/main.c)
dnl AM_INIT_AUTOMAKE(mpd, 0.12.0rc3)
dnl AM_INIT_AUTOMAKE(mpd, 0.12.0rc4)
AC_PREREQ(2.58)
AC_INIT(mpd, 0.12.0rc3, warren.dukes@gmail.com)
AC_INIT(mpd, 0.12.0rc4, warren.dukes@gmail.com)
AM_INIT_AUTOMAKE($PACKAGE_NAME, $PACKAGE_VERSION)
AC_SUBST(MPD_LIBS)
......@@ -149,12 +149,15 @@ case $host in
enable_osx=yes ;;
esac
if test x$enable_oggvorbis = xno; then
AC_MSG_WARN("disabling shout streaming support because vorbis encoder was not found")
enable_shout=no
elif test x$use_tremor = xyes; then
AC_MSG_WARN("disabling shout streaming support because tremor does not support vorbis encoding")
enable_shout=no
if test x$enable_shout = xyes; then
if test x$enable_oggvorbis = xno; then
AC_MSG_WARN([disabling shout streaming support because vorbis is not enabled])
enable_shout=no
fi
if test x$use_tremor = xyes; then
AC_MSG_WARN([disabling shout streaming support because tremor does not support vorbis encoding])
enable_shout=no
fi
fi
if test x$enable_ao = xyes; then
......@@ -318,7 +321,7 @@ if test x$enable_mpc = xyes; then
if test "x$mpcdec_libraries" != "x" ; then
MPCDEC_LIBS="-L$mpcdec_libraries"
elif test "x$mpcdec_prefix" != "x" ; then
MPCDEC_LIBS="-L$faad_prefix/lib"
MPCDEC_LIBS="-L$mpcdec_prefix/lib"
elif test "x$prefix" != "xNONE"; then
MPCDEC_LIBS="-L$libdir"
fi
......@@ -466,10 +469,6 @@ int main() {
CPPFLAGS=$oldcppflags
fi
if test x$enable_oggvorbis = xyes && test x$use_tremor != xyes; then
XIPH_PATH_OGG(MPD_LIBS="$MPD_LIBS $OGG_LIBS" MPD_CFLAGS="$MPD_CFLAGS $OGG_CFLAGS",enable_oggvorbis=no)
fi
if test x$use_tremor = xyes; then
if test "x$tremor_libraries" != "x" ; then
TREMOR_LIBS="-L$tremor_libraries"
......@@ -490,79 +489,22 @@ if test x$use_tremor = xyes; then
ac_save_LIBS="$LIBS"
CFLAGS="$CFLAGS $TREMOR_CFLAGS"
LIBS="$LIBS $TREMOR_LIBS"
AC_CHECK_LIB(vorbisidec,ov_read,,enable_oggvorbis=no;AC_MSG_WARN([vorbisidec lib needed for ogg support with tremor -- disabling ogg support]))
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
if test x$enable_oggvorbis = xyes; then
if test x$use_tremor = xyes; then
VORBIS_LIBS="$TREMOR_LIBS"
VORBIS_CFLAGS="$TREMOR_CFLAGS"
else
enable_vorbistest=no
XIPH_PATH_VORBIS(,enable_oggvorbis=no)
AC_CHECK_LIB(vorbisidec,ov_read,enable_oggvorbis=yes,enable_oggvorbis=no;AC_MSG_WARN([vorbisidec lib needed for ogg support with tremor -- disabling ogg support]))
if test x$enable_oggvorbis = xno; then
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
elif test x$enable_oggvorbis = xyes; then
XIPH_PATH_OGG(,enable_oggvorbis=no)
XIPH_PATH_VORBIS(,enable_oggvorbis=no)
if test x$enable_oggvorbis = xyes; then
MPD_LIBS="$MPD_LIBS $OGG_LIBS $VORBIS_LIBS $VORBISFILE_LIBS"
MPD_CFLAGS="$MPD_CFLAGS $OGG_CFLAGS $VORBIS_CFLAGS"
dnl
dnl Vorbis Test
dnl vorbistest in XIPH_PATH_OGG is broken on my debian system
dnl so here i used my own hacked up version till i get vorbis-dev gets
dnl upgraded in debian (hopefully when 1.0.1 comes out)
dnl
dnl This version also tests Tremor, which has no vorbistest of its own.
dnl
AC_MSG_CHECKING(that Vorbis is usable)
ac_save_CFLAGS="$CFLAGS"
ac_save_LIBS="$LIBS"
CFLAGS="$CFLAGS $VORBIS_CFLAGS $OGG_CFLAGS"
if test x$use_tremor = xyes; then
CFLAGS="$CFLAGS -DTREMOR"
if test x$enable_shout = xyes; then
MPD_LIBS="$MPD_LIBS $VORBISENC_LIBS"
MPD_CFLAGS="$VORBISFILE_CFLAGS $VORBISENC_CFLAGS"
fi
LIBS="$LIBS $VORBIS_LIBS $VORBISENC_LIBS $OGG_LIBS"
AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef TREMOR
#include <tremor/ivorbisfile.h>
#else
#include <vorbis/codec.h>
#include <vorbis/vorbisenc.h>
#endif
int main ()
{
vorbis_block vb;
vorbis_dsp_state vd;
vorbis_info vi;
vorbis_info_init (&vi);
#ifndef TREMOR
vorbis_encode_init (&vi, 2, 44100, -1, 128, -1);
#endif
/*vorbis_analysis_init (&vd, &vi);
vorbis_block_init (&vd, &vb);*/
/* this function was added in 1.0rc3, so this is what we're testing for */
/*vorbis_bitrate_addblock (&vb);*/
return 0;
}
], AC_MSG_RESULT(yes), [AC_MSG_RESULT(no);enable_oggvorbis=no],[echo $ac_n "cross compiling; assumed OK... $ac_c"])
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
dnl
dnl End of Vorbis Test
dnl
if test x$enable_oggvorbis = xyes; then
MPD_LIBS="$MPD_LIBS $VORBIS_LIBS $VORBISFILE_LIBS $VORBISENC_LIBS"
MPD_CFLAGS="$MPD_CFLAGS $VORBIS_CFLAGS $VORBISFILE_CFLAGS $VORBISENC_CFLAGS"
fi
fi
......@@ -572,7 +514,11 @@ fi
if test x$use_tremor = xyes; then
AC_DEFINE(HAVE_TREMOR,1,[Define to use tremor (libvorbisidec) for ogg support])
fi
if test x$enable_oggflac = xyes; then
AC_MSG_WARN([disabling OggFLAC support because it is incompatible with tremor])
enable_oggflac=no
fi
fi
if test x$enable_flac = xyes; then
oldmpdcflags="$MPD_CFLAGS"
......@@ -695,7 +641,7 @@ if test x$enable_ao = xno &&
test x$enable_osx = xno &&
test x$enable_pulse = xno &&
test x$enable_mvp = xno; then
AC_MSG_ERROR("No Audio Output types configured!")
AC_MSG_ERROR([No Audio Output types configured!])
fi
echo " File Format Support:"
......@@ -768,7 +714,7 @@ if
test x$enable_aac = xno &&
test x$enable_mpc = xno &&
test x$enable_mod = xno; then
AC_MSG_ERROR("No input plugins supported!")
AC_MSG_ERROR([No input plugins supported!])
fi
echo ""
......
......@@ -54,10 +54,44 @@ mpd will be saved to this file when mpd is terminated by a TERM signal or by
the "kill" command. When mpd is restarted, it will read the state file and
restore the state of mpd (including the playlist).
.TP
.B user <username>
This specifies the user that mpd will run as, if set.
.TP
.B bind_to_address <ip address or hostname or any>
This specifies which address mpd binds to and listens on. Multiple
bind_to_address parameters may be specified. The default is "any", which binds
to all available addresses.
.TP
.B port <port>
This specifies the port that mpd listens on. The default is 6600.
.TP
.B log_level <default, secure, or verbose>
This specifies how verbose logs are. "default" is minimal logging, "secure"
reports from what address a connection is opened, and when it is closed, and
"verbose" records excessive amounts of information for debugging purposes. The
default is "default".
.TP
.B password <password@permissions>
This specifies a password for access to mpd. The format is
"password@permissions" where permissions is a comma delimited list composed
of "read", "add", "control", and/or "admin". "read" allows for reading of the
database, displaying the current playlist, and current status of mpd. "add"
allows for adding songs and loading playlists. "control" allows for all other
player and playlist manipulations. "admin" allows the db to be updated and for
the client to kill mpd. An example value is "somePassword@read,add". Multiple
password parameters may be specified.
.TP
.B default_permissions <permissions>
This specifies the permissions of a client that has not been authenticated
using a password. The format of permissions is specified in the description of
the "password" config parameter. If no passwords are specified, the default is
"read,add,control,admin", otherwise it is "" (no permissions).
.TP
.B audio_output
See \fBDESCRIPTION\fP and the various \fBAUDIO OUTPUT PARAMETERS\fP sections
for the format of this parameter. Multiple audio_output parameters may be
specified.
for the format of this parameter. Multiple audio_output sections may be
specified. If no audio_output section is specified, then MPD will scan for a
usable audio output.
.TP
.B audio_output_format <sample_rate:bits:channels>
This specifies the sample rate, bits per sample, and number of channels of
......@@ -79,20 +113,15 @@ This specifies which mixer control to use (sometimes referred to as the
"device"). Examples of mixer controls are PCM, Line1, Master, etc. An example
for OSS is "Pcm", and an example for alsa is "PCM".
.TP
.B filesystem_charset <charset>
This specifies the character set used for the filesystem. A list of supported
character sets can be obtained by running "iconv -l". The default is
determined from the locale when the db was originally created.
.TP
.B replaygain <album or track>
If specified, mpd will adjust the volume of songs played using replaygain tags
If specified, mpd will adjust the volume of songs played using ReplayGain tags
(see <\fBhttp://www.replaygain.org/\fP>). Setting this to "album" will adjust
volume using the album's replaygain tags, while setting it to "track" will
adjust it using the track replaygain tags. Currently only FLAC, Ogg Vorbis,
Musepack, and MP3 (through ID3v2 replaygain tags, not APEv2) are supported.
volume using the album's ReplayGain tags, while setting it to "track" will
adjust it using the track ReplayGain tags. Currently only FLAC, Ogg Vorbis,
Musepack, and MP3 (through ID3v2 ReplayGain tags, not APEv2) are supported.
.TP
.B replaygain_preamp <-15 to 15>
This is the gain (in dB) applied to songs with replaygain tags.
This is the gain (in dB) applied to songs with ReplayGain tags.
.TP
.B volume_normalization <yes or no>
If yes, mpd will normalize the volume of songs as they play. Default is no.
......@@ -125,52 +154,6 @@ If the HTTP proxy server requires authentication, this specifies the username.
.B http_proxy_password <password>
If the HTTP proxy server requires authentication, this specifies the password.
.TP
.B user <username>
This specifies the user that mpd will run as, if set.
.TP
.B bind_to_address <ip address or hostname or any>
This specifies which address mpd binds to and listens on. Multiple
bind_to_address parameters may be specified. The default is "any", which binds
to all available addresses.
.TP
.B port <port>
This specifies the port that mpd listens on. The default is 6600.
.TP
.B password <password@permissions>
This specifies a password for access to mpd. The format is
"password@permissions" where permissions is a comma delimited list composed
of "read", "add", "control", and/or "admin". "read" allows for reading of the
database, displaying the current playlist, and current status of mpd. "add"
allows for adding songs and loading playlists. "control" allows for all other
player and playlist manipulations. "admin" allows the db to be updated and for
the client to kill mpd. An example value is "somePassword@read,add". Multiple
password parameters may be specified.
.TP
.B default_permissions <permissions>
This specifies the permissions of a client that has not been authenticated
using a password. The format of permissions is specified in the description of
the "password" config parameter. If no passwords are specified, the default is
"read,add,control,admin", otherwise it is "" (no permissions).
.TP
.B metadata_to_use <tags>
This specifies the song metadata that will be scanned and made available to
clients. Note that you must recreate (not update) your database for changes to
this parameter to take effect. Possible values are artist, album, title,
track, name, genre, date, composer, performer, comment, and disc. Multiple
tags may be specified as a comma separated list. An example value is
"artist,album,title,track". The special value "none" may be used alone to
disable all metadata. The default is to use all known tag types.
.TP
.B max_playlist_length <number>
This specifies the maximum number of songs that can be in the playlist. The
default is 4096.
.TP
.B log_level <default, secure, or verbose>
This specifies how verbose logs are. "default" is minimal logging, "secure"
reports from what address a connection is opened, and when it is closed, and
"verbose" records excessive amounts of information for debugging purposes. The
default is "default".
.TP
.B connection_timeout <seconds>
If a client does not send any new data in this time period, the connection is
closed. The default is 60.
......@@ -179,6 +162,10 @@ closed. The default is 60.
This specifies the maximum number of clients that can be connected to mpd. The
default is 5.
.TP
.B max_playlist_length <number>
This specifies the maximum number of songs that can be in the playlist. The
default is 4096.
.TP
.B max_command_list_size <size in KiB>
This specifies the maximum size a command list can be. The default is 2048.
.TP
......@@ -186,6 +173,27 @@ This specifies the maximum size a command list can be. The default is 2048.
This specifies the maximum size of the output buffer to a client. The default
is 8192.
.TP
.B filesystem_charset <charset>
This specifies the character set used for the filesystem. A list of supported
character sets can be obtained by running "iconv -l". The default is
determined from the locale when the db was originally created.
.TP
.B id3v1_encoding <charset>
This specifies the character set which ID3v1 tags are encoded in. A list of
supported character sets can be obtained by running "iconv -l". The default is
to let libid3tag convert them (from ISO-8859-1, as the standard specifies) and
do no additional conversion.
.TP
.B metadata_to_use <tags>
This specifies the song metadata that will be scanned and made available to
clients. Note that you must recreate (not update) your database for changes to
this parameter to take effect. Possible values are artist, album, title,
track, name, genre, date, composer, performer, comment, and disc. Multiple
tags may be specified as a comma separated list. An example value is
"artist,album,title,track". The special value "none" may be used alone to
disable all metadata. The default is to use all known tag types except for
comments.
.TP
.B save_absolute_paths_in_playlists <yes or no>
This specifies whether relative or absolute paths for song filenames are used
when saving playlists. The default is "no".
......
......@@ -24,7 +24,6 @@
#include "command.h"
#include "playerData.h"
#include "utils.h"
#include "playlist.h"
#include "state_file.h"
#include <stdlib.h>
......@@ -120,7 +119,7 @@ void initAudioDriver(void)
audioOutputArraySize = audio_device_count();
audioDeviceStates = (getPlayerData())->audioDeviceStates;
audioOutputArray = malloc(sizeof(AudioOutput) * audioOutputArraySize);
audioOutputArray = xmalloc(sizeof(AudioOutput) * audioOutputArraySize);
i = 0;
param = getNextConfigParam(CONF_AUDIO_OUTPUT, param);
......@@ -163,7 +162,7 @@ void initAudioConfig(void)
if (NULL == param || NULL == param->value)
return;
audio_configFormat = malloc(sizeof(AudioFormat));
audio_configFormat = xmalloc(sizeof(AudioFormat));
if (0 != parseAudioConfig(audio_configFormat, param->value)) {
ERROR("error parsing \"%s\" at line %i\n",
......@@ -336,7 +335,7 @@ int openAudioDevice(AudioFormat * audioFormat)
audioBufferSize = (audio_format.bits >> 3) *
audio_format.channels;
audioBufferSize *= audio_format.sampleRate >> 5;
audioBuffer = realloc(audioBuffer, audioBufferSize);
audioBuffer = xrealloc(audioBuffer, audioBufferSize);
}
syncAudioDeviceStates();
......
......@@ -198,7 +198,7 @@ static void convertAudioFormat(AudioOutput * audioOutput, char **chunkArgPtr,
if (size > audioOutput->convBufferLen) {
audioOutput->convBuffer =
realloc(audioOutput->convBuffer, size);
xrealloc(audioOutput->convBuffer, size);
audioOutput->convBufferLen = size;
}
......
......@@ -25,6 +25,7 @@
#include "audio.h"
#include "tag.h"
#include "conf.h"
#include "utils.h"
#define DISABLED_AUDIO_OUTPUT_PLUGIN(plugin) \
AudioOutputPlugin plugin = { \
......
......@@ -59,7 +59,7 @@ typedef struct _AlsaData {
static AlsaData *newAlsaData(void)
{
AlsaData *ret = malloc(sizeof(AlsaData));
AlsaData *ret = xmalloc(sizeof(AlsaData));
ret->device = NULL;
ret->pcmHandle = NULL;
......@@ -85,7 +85,7 @@ static int alsa_initDriver(AudioOutput * audioOutput, ConfigParam * param)
if (param) {
BlockParam *bp = getBlockParam(param, "device");
ad->device = bp ? strdup(bp->value) : strdup("default");
ad->device = bp ? xstrdup(bp->value) : xstrdup("default");
if ((bp = getBlockParam(param, "use_mmap")) &&
(!strcasecmp(bp->value, "yes") ||
......@@ -96,7 +96,7 @@ static int alsa_initDriver(AudioOutput * audioOutput, ConfigParam * param)
if ((bp = getBlockParam(param, "period_time")))
ad->period_time = atoi(bp->value);
} else
ad->device = strdup("default");
ad->device = xstrdup("default");
audioOutput->data = ad;
return 0;
......
......@@ -40,7 +40,7 @@ typedef struct _AoData {
static AoData *newAoData(void)
{
AoData *ret = malloc(sizeof(AoData));
AoData *ret = xmalloc(sizeof(AoData));
ret->device = NULL;
ret->options = NULL;
......@@ -112,9 +112,9 @@ static int audioOutputAo_initDriver(AudioOutput * audioOutput,
blockParam = getBlockParam(param, "options");
if (blockParam) {
dup = strdup(blockParam->value);
dup = xstrdup(blockParam->value);
} else
dup = strdup("");
dup = xstrdup("");
if (strlen(dup)) {
stk1 = NULL;
......
......@@ -109,7 +109,7 @@ static int mvp_testDefault(void)
static int mvp_initDriver(AudioOutput * audioOutput, ConfigParam * param)
{
MvpData *md = malloc(sizeof(MvpData));
MvpData *md = xmalloc(sizeof(MvpData));
md->fd = -1;
audioOutput->data = md;
......
......@@ -164,7 +164,7 @@ static void addSupportedParam(OssData * od, int param, int val)
int index = getIndexForParam(param);
od->numSupported[index]++;
od->supported[index] = realloc(od->supported[index],
od->supported[index] = xrealloc(od->supported[index],
od->numSupported[index] * sizeof(int));
od->supported[index][od->numSupported[index] - 1] = val;
}
......@@ -174,7 +174,7 @@ static void addUnsupportedParam(OssData * od, int param, int val)
int index = getIndexForParam(param);
od->numUnsupported[index]++;
od->unsupported[index] = realloc(od->unsupported[index],
od->unsupported[index] = xrealloc(od->unsupported[index],
od->numUnsupported[index] *
sizeof(int));
od->unsupported[index][od->numUnsupported[index] - 1] = val;
......@@ -193,7 +193,7 @@ static void removeSupportedParam(OssData * od, int param, int val)
}
od->numSupported[index]--;
od->supported[index] = realloc(od->supported[index],
od->supported[index] = xrealloc(od->supported[index],
od->numSupported[index] * sizeof(int));
}
......@@ -210,7 +210,7 @@ static void removeUnsupportedParam(OssData * od, int param, int val)
}
od->numUnsupported[index]--;
od->unsupported[index] = realloc(od->unsupported[index],
od->unsupported[index] = xrealloc(od->unsupported[index],
od->numUnsupported[index] *
sizeof(int));
}
......@@ -254,7 +254,7 @@ static void unsupportParam(OssData * od, int param, int val)
static OssData *newOssData(void)
{
OssData *ret = malloc(sizeof(OssData));
OssData *ret = xmalloc(sizeof(OssData));
ret->device = NULL;
ret->fd = -1;
......@@ -368,7 +368,7 @@ static int oss_open_default(AudioOutput *ao, ConfigParam *param, OssData *od)
else
ERROR("error trying to open default OSS device\n");
for (i = ARRAY_SIZE(default_devices) - 1; i >= 0; --i) {
for (i = ARRAY_SIZE(default_devices); --i >= 0; ) {
const char *dev = default_devices[i];
switch(ret[i]) {
case OSS_STAT_DOESN_T_EXIST:
......
......@@ -40,7 +40,7 @@ typedef struct _OsxData {
static OsxData *newOsxData()
{
OsxData *ret = malloc(sizeof(OsxData));
OsxData *ret = xmalloc(sizeof(OsxData));
pthread_mutex_init(&ret->mutex, NULL);
pthread_cond_init(&ret->condition, NULL);
......@@ -263,8 +263,11 @@ static int osx_openDevice(AudioOutput * audioOutput)
streamDesc.mSampleRate = audioFormat->sampleRate;
streamDesc.mFormatID = kAudioFormatLinearPCM;
streamDesc.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger |
kLinearPCMFormatFlagIsBigEndian;
streamDesc.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
#ifdef WORDS_BIGENDIAN
streamDesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
#endif
streamDesc.mBytesPerPacket =
audioFormat->channels * audioFormat->bits / 8;
streamDesc.mFramesPerPacket = 1;
......@@ -284,7 +287,7 @@ static int osx_openDevice(AudioOutput * audioOutput)
/* create a buffer of 1s */
od->bufferSize = (audioFormat->sampleRate) *
(audioFormat->bits >> 3) * (audioFormat->channels);
od->buffer = realloc(od->buffer, od->bufferSize);
od->buffer = xrealloc(od->buffer, od->bufferSize);
od->pos = 0;
od->len = 0;
......
......@@ -46,7 +46,7 @@ static PulseData *newPulseData(void)
{
PulseData *ret;
ret = malloc(sizeof(PulseData));
ret = xmalloc(sizeof(PulseData));
ret->s = NULL;
ret->server = NULL;
......@@ -78,8 +78,8 @@ static int pulse_initDriver(AudioOutput * audioOutput, ConfigParam * param)
}
pd = newPulseData();
pd->server = server ? strdup(server->value) : NULL;
pd->sink = sink ? strdup(sink->value) : NULL;
pd->server = server ? xstrdup(server->value) : NULL;
pd->sink = sink ? xstrdup(sink->value) : NULL;
audioOutput->data = pd;
return 0;
......
......@@ -74,7 +74,7 @@ typedef struct _ShoutData {
static ShoutData *newShoutData(void)
{
ShoutData *ret = malloc(sizeof(ShoutData));
ShoutData *ret = xmalloc(sizeof(ShoutData));
ret->shoutConn = shout_new();
ret->opened = 0;
......
......@@ -85,37 +85,37 @@ int main()
char *b;
int i, max;
b = strdup("lsinfo \"/some/dir/name \\\"test\\\"\"");
b = xstrdup("lsinfo \"/some/dir/name \\\"test\\\"\"");
max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir/name \"test\"", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"/some/dir/name \\\"test\\\" something else\"");
b = xstrdup("lsinfo \"/some/dir/name \\\"test\\\" something else\"");
max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir/name \"test\" something else", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"/some/dir\\\\name\"");
b = xstrdup("lsinfo \"/some/dir\\\\name\"");
max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir\\name", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"/some/dir name\"");
b = xstrdup("lsinfo \"/some/dir name\"");
max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir name", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"\\\"/some/dir\\\"\"");
b = xstrdup("lsinfo \"\\\"/some/dir\\\"\"");
max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("\"/some/dir\"", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"\\\"/some/dir\\\" x\"");
b = xstrdup("lsinfo \"\\\"/some/dir\\\" x\"");
max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("\"/some/dir\" x", a[1]) );
......
......@@ -19,6 +19,7 @@
#include "charConv.h"
#include "mpd_types.h"
#include "utf8.h"
#include "utils.h"
#include <stdlib.h>
#include <errno.h>
......@@ -64,8 +65,8 @@ int setCharSetConversion(char *to, char *from)
if (0 == strcmp(to, from)) {
char_conv_same = 1;
char_conv_to = strdup(to);
char_conv_from = strdup(from);
char_conv_to = xstrdup(to);
char_conv_from = xstrdup(from);
return 0;
}
......@@ -76,16 +77,16 @@ int setCharSetConversion(char *to, char *from)
}
if (char_conv_latin1ToUtf8 != 0) {
char_conv_to = strdup(to);
char_conv_from = strdup(from);
char_conv_to = xstrdup(to);
char_conv_from = xstrdup(from);
return 0;
}
#ifdef HAVE_ICONV
if ((char_conv_iconv = iconv_open(to, from)) == (iconv_t) (-1))
return -1;
char_conv_to = strdup(to);
char_conv_from = strdup(from);
char_conv_to = xstrdup(to);
char_conv_from = xstrdup(from);
char_conv_use_iconv = 1;
return 0;
......@@ -100,7 +101,7 @@ char *convStrDup(char *string)
return NULL;
if (char_conv_same)
return strdup(string);
return xstrdup(string);
#ifdef HAVE_ICONV
if (char_conv_use_iconv) {
......@@ -112,7 +113,7 @@ char *convStrDup(char *string)
size_t err;
char *bufferPtr;
ret = malloc(1);
ret = xmalloc(1);
ret[0] = '\0';
while (inleft) {
......@@ -127,7 +128,7 @@ char *convStrDup(char *string)
return NULL;
}
ret = realloc(ret, retlen + BUFFER_SIZE - outleft + 1);
ret = xrealloc(ret, retlen + BUFFER_SIZE - outleft + 1);
memcpy(ret + retlen, buffer, BUFFER_SIZE - outleft);
retlen += BUFFER_SIZE - outleft;
ret[retlen] = '\0';
......
......@@ -26,6 +26,7 @@
#include <sys/types.h>
#include "compress.h"
#include "utils.h"
#ifdef USE_X
#include <X11/Xlib.h>
......@@ -67,7 +68,7 @@ void CompressCfg(int show_mon, int anticlip, int target, int gainmax,
prefs.buckets = buckets;
/* Allocate the peak structure */
peaks = realloc(peaks, sizeof(int)*prefs.buckets);
peaks = xrealloc(peaks, sizeof(int)*prefs.buckets);
if (prefs.buckets > lastsize)
memset(peaks + lastsize, 0, sizeof(int)*(prefs.buckets
......
......@@ -52,12 +52,12 @@ static List *configEntriesList = NULL;
static ConfigParam *newConfigParam(char *value, int line)
{
ConfigParam *ret = malloc(sizeof(ConfigParam));
ConfigParam *ret = xmalloc(sizeof(ConfigParam));
if (!value)
ret->value = NULL;
else
ret->value = strdup(value);
ret->value = xstrdup(value);
ret->line = line;
......@@ -91,7 +91,7 @@ static void freeConfigParam(ConfigParam * param)
static ConfigEntry *newConfigEntry(int repeatable, int block)
{
ConfigEntry *ret = malloc(sizeof(ConfigEntry));
ConfigEntry *ret = xmalloc(sizeof(ConfigEntry));
ret->mask = 0;
ret->configParamList =
......@@ -135,44 +135,44 @@ void initConf(void)
configEntriesList = makeList((ListFreeDataFunc *) freeConfigEntry, 1);
/* registerConfigParam(name, repeatable, block); */
registerConfigParam(CONF_PORT, 0, 0);
registerConfigParam(CONF_PID_FILE, 0, 0);
registerConfigParam(CONF_MUSIC_DIR, 0, 0);
registerConfigParam(CONF_PLAYLIST_DIR, 0, 0);
registerConfigParam(CONF_DB_FILE, 0, 0);
registerConfigParam(CONF_LOG_FILE, 0, 0);
registerConfigParam(CONF_ERROR_FILE, 0, 0);
registerConfigParam(CONF_CONN_TIMEOUT, 0, 0);
registerConfigParam(CONF_MIXER_DEVICE, 0, 0);
registerConfigParam(CONF_MAX_CONN, 0, 0);
registerConfigParam(CONF_MAX_PLAYLIST_LENGTH, 0, 0);
registerConfigParam(CONF_BUFFER_BEFORE_PLAY, 0, 0);
registerConfigParam(CONF_MAX_COMMAND_LIST_SIZE, 0, 0);
registerConfigParam(CONF_MAX_OUTPUT_BUFFER_SIZE, 0, 0);
registerConfigParam(CONF_AUDIO_OUTPUT, 1, 1);
registerConfigParam(CONF_SAVE_ABSOLUTE_PATHS, 0, 0);
registerConfigParam(CONF_BIND_TO_ADDRESS, 1, 0);
registerConfigParam(CONF_MIXER_TYPE, 0, 0);
registerConfigParam(CONF_PID_FILE, 0, 0);
registerConfigParam(CONF_STATE_FILE, 0, 0);
registerConfigParam(CONF_USER, 0, 0);
registerConfigParam(CONF_DB_FILE, 0, 0);
registerConfigParam(CONF_BIND_TO_ADDRESS, 1, 0);
registerConfigParam(CONF_PORT, 0, 0);
registerConfigParam(CONF_LOG_LEVEL, 0, 0);
registerConfigParam(CONF_MIXER_CONTROL, 0, 0);
registerConfigParam(CONF_FS_CHARSET, 0, 0);
registerConfigParam(CONF_PASSWORD, 1, 0);
registerConfigParam(CONF_DEFAULT_PERMS, 0, 0);
registerConfigParam(CONF_AUDIO_BUFFER_SIZE, 0, 0);
registerConfigParam(CONF_REPLAYGAIN, 0, 0);
registerConfigParam(CONF_AUDIO_OUTPUT, 1, 1);
registerConfigParam(CONF_AUDIO_OUTPUT_FORMAT, 0, 0);
registerConfigParam(CONF_MIXER_TYPE, 0, 0);
registerConfigParam(CONF_MIXER_DEVICE, 0, 0);
registerConfigParam(CONF_MIXER_CONTROL, 0, 0);
registerConfigParam(CONF_REPLAYGAIN, 0, 0);
registerConfigParam(CONF_REPLAYGAIN_PREAMP, 0, 0);
registerConfigParam(CONF_VOLUME_NORMALIZATION, 0, 0);
registerConfigParam(CONF_AUDIO_BUFFER_SIZE, 0, 0);
registerConfigParam(CONF_BUFFER_BEFORE_PLAY, 0, 0);
registerConfigParam(CONF_HTTP_BUFFER_SIZE, 0, 0);
registerConfigParam(CONF_HTTP_PREBUFFER_SIZE, 0, 0);
registerConfigParam(CONF_HTTP_PROXY_HOST, 0, 0);
registerConfigParam(CONF_HTTP_PROXY_PORT, 0, 0);
registerConfigParam(CONF_HTTP_PROXY_USER, 0, 0);
registerConfigParam(CONF_HTTP_PROXY_PASSWORD, 0, 0);
registerConfigParam(CONF_HTTP_BUFFER_SIZE, 0, 0);
registerConfigParam(CONF_HTTP_PREBUFFER_SIZE, 0, 0);
registerConfigParam(CONF_REPLAYGAIN_PREAMP, 0, 0);
registerConfigParam(CONF_METADATA_TO_USE, 0, 0);
registerConfigParam(CONF_CONN_TIMEOUT, 0, 0);
registerConfigParam(CONF_MAX_CONN, 0, 0);
registerConfigParam(CONF_MAX_PLAYLIST_LENGTH, 0, 0);
registerConfigParam(CONF_MAX_COMMAND_LIST_SIZE, 0, 0);
registerConfigParam(CONF_MAX_OUTPUT_BUFFER_SIZE, 0, 0);
registerConfigParam(CONF_FS_CHARSET, 0, 0);
registerConfigParam(CONF_ID3V1_ENCODING, 0, 0);
registerConfigParam(CONF_VOLUME_NORMALIZATION, 0, 0);
registerConfigParam(CONF_METADATA_TO_USE, 0, 0);
registerConfigParam(CONF_SAVE_ABSOLUTE_PATHS, 0, 0);
}
static void addBlockParam(ConfigParam * param, char *name, char *value,
......@@ -180,13 +180,13 @@ static void addBlockParam(ConfigParam * param, char *name, char *value,
{
param->numberOfBlockParams++;
param->blockParams = realloc(param->blockParams,
param->blockParams = xrealloc(param->blockParams,
param->numberOfBlockParams *
sizeof(BlockParam));
param->blockParams[param->numberOfBlockParams - 1].name = strdup(name);
param->blockParams[param->numberOfBlockParams - 1].name = xstrdup(name);
param->blockParams[param->numberOfBlockParams - 1].value =
strdup(value);
xstrdup(value);
param->blockParams[param->numberOfBlockParams - 1].line = line;
}
......@@ -452,7 +452,7 @@ ConfigParam *parseConfigFilePath(char *name, int force)
if (foundSlash)
*ch = '/';
}
newPath = malloc(strlen(pwd->pw_dir) + strlen(path + pos) + 1);
newPath = xmalloc(strlen(pwd->pw_dir) + strlen(path + pos) + 1);
strcpy(newPath, pwd->pw_dir);
strcat(newPath, path + pos);
free(param->value);
......
......@@ -21,44 +21,44 @@
#include "../config.h"
#define CONF_PORT "port"
#define CONF_PID_FILE "pid_file"
#define CONF_MUSIC_DIR "music_directory"
#define CONF_PLAYLIST_DIR "playlist_directory"
#define CONF_DB_FILE "db_file"
#define CONF_LOG_FILE "log_file"
#define CONF_ERROR_FILE "error_file"
#define CONF_CONN_TIMEOUT "connection_timeout"
#define CONF_MIXER_DEVICE "mixer_device"
#define CONF_MAX_CONN "max_connections"
#define CONF_MAX_PLAYLIST_LENGTH "max_playlist_length"
#define CONF_BUFFER_BEFORE_PLAY "buffer_before_play"
#define CONF_MAX_COMMAND_LIST_SIZE "max_command_list_size"
#define CONF_MAX_OUTPUT_BUFFER_SIZE "max_output_buffer_size"
#define CONF_AUDIO_OUTPUT "audio_output"
#define CONF_SAVE_ABSOLUTE_PATHS "save_absolute_paths_in_playlists"
#define CONF_BIND_TO_ADDRESS "bind_to_address"
#define CONF_MIXER_TYPE "mixer_type"
#define CONF_PID_FILE "pid_file"
#define CONF_STATE_FILE "state_file"
#define CONF_USER "user"
#define CONF_DB_FILE "db_file"
#define CONF_BIND_TO_ADDRESS "bind_to_address"
#define CONF_PORT "port"
#define CONF_LOG_LEVEL "log_level"
#define CONF_MIXER_CONTROL "mixer_control"
#define CONF_FS_CHARSET "filesystem_charset"
#define CONF_PASSWORD "password"
#define CONF_DEFAULT_PERMS "default_permissions"
#define CONF_AUDIO_BUFFER_SIZE "audio_buffer_size"
#define CONF_AUDIO_OUTPUT "audio_output"
#define CONF_AUDIO_OUTPUT_FORMAT "audio_output_format"
#define CONF_MIXER_TYPE "mixer_type"
#define CONF_MIXER_DEVICE "mixer_device"
#define CONF_MIXER_CONTROL "mixer_control"
#define CONF_REPLAYGAIN "replaygain"
#define CONF_REPLAYGAIN_PREAMP "replaygain_preamp"
#define CONF_VOLUME_NORMALIZATION "volume_normalization"
#define CONF_AUDIO_BUFFER_SIZE "audio_buffer_size"
#define CONF_BUFFER_BEFORE_PLAY "buffer_before_play"
#define CONF_HTTP_BUFFER_SIZE "http_buffer_size"
#define CONF_HTTP_PREBUFFER_SIZE "http_prebuffer_size"
#define CONF_HTTP_PROXY_HOST "http_proxy_host"
#define CONF_HTTP_PROXY_PORT "http_proxy_port"
#define CONF_HTTP_PROXY_USER "http_proxy_user"
#define CONF_HTTP_PROXY_PASSWORD "http_proxy_password"
#define CONF_HTTP_BUFFER_SIZE "http_buffer_size"
#define CONF_HTTP_PREBUFFER_SIZE "http_prebuffer_size"
#define CONF_METADATA_TO_USE "metadata_to_use"
#define CONF_CONN_TIMEOUT "connection_timeout"
#define CONF_MAX_CONN "max_connections"
#define CONF_MAX_PLAYLIST_LENGTH "max_playlist_length"
#define CONF_MAX_COMMAND_LIST_SIZE "max_command_list_size"
#define CONF_MAX_OUTPUT_BUFFER_SIZE "max_output_buffer_size"
#define CONF_FS_CHARSET "filesystem_charset"
#define CONF_ID3V1_ENCODING "id3v1_encoding"
#define CONF_VOLUME_NORMALIZATION "volume_normalization"
#define CONF_METADATA_TO_USE "metadata_to_use"
#define CONF_SAVE_ABSOLUTE_PATHS "save_absolute_paths_in_playlists"
typedef struct _BlockParam {
char *name;
......
......@@ -69,14 +69,14 @@ static int initLocateTagItem(LocateTagItem * item, char *typeStr, char *needle)
if (item->tagType < 0)
return -1;
item->needle = strdup(needle);
item->needle = xstrdup(needle);
return 0;
}
LocateTagItem *newLocateTagItem(char *typeStr, char *needle)
{
LocateTagItem *ret = malloc(sizeof(LocateTagItem));
LocateTagItem *ret = xmalloc(sizeof(LocateTagItem));
if (initLocateTagItem(ret, typeStr, needle) < 0) {
free(ret);
......@@ -108,7 +108,7 @@ int newLocateTagItemArrayFromArgArray(char *argArray[],
if (numArgs % 2 != 0)
return -1;
*arrayRet = malloc(sizeof(LocateTagItem) * numArgs / 2);
*arrayRet = xmalloc(sizeof(LocateTagItem) * numArgs / 2);
for (i = 0, item = *arrayRet; i < numArgs / 2; i++, item++) {
if (initLocateTagItem
......@@ -214,7 +214,7 @@ int searchForSongsIn(int fd, char *name, int numItems, LocateTagItem * items)
int ret = -1;
int i;
char **originalNeedles = malloc(numItems * sizeof(char *));
char **originalNeedles = xmalloc(numItems * sizeof(char *));
LocateTagItemArray array;
for (i = 0; i < numItems; i++) {
......@@ -347,7 +347,7 @@ unsigned long sumSongTimesIn(int fd, char *name)
static ListCommandItem *newListCommandItem(int tagType, int numConditionals,
LocateTagItem * conditionals)
{
ListCommandItem *item = malloc(sizeof(ListCommandItem));
ListCommandItem *item = xmalloc(sizeof(ListCommandItem));
item->tagType = tagType;
item->numConditionals = numConditionals;
......
......@@ -264,7 +264,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb,
if (isRemoteUrl(pc->utf8url))
path = utf8StrToLatin1Dup(pc->utf8url);
else
path = strdup(rmp2amp(utf8ToFsCharset(pc->utf8url)));
path = xstrdup(rmp2amp(utf8ToFsCharset(pc->utf8url)));
if (!path) {
dc->error = DECODE_ERROR_FILE;
......@@ -304,7 +304,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb,
/*if(inStream.metaName) {
MpdTag * tag = newMpdTag();
tag->name = strdup(inStream.metaName);
tag->name = xstrdup(inStream.metaName);
copyMpdTagToOutputBuffer(cb, tag);
freeMpdTag(tag);
} */
......
......@@ -236,7 +236,7 @@ int updateInit(int fd, List * pathList)
static DirectoryStat *newDirectoryStat(struct stat *st)
{
DirectoryStat *ret = malloc(sizeof(DirectoryStat));
DirectoryStat *ret = xmalloc(sizeof(DirectoryStat));
ret->inode = st->st_ino;
ret->device = st->st_dev;
return ret;
......@@ -258,10 +258,10 @@ static Directory *newDirectory(char *dirname, Directory * parent)
{
Directory *directory;
directory = malloc(sizeof(Directory));
directory = xmalloc(sizeof(Directory));
if (dirname && strlen(dirname))
directory->path = strdup(dirname);
directory->path = xstrdup(dirname);
else
directory->path = NULL;
directory->subDirectories = newDirectoryList();
......@@ -392,11 +392,11 @@ static int removeDeletedFromDirectory(Directory * directory, DIR * dir)
continue;
if (directory->path) {
s = malloc(strlen(getDirectoryPath(directory))
s = xmalloc(strlen(getDirectoryPath(directory))
+ strlen(utf8) + 2);
sprintf(s, "%s/%s", getDirectoryPath(directory), utf8);
} else
s = strdup(utf8);
s = xstrdup(utf8);
insertInList(entList, utf8, s);
}
......@@ -445,7 +445,7 @@ static Directory *addDirectoryPathToDB(char *utf8path, char **shortname)
Directory *parentDirectory;
void *directory;
parent = strdup(parentPath(utf8path));
parent = xstrdup(parentPath(utf8path));
if (strlen(parent) == 0)
parentDirectory = (void *)mp3rootDirectory;
......@@ -489,7 +489,7 @@ static Directory *addParentPathToDB(char *utf8path, char **shortname)
char *parent;
Directory *parentDirectory;
parent = strdup(parentPath(utf8path));
parent = xstrdup(parentPath(utf8path));
if (strlen(parent) == 0)
parentDirectory = (void *)mp3rootDirectory;
......@@ -653,14 +653,14 @@ static int updateDirectory(Directory * directory)
if (!utf8)
continue;
utf8 = strdup(utf8);
utf8 = xstrdup(utf8);
if (directory->path) {
s = malloc(strlen(getDirectoryPath(directory)) +
s = xmalloc(strlen(getDirectoryPath(directory)) +
strlen(utf8) + 2);
sprintf(s, "%s/%s", getDirectoryPath(directory), utf8);
} else
s = strdup(utf8);
s = xstrdup(utf8);
if (updateInDirectory(directory, utf8, s) > 0)
ret = 1;
free(utf8);
......@@ -708,16 +708,16 @@ static int exploreDirectory(Directory * directory)
if (!utf8)
continue;
utf8 = strdup(utf8);
utf8 = xstrdup(utf8);
DEBUG("explore: found: %s (%s)\n", ent->d_name, utf8);
if (directory->path) {
s = malloc(strlen(getDirectoryPath(directory)) +
s = xmalloc(strlen(getDirectoryPath(directory)) +
strlen(utf8) + 2);
sprintf(s, "%s/%s", getDirectoryPath(directory), utf8);
} else
s = strdup(utf8);
s = xstrdup(utf8);
if (addToDirectory(directory, utf8, s) > 0)
ret = 1;
free(utf8);
......@@ -817,7 +817,7 @@ void closeMp3Directory(void)
static Directory *findSubDirectory(Directory * directory, char *name)
{
void *subDirectory;
char *dup = strdup(name);
char *dup = xstrdup(name);
char *key;
key = strtok(dup, "/");
......@@ -942,7 +942,7 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
while (myFgets(buffer, bufferSize, fp)
&& 0 != strncmp(DIRECTORY_END, buffer, strlen(DIRECTORY_END))) {
if (0 == strncmp(DIRECTORY_DIR, buffer, strlen(DIRECTORY_DIR))) {
key = strdup(&(buffer[strlen(DIRECTORY_DIR)]));
key = xstrdup(&(buffer[strlen(DIRECTORY_DIR)]));
if (!myFgets(buffer, bufferSize, fp)) {
ERROR("Error reading db, fgets\n");
exit(EXIT_FAILURE);
......@@ -961,7 +961,7 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
ERROR("Error reading db at line: %s\n", buffer);
exit(EXIT_FAILURE);
}
name = strdup(&(buffer[strlen(DIRECTORY_BEGIN)]));
name = xstrdup(&(buffer[strlen(DIRECTORY_BEGIN)]));
while (nextDirNode && (strcmpRet =
strcmp(key,
......@@ -1034,7 +1034,7 @@ int checkDirectoryDB(void)
/* If the file doesn't exist, we can't check if we can write
* it, so we are going to try to get the directory path, and
* see if we can write a file in that */
dbPath = strdup(dbFile);
dbPath = xstrdup(dbFile);
dirPath = dirname(dbPath);
/* Check that the parent part of the path is a directory */
......@@ -1329,7 +1329,7 @@ static Song *getSongDetails(char *file, char **shortnameRet,
void *song = NULL;
Directory *directory;
char *dir = NULL;
char *dup = strdup(file);
char *dup = xstrdup(file);
char *shortname = dup;
char *c = strtok(dup, "/");
......
......@@ -25,8 +25,7 @@
* example taken from: http://rlove.org/log/2005102601
*/
/* disabled (0) until I fix all the warnings :) */
#if __GNUC__ >= 3
#if defined(__GNUC__) && (__GNUC__ >= 3)
# define mpd_const __attribute__ ((const))
# define mpd_deprecated __attribute__ ((deprecated))
# define mpd_malloc __attribute__ ((malloc))
......
......@@ -162,7 +162,7 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length,
fileread = inStream->size;
b->buffer = malloc(FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS);
b->buffer = xmalloc(FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS);
memset(b->buffer, 0, FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS);
bread = readFromInputStream(inStream, b->buffer, 1,
......@@ -223,9 +223,10 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length,
skipSize]
& 0xE0);
*length = fileread;
if (*length != 0 && bitRate != 0)
*length = *length * 8.0 / bitRate;
if (fileread != 0 && bitRate != 0)
*length = fileread * 8.0 / bitRate;
else
*length = fileread;
}
}
......
......@@ -70,10 +70,12 @@ static int audiofile_decode(OutputBuffer * cb, DecoderControl * dc, char *path)
return -1;
}
afGetSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits);
afSetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK,
AF_SAMPFMT_TWOSCOMP, 16);
afGetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits);
dc->audioFormat.bits = bits;
dc->audioFormat.sampleRate = afGetRate(af_fp, AF_DEFAULT_TRACK);
dc->audioFormat.channels = afGetChannels(af_fp, AF_DEFAULT_TRACK);
dc->audioFormat.channels = afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK);
getOutputAudioFormat(&(dc->audioFormat), &(cb->audioFormat));
frame_count = afGetFrameCount(af_fp, AF_DEFAULT_TRACK);
......@@ -90,7 +92,7 @@ static int audiofile_decode(OutputBuffer * cb, DecoderControl * dc, char *path)
return -1;
}
fs = (int)afGetFrameSize(af_fp, AF_DEFAULT_TRACK, 1);
fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1);
dc->state = DECODE_STATE_DECODE;
{
......
......@@ -143,9 +143,9 @@ static mod_Data *mod_open(char *path)
if (!(moduleHandle = Player_Load(path, 128, 0)))
return NULL;
data = malloc(sizeof(mod_Data));
data = xmalloc(sizeof(mod_Data));
data->audio_buffer = malloc(MIKMOD_FRAME_SIZE);
data->audio_buffer = xmalloc(MIKMOD_FRAME_SIZE);
data->moduleHandle = moduleHandle;
Player_Start(data->moduleHandle);
......@@ -243,7 +243,7 @@ static MpdTag *modTagDup(char *file)
ret = newMpdTag();
ret->time = 0;
title = strdup(Player_LoadTitle(file));
title = xstrdup(Player_LoadTitle(file));
if (title)
addItemToMpdTag(ret, TAG_ITEM_TITLE, title);
......
......@@ -293,7 +293,7 @@ static void mp3_parseId3Tag(mp3DecodeData * data, signed long tagsize,
id3_data = data->stream.this_frame;
mad_stream_skip(&(data->stream), tagsize);
} else {
allocated = malloc(tagsize);
allocated = xmalloc(tagsize);
if (!allocated)
goto fail;
......@@ -682,8 +682,8 @@ static int decodeFirstFrame(mp3DecodeData * data, DecoderControl * dc,
}
}
data->frameOffset = malloc(sizeof(long) * data->maxFrames);
data->times = malloc(sizeof(mad_timer_t) * data->maxFrames);
data->frameOffset = xmalloc(sizeof(long) * data->maxFrames);
data->times = xmalloc(sizeof(mad_timer_t) * data->maxFrames);
return 0;
}
......
......@@ -123,7 +123,7 @@ static int mp4_decode(OutputBuffer * cb, DecoderControl * dc, char *path)
return -1;
}
mp4cb = malloc(sizeof(mp4ff_callback_t));
mp4cb = xmalloc(sizeof(mp4ff_callback_t));
mp4cb->read = mp4_inputStreamReadCallback;
mp4cb->seek = mp4_inputStreamSeekCallback;
mp4cb->user_data = &inStream;
......@@ -195,7 +195,7 @@ static int mp4_decode(OutputBuffer * cb, DecoderControl * dc, char *path)
time = 0.0;
seekTable = malloc(sizeof(float) * numSamples);
seekTable = xmalloc(sizeof(float) * numSamples);
for (sampleId = 0; sampleId < numSamples && !eof; sampleId++) {
if (dc->seek)
......@@ -341,7 +341,7 @@ static MpdTag *mp4DataDup(char *file, int *mp4MetadataFound)
return NULL;
}
cb = malloc(sizeof(mp4ff_callback_t));
cb = xmalloc(sizeof(mp4ff_callback_t));
cb->read = mp4_inputStreamReadCallback;
cb->seek = mp4_inputStreamSeekCallback;
cb->user_data = &inStream;
......
......@@ -172,7 +172,7 @@ static char *base64Dup(char *s)
{
int i;
int len = strlen(s);
char *ret = calloc(BASE64_LENGTH(len) + 1, 1);
char *ret = xcalloc(BASE64_LENGTH(len) + 1, 1);
unsigned char *p = (unsigned char *)ret;
char tbl[64] = {
......@@ -216,14 +216,14 @@ static char *authString(char *header, char *user, char *password)
return NULL;
templen = strlen(user) + strlen(password) + 2;
temp = malloc(templen);
temp = xmalloc(templen);
strcpy(temp, user);
strcat(temp, ":");
strcat(temp, password);
temp64 = base64Dup(temp);
free(temp);
ret = malloc(strlen(temp64) + strlen(header) + 3);
ret = xmalloc(strlen(temp64) + strlen(header) + 3);
strcpy(ret, header);
strcat(ret, temp64);
strcat(ret, "\r\n");
......@@ -240,7 +240,7 @@ static char *authString(char *header, char *user, char *password)
static InputStreamHTTPData *newInputStreamHTTPData(void)
{
InputStreamHTTPData *ret = malloc(sizeof(InputStreamHTTPData));
InputStreamHTTPData *ret = xmalloc(sizeof(InputStreamHTTPData));
if (proxyHost) {
ret->proxyAuth = proxyAuthString(proxyUser, proxyPassword);
......@@ -256,7 +256,7 @@ static InputStreamHTTPData *newInputStreamHTTPData(void)
ret->icyMetaint = 0;
ret->prebuffer = 0;
ret->icyOffset = 0;
ret->buffer = malloc(bufferSize);
ret->buffer = xmalloc(bufferSize);
return ret;
}
......@@ -305,19 +305,19 @@ static int parseUrl(InputStreamHTTPData * data, char *url)
char *passwd;
if (colon && colon < at) {
user = malloc(colon - temp + 1);
user = xmalloc(colon - temp + 1);
memcpy(user, temp, colon - temp);
user[colon - temp] = '\0';
passwd = malloc(at - colon);
passwd = xmalloc(at - colon);
memcpy(passwd, colon + 1, at - colon - 1);
passwd[at - colon - 1] = '\0';
} else {
user = malloc(at - temp + 1);
user = xmalloc(at - temp + 1);
memcpy(user, temp, at - temp);
user[at - temp] = '\0';
passwd = strdup("");
passwd = xstrdup("");
}
data->httpAuth = httpAuthString(user, passwd);
......@@ -345,7 +345,7 @@ static int parseUrl(InputStreamHTTPData * data, char *url)
if (len <= 1)
return -1;
data->host = malloc(len);
data->host = xmalloc(len);
memcpy(data->host, temp, len - 1);
data->host[len - 1] = '\0';
/* fetch the port */
......@@ -353,19 +353,19 @@ static int parseUrl(InputStreamHTTPData * data, char *url)
len = strlen(colon) - 1;
if (slash)
len -= strlen(slash);
data->port = malloc(len + 1);
data->port = xmalloc(len + 1);
memcpy(data->port, colon + 1, len);
data->port[len] = '\0';
DEBUG(__FILE__ ": Port: %s\n", data->port);
} else {
data->port = strdup("80");
data->port = xstrdup("80");
}
/* fetch the path */
if (proxyHost)
data->path = strdup(url);
data->path = xstrdup(url);
else
data->path = strdup(slash ? slash : "/");
data->path = xstrdup(slash ? slash : "/");
return 0;
}
......@@ -591,7 +591,7 @@ static int getHTTPHello(InputStream * inStream)
&& *(cur + curlen) != '\r') {
curlen++;
}
url = malloc(curlen + 1);
url = xmalloc(curlen + 1);
memcpy(url, cur, curlen);
url[curlen] = '\0';
ret = parseUrl(data, url);
......@@ -634,7 +634,7 @@ static int getHTTPHello(InputStream * inStream)
free(inStream->metaName);
while (*(incr + cur) == ' ')
incr++;
inStream->metaName = strdup(cur + incr);
inStream->metaName = xstrdup(cur + incr);
*temp = '\r';
DEBUG("inputStream_http: metaName: %s\n",
inStream->metaName);
......@@ -648,7 +648,7 @@ static int getHTTPHello(InputStream * inStream)
free(inStream->metaName);
while (*(incr + cur) == ' ')
incr++;
inStream->metaName = strdup(cur + incr);
inStream->metaName = xstrdup(cur + incr);
*temp = '\r';
DEBUG("inputStream_http: metaName: %s\n",
inStream->metaName);
......@@ -662,7 +662,7 @@ static int getHTTPHello(InputStream * inStream)
free(inStream->mime);
while (*(incr + cur) == ' ')
incr++;
inStream->mime = strdup(cur + incr);
inStream->mime = xstrdup(cur + incr);
*temp = '\r';
}
......@@ -735,7 +735,7 @@ static void parseIcyMetadata(InputStream * inStream, char *metadata, int size)
{
char *r;
char *s;
char *temp = malloc(size + 1);
char *temp = xmalloc(size + 1);
memcpy(temp, metadata, size);
temp[size] = '\0';
s = strtok_r(temp, ";", &r);
......@@ -749,7 +749,7 @@ static void parseIcyMetadata(InputStream * inStream, char *metadata, int size)
if (s[strlen(s) - 1] == '\'') {
s[strlen(s) - 1] = '\0';
}
inStream->metaTitle = strdup(s + cur);
inStream->metaTitle = xstrdup(s + cur);
DEBUG("inputStream_http: metaTitle: %s\n",
inStream->metaTitle);
}
......
......@@ -132,7 +132,7 @@ static void set_send_buf_size(Interface * interface)
if (interface->send_buf_alloc < new_size) {
if (interface->send_buf)
free(interface->send_buf);
interface->send_buf = malloc(new_size);
interface->send_buf = xmalloc(new_size);
interface->send_buf_alloc = new_size;
}
}
......@@ -593,9 +593,9 @@ void initInterfaces(void)
interface_max_output_buffer_size *= 1024;
}
interfaces = malloc(sizeof(Interface) * interface_max_connections);
interfaces = xmalloc(sizeof(Interface) * interface_max_connections);
list_cache = calloc(interface_list_cache_size, sizeof(struct strnode));
list_cache = xcalloc(interface_list_cache_size, sizeof(struct strnode));
list_cache_head = &(list_cache[0]);
list_cache_tail = &(list_cache[interface_list_cache_size - 1]);
......
......@@ -17,6 +17,7 @@
*/
#include "list.h"
#include "utils.h"
#include <stdlib.h>
#include <string.h>
......@@ -32,7 +33,7 @@ static void makeListNodesArray(List * list)
if (!list->numberOfNodes)
return;
list->nodesArray = realloc(list->nodesArray,
list->nodesArray = xrealloc(list->nodesArray,
sizeof(ListNode *) * list->numberOfNodes);
for (i = 0; i < list->numberOfNodes; i++) {
......@@ -51,7 +52,7 @@ static void freeListNodesArray(List * list)
List *makeList(ListFreeDataFunc * freeDataFunc, int strdupKeys)
{
List *list = malloc(sizeof(List));
List *list = xmalloc(sizeof(List));
assert(list != NULL);
......@@ -75,7 +76,7 @@ ListNode *insertInListBeforeNode(List * list, ListNode * beforeNode, int pos,
assert(key != NULL);
/*assert(data!=NULL); */
node = malloc(sizeof(ListNode));
node = xmalloc(sizeof(ListNode));
assert(node != NULL);
node->nextNode = beforeNode;
......@@ -102,7 +103,7 @@ ListNode *insertInListBeforeNode(List * list, ListNode * beforeNode, int pos,
}
if (list->strdupKeys)
node->key = strdup(key);
node->key = xstrdup(key);
else
node->key = key;
......@@ -111,7 +112,7 @@ ListNode *insertInListBeforeNode(List * list, ListNode * beforeNode, int pos,
list->numberOfNodes++;
if (list->sorted) {
list->nodesArray = realloc(list->nodesArray,
list->nodesArray = xrealloc(list->nodesArray,
list->numberOfNodes *
sizeof(ListNode *));
if (node == list->lastNode) {
......@@ -138,7 +139,7 @@ ListNode *insertInList(List * list, char *key, void *data)
assert(key != NULL);
/*assert(data!=NULL); */
node = malloc(sizeof(ListNode));
node = xmalloc(sizeof(ListNode));
assert(node != NULL);
if (list->nodesArray)
......@@ -154,7 +155,7 @@ ListNode *insertInList(List * list, char *key, void *data)
}
if (list->strdupKeys)
node->key = strdup(key);
node->key = xstrdup(key);
else
node->key = key;
......@@ -176,7 +177,7 @@ int insertInListWithoutKey(List * list, void *data)
assert(list != NULL);
assert(data != NULL);
node = malloc(sizeof(ListNode));
node = xmalloc(sizeof(ListNode));
assert(node != NULL);
if (list->nodesArray)
......@@ -416,8 +417,8 @@ static void quickSort(ListNode ** nodesArray, long start, long end)
List *startList = makeList(free, 0);
List *endList = makeList(free, 0);
long *startPtr = malloc(sizeof(long));
long *endPtr = malloc(sizeof(long));
long *startPtr = xmalloc(sizeof(long));
long *endPtr = xmalloc(sizeof(long));
*startPtr = start;
*endPtr = end;
insertInListWithoutKey(startList, (void *)startPtr);
......@@ -471,8 +472,8 @@ static void quickSort(ListNode ** nodesArray, long start, long end)
deleteNodeFromList(endList, endList->lastNode);
if (pivot - 1 - start > 0) {
startPtr = malloc(sizeof(long));
endPtr = malloc(sizeof(long));
startPtr = xmalloc(sizeof(long));
endPtr = xmalloc(sizeof(long));
*startPtr = start;
*endPtr = pivot - 1;
insertInListWithoutKey(startList,
......@@ -483,8 +484,8 @@ static void quickSort(ListNode ** nodesArray, long start, long end)
}
if (end - pivot - 1 > 0) {
startPtr = malloc(sizeof(long));
endPtr = malloc(sizeof(long));
startPtr = xmalloc(sizeof(long));
endPtr = xmalloc(sizeof(long));
*startPtr = pivot + 1;
*endPtr = end;
insertInListWithoutKey(startList,
......
......@@ -101,7 +101,7 @@ static int establishListen(unsigned int port,
numberOfListenSockets++;
listenSockets =
realloc(listenSockets, sizeof(int) * numberOfListenSockets);
xrealloc(listenSockets, sizeof(int) * numberOfListenSockets);
listenSockets[numberOfListenSockets - 1] = sock;
......
......@@ -20,8 +20,7 @@
#define LOG_H
#include "../config.h"
#include "myfprintf.h"
#include "gcc.h"
#include <unistd.h>
......
......@@ -22,6 +22,7 @@
#include "myfprintf.h"
#include "log.h"
#include "utf8.h"
#include "utils.h"
#include <dirent.h>
#include <stdio.h>
......@@ -154,7 +155,7 @@ int lsPlaylists(int fd, char *utf8path)
int i;
sortList(list);
dup = malloc(strlen(utf8path) + 2);
dup = xmalloc(strlen(utf8path) + 2);
strcpy(dup, utf8path);
for (i = strlen(dup) - 1; i >= 0 && dup[i] == '/'; i--) {
dup[i] = '\0';
......
......@@ -90,7 +90,7 @@ static int setenv(const char *name, const char *value, int replace)
namelen = strlen(name);
valuelen = strlen(value);
envstr = malloc((namelen + valuelen + 2));
envstr = xmalloc((namelen + valuelen + 2));
if (!envstr)
return -1;
......
......@@ -91,7 +91,7 @@ int sendDataToOutputBuffer(OutputBuffer * cb, InputStream * inStream,
&(cb->
audioFormat));
if (datalen > convBufferLen) {
convBuffer = realloc(convBuffer, datalen);
convBuffer = xrealloc(convBuffer, datalen);
convBufferLen = datalen;
}
data = convBuffer;
......
......@@ -21,6 +21,7 @@
#include "charConv.h"
#include "conf.h"
#include "utf8.h"
#include "utils.h"
#include <stdlib.h>
#include <string.h>
......@@ -69,7 +70,7 @@ char *utf8ToFsCharset(char *str)
ret = pathConvCharset(fsCharset, "UTF-8", str, ret);
if (!ret)
ret = strdup(str);
ret = xstrdup(str);
return ret;
}
......@@ -81,7 +82,7 @@ void setFsCharset(char *charset)
if (fsCharset)
free(fsCharset);
fsCharset = strdup(charset);
fsCharset = xstrdup(charset);
DEBUG("setFsCharset: fs charset is: %s\n", fsCharset);
......@@ -101,7 +102,7 @@ void setFsCharset(char *charset)
if (error) {
free(fsCharset);
WARNING("setting fs charset to ISO-8859-1!\n");
fsCharset = strdup("ISO-8859-1");
fsCharset = xstrdup("ISO-8859-1");
}
}
......@@ -116,7 +117,7 @@ static char *appendSlash(char **path)
int len = strlen(temp);
if (temp[len - 1] != '/') {
temp = malloc(len + 2);
temp = xmalloc(len + 2);
memset(temp, 0, len + 2);
memcpy(temp, *path, len);
temp[len] = '/';
......@@ -157,14 +158,14 @@ void initPaths(void)
closedir(dir);
if (fsCharsetParam) {
charset = strdup(fsCharsetParam->value);
charset = xstrdup(fsCharsetParam->value);
}
#ifdef HAVE_LOCALE
#ifdef HAVE_LANGINFO_CODESET
else if ((originalLocale = setlocale(LC_CTYPE, NULL))) {
char *temp;
char *currentLocale;
originalLocale = strdup(originalLocale);
originalLocale = xstrdup(originalLocale);
if (!(currentLocale = setlocale(LC_CTYPE, ""))) {
WARNING("problems setting current locale with "
......@@ -175,7 +176,7 @@ void initPaths(void)
WARNING("current locale is \"%s\"\n",
currentLocale);
} else if ((temp = nl_langinfo(CODESET))) {
charset = strdup(temp);
charset = xstrdup(temp);
} else
WARNING
("problems getting charset for locale\n");
......@@ -273,7 +274,7 @@ char *parentPath(char *path)
char *sanitizePathDup(char *path)
{
int len = strlen(path) + 1;
char *ret = malloc(len);
char *ret = xmalloc(len);
char *cp = ret;
memset(ret, 0, len);
......@@ -307,5 +308,5 @@ char *sanitizePathDup(char *path)
DEBUG("sanitized: %s\n", ret);
return realloc(ret, len + 1);
return xrealloc(ret, len + 1);
}
......@@ -34,7 +34,7 @@ void finishPaths(void);
* which means:
* - Do not manually free the return value of these functions, it'll be
* automatically freed the next time it is called.
* - They are not reentrant, strdup the return value immediately if
* - They are not reentrant, xstrdup the return value immediately if
* you expect to call one of these functions again, but still need the
* previous result.
* - The static pointer is unique to each function.
......
......@@ -20,6 +20,7 @@
#include "mpd_types.h"
#include "log.h"
#include "utils.h"
#include <string.h>
#include <math.h>
......@@ -153,7 +154,7 @@ void pcm_convertAudioFormat(AudioFormat * inFormat, char *inBuffer, size_t
case 8:
dataBitLen = inSize << 1;
if (dataBitLen > bitConvBufferLength) {
bitConvBuffer = realloc(bitConvBuffer, dataBitLen);
bitConvBuffer = xrealloc(bitConvBuffer, dataBitLen);
bitConvBufferLength = dataBitLen;
}
dataBitConv = bitConvBuffer;
......@@ -187,7 +188,7 @@ void pcm_convertAudioFormat(AudioFormat * inFormat, char *inBuffer, size_t
case 1:
dataChannelLen = (dataBitLen >> 1) << 2;
if (dataChannelLen > channelConvBufferLength) {
channelConvBuffer = realloc(channelConvBuffer,
channelConvBuffer = xrealloc(channelConvBuffer,
dataChannelLen);
channelConvBufferLength = dataChannelLen;
}
......@@ -207,7 +208,7 @@ void pcm_convertAudioFormat(AudioFormat * inFormat, char *inBuffer, size_t
case 2:
dataChannelLen = dataBitLen >> 1;
if (dataChannelLen > channelConvBufferLength) {
channelConvBuffer = realloc(channelConvBuffer,
channelConvBuffer = xrealloc(channelConvBuffer,
dataChannelLen);
channelConvBufferLength = dataChannelLen;
}
......
......@@ -21,6 +21,7 @@
#include "conf.h"
#include "list.h"
#include "log.h"
#include "utils.h"
#include <string.h>
......@@ -103,7 +104,7 @@ void initPermissions(void)
password = temp;
permission = malloc(sizeof(int));
permission = xmalloc(sizeof(int));
*permission =
parsePermissions(strtok_r(NULL, "", &cp2));
......
......@@ -301,7 +301,7 @@ char *getPlayerErrorStr(void)
int errorlen = MAXPATHLEN + 1024;
PlayerControl *pc = &(getPlayerData()->playerControl);
error = realloc(error, errorlen + 1);
error = xrealloc(error, errorlen + 1);
memset(error, 0, errorlen + 1);
switch (pc->error) {
......@@ -328,7 +328,7 @@ char *getPlayerErrorStr(void)
}
errorlen = strlen(error);
error = realloc(error, errorlen + 1);
error = xrealloc(error, errorlen + 1);
if (errorlen)
return error;
......@@ -513,12 +513,12 @@ Song *playerCurrentDecodeSong(void)
DEBUG("playerCurrentDecodeSong: caught new metadata!\n");
if (prev)
free(prev);
prev = malloc(sizeof(MetadataChunk));
prev = xmalloc(sizeof(MetadataChunk));
memcpy(prev, &(pc->metadataChunk), sizeof(MetadataChunk));
if (song)
freeJustSong(song);
song = newNullSong();
song->url = strdup(pc->currentUrl);
song->url = xstrdup(pc->currentUrl);
song->tag = metadataChunkToMpdTagDup(prev);
ret = song;
resetPlayerMetadata();
......
......@@ -161,12 +161,12 @@ void initPlaylist(void)
if (playlist_saveAbsolutePaths == -1) playlist_saveAbsolutePaths = 0;
else if (playlist_saveAbsolutePaths < 0) exit(EXIT_FAILURE);
playlist.songs = malloc(sizeof(Song *) * playlist_max_length);
playlist.songMod = malloc(sizeof(mpd_uint32) * playlist_max_length);
playlist.order = malloc(sizeof(int) * playlist_max_length);
playlist.idToPosition = malloc(sizeof(int) * playlist_max_length *
playlist.songs = xmalloc(sizeof(Song *) * playlist_max_length);
playlist.songMod = xmalloc(sizeof(mpd_uint32) * playlist_max_length);
playlist.order = xmalloc(sizeof(int) * playlist_max_length);
playlist.idToPosition = xmalloc(sizeof(int) * playlist_max_length *
PLAYLIST_HASH_MULT);
playlist.positionToId = malloc(sizeof(int) * playlist_max_length);
playlist.positionToId = xmalloc(sizeof(int) * playlist_max_length);
memset(playlist.songs, 0, sizeof(char *) * playlist_max_length);
......@@ -1264,7 +1264,7 @@ int shufflePlaylist(int fd)
int deletePlaylist(int fd, char *utf8file)
{
char *file = utf8ToFsCharset(utf8file);
char *rfile = malloc(strlen(file) + strlen(".") +
char *rfile = xmalloc(strlen(file) + strlen(".") +
strlen(PLAYLIST_FILE_SUFFIX) + 1);
char *actualFile;
......@@ -1308,7 +1308,7 @@ int savePlaylist(int fd, char *utf8file)
file = utf8ToFsCharset(utf8file);
rfile = malloc(strlen(file) + strlen(".") +
rfile = xmalloc(strlen(file) + strlen(".") +
strlen(PLAYLIST_FILE_SUFFIX) + 1);
strcpy(rfile, file);
......@@ -1421,7 +1421,7 @@ static int PlaylistIterFunc(int fd, char *utf8file,
char s[MAXPATHLEN + 1];
int slength = 0;
char *temp = utf8ToFsCharset(utf8file);
char *rfile = malloc(strlen(temp) + strlen(".") +
char *rfile = xmalloc(strlen(temp) + strlen(".") +
strlen(PLAYLIST_FILE_SUFFIX) + 1);
char *actualFile;
char *parent = parentPath(temp);
......@@ -1461,7 +1461,7 @@ static int PlaylistIterFunc(int fd, char *utf8file,
if (strncmp(s, musicDir, strlen(musicDir)) == 0) {
strcpy(s, &(s[strlen(musicDir)]));
} else if (parentlen) {
temp = strdup(s);
temp = xstrdup(s);
memset(s, 0, MAXPATHLEN + 1);
strcpy(s, parent);
strncat(s, "/", MAXPATHLEN - parentlen);
......@@ -1536,7 +1536,7 @@ static void PlaylistLoadIterFunc(int fd, char *temp, char **erroredFile)
} else if ((addToPlaylist(STDERR_FILENO, temp, 0)) < 0) {
/* for windows compatibilit, convert slashes */
char *temp2 = strdup(temp);
char *temp2 = xstrdup(temp);
char *p = temp2;
while (*p) {
if (*p == '\\')
......@@ -1545,7 +1545,7 @@ static void PlaylistLoadIterFunc(int fd, char *temp, char **erroredFile)
}
if ((addToPlaylist(STDERR_FILENO, temp2, 0)) < 0) {
if (!*erroredFile) {
*erroredFile = strdup(temp);
*erroredFile = xstrdup(temp);
}
}
free(temp2);
......
......@@ -18,6 +18,7 @@
*/
#include "replayGain.h"
#include "utils.h"
#include "log.h"
#include "conf.h"
......@@ -89,7 +90,7 @@ static float computeReplayGainScale(float gain, float peak)
ReplayGainInfo *newReplayGainInfo(void)
{
ReplayGainInfo *ret = malloc(sizeof(ReplayGainInfo));
ReplayGainInfo *ret = xmalloc(sizeof(ReplayGainInfo));
ret->albumGain = 0.0;
ret->albumPeak = 0.0;
......
......@@ -30,14 +30,14 @@ static void init_strnode(struct strnode *x, char *s)
struct strnode *new_strnode(char *s)
{
struct strnode *x = malloc(sizeof(struct strnode));
struct strnode *x = xmalloc(sizeof(struct strnode));
init_strnode(x, s);
return x;
}
struct strnode *new_strnode_dup(char *s, const size_t size)
{
struct strnode *x = malloc(sizeof(struct strnode) + size);
struct strnode *x = xmalloc(sizeof(struct strnode) + size);
x->next = NULL;
x->data = ((char *)x + sizeof(struct strnode));
memcpy((void *)x->data, (void*)s, size);
......@@ -46,7 +46,7 @@ struct strnode *new_strnode_dup(char *s, const size_t size)
struct sllnode *new_sllnode(void *s, const size_t size)
{
struct sllnode *x = malloc(sizeof(struct sllnode) + size);
struct sllnode *x = xmalloc(sizeof(struct sllnode) + size);
x->next = NULL;
x->size = size;
x->data = ((char *)x + sizeof(struct sllnode));
......
......@@ -27,7 +27,7 @@
* should _NEVER_ be explicitly freed
*
* there's no free command, iterate through them yourself and just
* call free() on it iff you malloc'd them */
* call free() on it iff you xmalloc'd them */
struct strnode {
struct strnode *next;
......
......@@ -25,6 +25,7 @@
#include "path.h"
#include "playlist.h"
#include "inputPlugin.h"
#include "myfprintf.h"
#define SONG_KEY "key: "
#define SONG_FILE "file: "
......@@ -37,7 +38,7 @@
Song *newNullSong(void)
{
Song *song = malloc(sizeof(Song));
Song *song = xmalloc(sizeof(Song));
song->tag = NULL;
song->url = NULL;
......@@ -58,7 +59,7 @@ Song *newSong(char *url, int type, Directory * parentDir)
song = newNullSong();
song->url = strdup(url);
song->url = xstrdup(url);
song->type = type;
song->parentDir = parentDir;
......@@ -248,7 +249,7 @@ void readSongInfoIntoList(FILE * fp, SongList * list, Directory * parentDir)
}
song = newNullSong();
song->url = strdup(buffer + strlen(SONG_KEY));
song->url = xstrdup(buffer + strlen(SONG_KEY));
song->type = SONG_TYPE_FILE;
song->parentDir = parentDir;
} else if (0 == strncmp(SONG_FILE, buffer, strlen(SONG_FILE))) {
......@@ -257,7 +258,7 @@ void readSongInfoIntoList(FILE * fp, SongList * list, Directory * parentDir)
exit(EXIT_FAILURE);
}
/* we don't need this info anymore
song->url = strdup(&(buffer[strlen(SONG_FILE)]));
song->url = xstrdup(&(buffer[strlen(SONG_FILE)]));
*/
} else if (matchesAnMpdTagItemKey(buffer, &itemType)) {
if (!song->tag)
......@@ -346,7 +347,7 @@ char *getSongUrl(Song * song)
size = slen + dlen + 2;
if (size > bufferSize) {
buffer = realloc(buffer, size);
buffer = xrealloc(buffer, size);
bufferSize = size;
}
......
......@@ -35,13 +35,6 @@
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#ifdef HAVE_OGGVORBIS
#include <vorbis/vorbisfile.h>
#endif
#ifdef HAVE_FLAC
#include <FLAC/file_decoder.h>
#include <FLAC/metadata.h>
#endif
#ifdef HAVE_ID3TAG
# define isId3v1(tag) (id3_tag_options(tag, 0, 0) & ID3_TAG_OPTION_ID3V1)
......@@ -93,7 +86,7 @@ void initTagConfig(void)
if (0 == strcasecmp(param->value, "none"))
return;
temp = c = s = strdup(param->value);
temp = c = s = xstrdup(param->value);
while (!quit) {
if (*s == ',' || *s == '\0') {
if (*s == '\0')
......@@ -250,7 +243,7 @@ static struct id3_tag *getId3Tag(FILE * stream, long offset, int whence)
if (tagSize <= 0) return NULL;
/* Found a tag. Allocate a buffer and read it in. */
tagBuf = malloc(tagSize);
tagBuf = xmalloc(tagSize);
if (!tagBuf) return NULL;
tagBufSize = fillBuffer(tagBuf, tagSize, stream, offset, whence);
......@@ -428,7 +421,7 @@ MpdTag *apeDup(char *file)
/* read tag into buffer */
tagLen -= sizeof(footer);
buffer = malloc(tagLen);
buffer = xmalloc(tagLen);
if (fread(buffer, 1, tagLen, fp) != tagLen)
goto fail;
......@@ -481,7 +474,7 @@ fail:
MpdTag *newMpdTag(void)
{
MpdTag *ret = malloc(sizeof(MpdTag));
MpdTag *ret = xmalloc(sizeof(MpdTag));
ret->items = NULL;
ret->time = -1;
ret->numOfItems = 0;
......@@ -503,7 +496,7 @@ static void deleteItem(MpdTag * tag, int index)
}
if (tag->numOfItems > 0) {
tag->items = realloc(tag->items,
tag->items = xrealloc(tag->items,
tag->numOfItems * sizeof(MpdTagItem));
} else {
free(tag->items);
......@@ -605,7 +598,7 @@ int mpdTagsAreEqual(MpdTag * tag1, MpdTag * tag2)
static void appendToTagItems(MpdTag * tag, int type, char *value, int len)
{
int i = tag->numOfItems;
char *dup = malloc(len + 1);
char *dup = xmalloc(len + 1);
memcpy(dup, value, len);
dup[len] = '\0';
......@@ -614,7 +607,7 @@ static void appendToTagItems(MpdTag * tag, int type, char *value, int len)
stripReturnChar(dup);
tag->numOfItems++;
tag->items = realloc(tag->items, tag->numOfItems * sizeof(MpdTagItem));
tag->items = xrealloc(tag->items, tag->numOfItems * sizeof(MpdTagItem));
tag->items[i].type = type;
tag->items[i].value = getTagItemString(type, dup);
......
......@@ -20,6 +20,8 @@
#include "tree.h"
#include "log.h"
#include "utils.h"
#include "myfprintf.h"
#include <assert.h>
#include <stdlib.h>
......@@ -57,8 +59,8 @@ char *getTagItemString(int type, char *string)
}
else
{
TagTrackerItem *item = malloc(sizeof(TagTrackerItem));
char *key = strdup(string);
TagTrackerItem *item = xmalloc(sizeof(TagTrackerItem));
char *key = xstrdup(string);
item->count = 1;
item->visited = 0;
InsertInTree(tagTrees[type], key, item);
......
......@@ -17,6 +17,7 @@
*/
#include "tree.h"
#include "utils.h"
#include <assert.h>
#include <stdlib.h>
......@@ -59,7 +60,7 @@ static
TreeNode *
_MakeNode(void)
{
TreeNode * ret = malloc(sizeof(TreeNode));
TreeNode * ret = xmalloc(sizeof(TreeNode));
memset(ret, 0, sizeof(TreeNode));
return ret;
}
......@@ -571,7 +572,7 @@ MakeTree(TreeCompareKeyFunction compareKey,
TreeFreeFunction freeKey,
TreeFreeFunction freeData)
{
Tree * ret = malloc(sizeof(Tree));
Tree * ret = xmalloc(sizeof(Tree));
ret->compareKey = compareKey;
ret->freeKey = freeKey;
ret->freeData = freeData;
......
......@@ -17,6 +17,7 @@
*/
#include "utf8.h"
#include "utils.h"
#include <stdio.h>
#include <string.h>
......@@ -46,7 +47,7 @@ char *latin1StrToUtf8Dup(char *latin1)
{
/* utf8 should have at most two char's per latin1 char */
int len = strlen(latin1) * 2 + 1;
char *ret = malloc(len);
char *ret = xmalloc(len);
char *cp = ret;
char *utf8;
......@@ -63,7 +64,7 @@ char *latin1StrToUtf8Dup(char *latin1)
latin1++;
}
return realloc(ret, len + 1);
return xrealloc(ret, len + 1);
}
static char utf8ToLatin1(char *inUtf8)
......@@ -124,7 +125,7 @@ char *utf8StrToLatin1Dup(char *utf8)
{
/* utf8 should have at most two char's per latin1 char */
int len = strlen(utf8) + 1;
char *ret = malloc(len);
char *ret = xmalloc(len);
char *cp = ret;
int count;
......@@ -143,5 +144,5 @@ char *utf8StrToLatin1Dup(char *utf8)
len++;
}
return realloc(ret, len + 1);
return xrealloc(ret, len + 1);
}
......@@ -17,6 +17,7 @@
*/
#include "utils.h"
#include "log.h"
#include <stdlib.h>
#include <string.h>
......@@ -26,6 +27,7 @@
#include <sys/select.h>
#include <sys/time.h>
#include <unistd.h>
#include <assert.h>
char *myFgets(char *buffer, int bufferSize, FILE * fp)
{
......@@ -41,7 +43,7 @@ char *myFgets(char *buffer, int bufferSize, FILE * fp)
char *strDupToUpper(char *str)
{
char *ret = strdup(str);
char *ret = xstrdup(str);
int i;
for (i = 0; i < strlen(str); i++)
......@@ -86,12 +88,12 @@ char *appendToString(char *dest, const char *src)
int srclen = strlen(src);
if (dest == NULL) {
dest = malloc(srclen + 1);
dest = xmalloc(srclen + 1);
memset(dest, 0, srclen + 1);
destlen = 0;
} else {
destlen = strlen(dest);
dest = realloc(dest, destlen + srclen + 1);
dest = xrealloc(dest, destlen + srclen + 1);
}
memcpy(dest + destlen, src, srclen);
......@@ -106,3 +108,54 @@ unsigned long readLEuint32(const unsigned char *p)
((unsigned long)p[1] << 8) |
((unsigned long)p[2] << 16) | ((unsigned long)p[3] << 24);
}
mpd_malloc char *xstrdup(const char *s)
{
char *ret = strdup(s);
if (mpd_unlikely(!ret))
FATAL("OOM: strdup\n");
return ret;
}
/* borrowed from git :) */
mpd_malloc void *xmalloc(size_t size)
{
void *ret;
assert(mpd_likely(size));
ret = malloc(size);
if (mpd_unlikely(!ret))
FATAL("OOM: malloc\n");
return ret;
}
mpd_malloc void *xrealloc(void *ptr, size_t size)
{
void *ret = realloc(ptr, size);
/* some C libraries return NULL when size == 0,
* make sure we get a free()-able pointer (free(NULL)
* doesn't work with all C libraries, either) */
if (mpd_unlikely(!ret && !size))
ret = realloc(ptr, 1);
if (mpd_unlikely(!ret))
FATAL("OOM: realloc\n");
return ret;
}
mpd_malloc void *xcalloc(size_t nmemb, size_t size)
{
void *ret;
assert(mpd_likely(nmemb && size));
ret = calloc(nmemb, size);
if (mpd_unlikely(!ret))
FATAL("OOM: calloc\n");
return ret;
}
......@@ -20,6 +20,7 @@
#define UTILS_H
#include "../config.h"
#include "gcc.h"
#include <unistd.h>
#include <stdlib.h>
......@@ -73,4 +74,12 @@ static inline ssize_t xwrite(int fd, const void *buf, size_t len)
}
}
mpd_malloc char *xstrdup(const char *s);
mpd_malloc void *xmalloc(size_t size);
mpd_malloc void *xrealloc(void *ptr, size_t size);
mpd_malloc void *xcalloc(size_t nmemb, size_t size);
#endif
......@@ -112,7 +112,7 @@ static int prepOssMixer(char *device)
}
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
dup = strdup(labels[i]);
dup = xstrdup(labels[i]);
/* eliminate spaces at the end */
j = strlen(dup) - 1;
while (j >= 0 && dup[j] == ' ')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment