Discussion:
[PATCH 03/17] portability: replace (_ & S_IFREG) with S_ISREG(_)
Johannes Weißl
2011-05-05 15:20:03 UTC
Permalink
S_ISREG is described by POSIX, S_IFREG not (only Unix V7).
---
ape.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/ape.c b/ape.c
index 197de81..0c5940c 100644
--- a/ape.c
+++ b/ape.c
@@ -203,7 +203,7 @@ static off_t get_size(int fd)
{
struct stat statbuf;

- if (fstat(fd, &statbuf) || !(statbuf.st_mode & S_IFREG))
+ if (fstat(fd, &statbuf) || !S_ISREG(statbuf.st_mode))
return 0;
return statbuf.st_size;
}
--
1.7.5
Johannes Weißl
2011-05-05 15:20:02 UTC
Permalink
<strings.h> for strcasecmp()
<sys/select.h> for select()
<string.h> for strcmp()
---
http.c | 1 +
tree.c | 1 +
ui_curses.c | 1 +
wav.c | 1 +
4 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/http.c b/http.c
index 1a53cf6..b504ad1 100644
--- a/http.c
+++ b/http.c
@@ -27,6 +27,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
+#include <sys/select.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
diff --git a/tree.c b/tree.c
index db70d7a..c80cef5 100644
--- a/tree.c
+++ b/tree.c
@@ -29,6 +29,7 @@

#include <ctype.h>
#include <stdio.h>
+#include <string.h>
#include <strings.h>

struct searchable *tree_searchable;
diff --git a/ui_curses.c b/ui_curses.c
index 00a6246..f716e7c 100644
--- a/ui_curses.c
+++ b/ui_curses.c
@@ -53,6 +53,7 @@
#include <stdio.h>
#include <errno.h>
#include <sys/ioctl.h>
+#include <sys/select.h>
#include <ctype.h>
#include <dirent.h>
#include <locale.h>
diff --git a/wav.c b/wav.c
index ae202dd..6675ba8 100644
--- a/wav.c
+++ b/wav.c
@@ -24,6 +24,7 @@

#include <stdio.h>
#include <string.h>
+#include <strings.h>
#include <errno.h>

#include <sys/types.h>
--
1.7.5
Johannes Weißl
2011-05-05 15:20:04 UTC
Permalink
alloca is not POSIX, and has no benefit here at all.
---
alsa.c | 8 +++++---
mixer_alsa.c | 14 +++++++-------
2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/alsa.c b/alsa.c
index a73bfe5..7acbbdd 100644
--- a/alsa.c
+++ b/alsa.c
@@ -124,12 +124,12 @@ static int op_alsa_exit(void)
/* randomize hw params */
static int alsa_set_hw_params(void)
{
- snd_pcm_hw_params_t *hwparams;
+ snd_pcm_hw_params_t *hwparams = NULL;
const char *cmd;
unsigned int rate;
int rc, dir;

- snd_pcm_hw_params_alloca(&hwparams);
+ snd_pcm_hw_params_malloc(&hwparams);

cmd = "snd_pcm_hw_params_any";
rc = snd_pcm_hw_params_any(alsa_handle, hwparams);
@@ -170,9 +170,11 @@ static int alsa_set_hw_params(void)
rc = snd_pcm_hw_params(alsa_handle, hwparams);
if (rc < 0)
goto error;
- return 0;
+ goto out;
error:
d_print("%s: error: %s\n", cmd, snd_strerror(rc));
+out:
+ snd_pcm_hw_params_free(hwparams);
return rc;
}

diff --git a/mixer_alsa.c b/mixer_alsa.c
index f3dcff5..0b9d13c 100644
--- a/mixer_alsa.c
+++ b/mixer_alsa.c
@@ -58,9 +58,9 @@ static int alsa_mixer_exit(void)
static snd_mixer_elem_t *find_mixer_elem_by_name(const char *goal_name)
{
snd_mixer_elem_t *elem;
- snd_mixer_selem_id_t *sid;
+ snd_mixer_selem_id_t *sid = NULL;

- snd_mixer_selem_id_alloca(&sid);
+ snd_mixer_selem_id_malloc(&sid);

for (elem = snd_mixer_first_elem(alsa_mixer_handle); elem;
elem = snd_mixer_elem_next(elem)) {
@@ -74,16 +74,16 @@ static snd_mixer_elem_t *find_mixer_elem_by_name(const char *goal_name)
d_print("has playback switch = %d\n", snd_mixer_selem_has_playback_switch(elem));

if (strcasecmp(name, goal_name) == 0) {
- if (snd_mixer_selem_has_playback_volume(elem)) {
- return elem;
- } else {
+ if (!snd_mixer_selem_has_playback_volume(elem)) {
d_print("mixer element `%s' does not have playback volume\n", name);
- return NULL;
+ elem = NULL;
}
+ break;
}
}

- return NULL;
+ snd_mixer_selem_id_free(sid);
+ return elem;
}

static int alsa_mixer_open(int *volume_max)
--
1.7.5
Johannes Weißl
2011-05-05 15:20:06 UTC
Permalink
NO_ADDRESS is not defined in POSIX.
---
main.c | 2 +-
server.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/main.c b/main.c
index 83bb55d..2c65f9b 100644
--- a/main.c
+++ b/main.c
@@ -44,7 +44,7 @@ static void gethostbyname_failed(void)

switch (h_errno) {
case HOST_NOT_FOUND:
- case NO_ADDRESS:
+ case NO_DATA:
error = "Host not found.";
break;
case NO_RECOVERY:
diff --git a/server.c b/server.c
index 1410e80..88593af 100644
--- a/server.c
+++ b/server.c
@@ -258,7 +258,7 @@ static void gethostbyname_failed(void)

switch (h_errno) {
case HOST_NOT_FOUND:
- case NO_ADDRESS:
+ case NO_DATA:
error = "Host not found.";
break;
case NO_RECOVERY:
--
1.7.5
Johannes Weißl
2011-05-05 15:20:09 UTC
Permalink
Setting memory of pointers to 0 violates the C standard. Also this
solution is more readable!
---
aac.c | 11 +++++++----
flac.c | 16 ++++++++++------
mp4.c | 6 +++++-
mpc.c | 25 +++++++++++++++----------
nomad.c | 14 +++++++++++---
wavpack.c | 12 +++++++++---
6 files changed, 57 insertions(+), 27 deletions(-)

diff --git a/aac.c b/aac.c
index 56d4bc5..3b3552a 100644
--- a/aac.c
+++ b/aac.c
@@ -193,10 +193,13 @@ static int aac_open(struct input_plugin_data *ip_data)
int ret, n;

/* init private struct */
- priv = xnew0(struct aac_private, 1);
- priv->decoder = NeAACDecOpen();
- priv->bitrate = -1;
- priv->object_type = -1;
+ const struct aac_private priv_init = {
+ .decoder = NeAACDecOpen(),
+ .bitrate = -1,
+ .object_type = -1
+ };
+ priv = xnew(struct aac_private, 1);
+ *priv = priv_init;
ip_data->private = priv;

/* set decoder config */
diff --git a/flac.c b/flac.c
index 3b02a77..64b1d0d 100644
--- a/flac.c
+++ b/flac.c
@@ -378,15 +378,19 @@ static void free_priv(struct input_plugin_data *ip_data)
static int flac_open(struct input_plugin_data *ip_data)
{
struct flac_private *priv;
- Dec *dec;

- dec = F(new)();
- if (dec == NULL)
+ Dec *dec = F(new)();
+
+ const struct flac_private priv_init = {
+ .dec = dec,
+ .duration = -1
+ };
+
+ if (!dec)
return -IP_ERROR_INTERNAL;

- priv = xnew0(struct flac_private, 1);
- priv->dec = dec;
- priv->duration = -1;
+ priv = xnew(struct flac_private, 1);
+ *priv = priv_init;
if (ip_data->remote) {
priv->len = UINT64_MAX;
} else {
diff --git a/mp4.c b/mp4.c
index 43b20b8..8afc5fe 100644
--- a/mp4.c
+++ b/mp4.c
@@ -99,13 +99,17 @@ static int mp4_open(struct input_plugin_data *ip_data)
unsigned int buf_size;
int rc = -IP_ERROR_FILE_FORMAT;

+ const struct mp4_private priv_init = {
+ .decoder = NULL
+ };

/* http://sourceforge.net/forum/message.php?msg_id=3578887 */
if (ip_data->remote)
return -IP_ERROR_FUNCTION_NOT_SUPPORTED;

/* init private struct */
- priv = xnew0(struct mp4_private, 1);
+ priv = xnew(struct mp4_private, 1);
+ *priv = priv_init;
ip_data->private = priv;

priv->decoder = NeAACDecOpen();
diff --git a/mpc.c b/mpc.c
index cff2387..8320191 100644
--- a/mpc.c
+++ b/mpc.c
@@ -123,22 +123,27 @@ static int mpc_open(struct input_plugin_data *ip_data)
{
struct mpc_private *priv;

- priv = xnew0(struct mpc_private, 1);
+ const struct mpc_private priv_init = {
+ .file_size = -1,
+ /* set up an mpc_reader linked to our function implementations */
+ .reader = {
+ .read = read_impl,
+ .seek = seek_impl,
+ .tell = tell_impl,
+ .get_size = get_size_impl,
+ .canseek = canseek_impl,
+ .data = ip_data
+ }
+ };
+
+ priv = xnew(struct mpc_private, 1);
+ *priv = priv_init;

- priv->file_size = -1;
if (!ip_data->remote) {
priv->file_size = lseek(ip_data->fd, 0, SEEK_END);
lseek(ip_data->fd, 0, SEEK_SET);
}

- /* set up an mpc_reader linked to our function implementations */
- priv->reader.read = read_impl;
- priv->reader.seek = seek_impl;
- priv->reader.tell = tell_impl;
- priv->reader.get_size = get_size_impl;
- priv->reader.canseek = canseek_impl;
- priv->reader.data = ip_data;
-
/* must be before mpc_streaminfo_read() */
ip_data->private = priv;

diff --git a/nomad.c b/nomad.c
index 453ee07..e892d78 100644
--- a/nomad.c
+++ b/nomad.c
@@ -585,9 +585,17 @@ int nomad_open_callbacks(struct nomad **nomadp, void *datasource, struct nomad_c
{
struct nomad *nomad;

- nomad = xnew0(struct nomad, 1);
- nomad->datasource = datasource;
- nomad->cbs = *cbs;
+ const struct nomad nomad_init = {
+ .datasource = datasource,
+ .cbs = {
+ .read = cbs->read,
+ .lseek = cbs->lseek,
+ .close = cbs->close
+ }
+ };
+
+ nomad = xnew(struct nomad, 1);
+ *nomad = nomad_init;
nomad->lame.peak = nomad->lame.trackGain = nomad->lame.albumGain = strtof("NAN", NULL);
*nomadp = nomad;
/* on error do_open calls nomad_close */
diff --git a/wavpack.c b/wavpack.c
index 9d57400..257d5b5 100644
--- a/wavpack.c
+++ b/wavpack.c
@@ -165,9 +165,15 @@ static int wavpack_open(struct input_plugin_data *ip_data)
struct stat st;
char msg[80];

- priv = xnew0(struct wavpack_private, 1);
- priv->wv_file.fd = ip_data->fd;
- priv->wv_file.push_back_byte = EOF;
+ const struct wavpack_private priv_init = {
+ .wv_file = {
+ .fd = ip_data->fd,
+ .push_back_byte = EOF
+ }
+ };
+
+ priv = xnew(struct wavpack_private, 1);
+ *priv = priv_init;
if (!ip_data->remote && fstat(ip_data->fd, &st) == 0) {
char *filename_wvc;
--
1.7.5
Johannes Weißl
2011-05-05 15:20:10 UTC
Permalink
---
ape.c | 1 -
browser.c | 1 -
cmus.c | 1 -
command_mode.c | 1 -
filters.h | 1 -
help.h | 1 -
id3.c | 1 -
lib.h | 2 --
options.c | 1 -
read_wrapper.c | 2 --
track.c | 1 -
tree.c | 1 -
12 files changed, 0 insertions(+), 14 deletions(-)

diff --git a/ape.c b/ape.c
index 0c5940c..9e8bb5f 100644
--- a/ape.c
+++ b/ape.c
@@ -18,7 +18,6 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

-#include "ip.h"
#include "ape.h"
#include "file.h"
#include "xmalloc.h"
diff --git a/browser.c b/browser.c
index 397ceda..d715b63 100644
--- a/browser.c
+++ b/browser.c
@@ -20,7 +20,6 @@
#include "load_dir.h"
#include "cmus.h"
#include "xmalloc.h"
-#include "xstrjoin.h"
#include "ui_curses.h"
#include "file.h"
#include "misc.h"
diff --git a/cmus.c b/cmus.c
index 96a9e69..0d869fd 100644
--- a/cmus.c
+++ b/cmus.c
@@ -31,7 +31,6 @@
#include "path.h"
#include "options.h"
#include "xmalloc.h"
-#include "xstrjoin.h"
#include "debug.h"
#include "load_dir.h"
#include "ui_curses.h"
diff --git a/command_mode.c b/command_mode.c
index 2e0d645..e13c2a4 100644
--- a/command_mode.c
+++ b/command_mode.c
@@ -39,7 +39,6 @@
#include "xstrjoin.h"
#include "misc.h"
#include "path.h"
-#include "format_print.h"
#include "spawn.h"
#include "utils.h"
#include "list.h"
diff --git a/filters.h b/filters.h
index 9a964db..4a60972 100644
--- a/filters.h
+++ b/filters.h
@@ -22,7 +22,6 @@
#include "list.h"
#include "window.h"
#include "search.h"
-#include "uchar.h"

/* factivate foo !bar
*
diff --git a/help.h b/help.h
index 3dd49a4..c81d782 100644
--- a/help.h
+++ b/help.h
@@ -24,7 +24,6 @@
#include "list.h"
#include "window.h"
#include "search.h"
-#include "uchar.h"
#include "keys.h"

struct help_entry {
diff --git a/id3.c b/id3.c
index 47b605a..8c6d82a 100644
--- a/id3.c
+++ b/id3.c
@@ -17,7 +17,6 @@
*/

#include "id3.h"
-#include "comment.h"
#include "xmalloc.h"
#include "convert.h"
#include "uchar.h"
diff --git a/lib.h b/lib.h
index 5c30bf3..ae3dcd0 100644
--- a/lib.h
+++ b/lib.h
@@ -25,8 +25,6 @@
#include "expr.h"
#include "rbtree.h"

-#include <sys/time.h>
-
struct tree_track {
struct shuffle_track shuffle_track;

diff --git a/options.c b/options.c
index 6f9eb75..9c49d90 100644
--- a/options.c
+++ b/options.c
@@ -23,7 +23,6 @@
#include "player.h"
#include "buffer.h"
#include "ui_curses.h"
-#include "format_print.h"
#include "cmus.h"
#include "misc.h"
#include "lib.h"
diff --git a/read_wrapper.c b/read_wrapper.c
index 18a2344..df2e961 100644
--- a/read_wrapper.c
+++ b/read_wrapper.c
@@ -20,8 +20,6 @@
#include "ip.h"
#include "file.h"

-#include <errno.h>
-#include <string.h>

ssize_t read_wrapper(struct input_plugin_data *ip_data, void *buffer, size_t count)
{
diff --git a/track.c b/track.c
index ed64b9b..16545bb 100644
--- a/track.c
+++ b/track.c
@@ -21,7 +21,6 @@
#include "search_mode.h"
#include "window.h"
#include "options.h"
-#include "comment.h"
#include "uchar.h"
#include "xmalloc.h"

diff --git a/tree.c b/tree.c
index c80cef5..e359e23 100644
--- a/tree.c
+++ b/tree.c
@@ -19,7 +19,6 @@
#include "lib.h"
#include "search_mode.h"
#include "xmalloc.h"
-#include "comment.h"
#include "utils.h"
#include "debug.h"
#include "mergesort.h"
--
1.7.5
Johannes Weißl
2011-05-05 15:20:05 UTC
Permalink
---
compiler.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/compiler.h b/compiler.h
index 7143431..adf5d54 100644
--- a/compiler.h
+++ b/compiler.h
@@ -75,7 +75,7 @@
((type *)(void *)( (char *)(ptr) - offsetof(type,member) ))
#undef container_of
#if defined(__GNUC__)
-#define container_of(ptr, type, member) ({ \
+#define container_of(ptr, type, member) __extension__ ({ \
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
container_of_portable(__mptr, type, member);})
#else
--
1.7.5
Johannes Weißl
2011-05-05 15:20:12 UTC
Permalink
inttypes.h includes stdint.h, but additional stuff not needed.
---
ape.h | 2 +-
debug.h | 2 +-
flac.c | 2 +-
id3.c | 2 +-
mpc.c | 2 +-
pcm.c | 2 +-
utils.h | 2 +-
7 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/ape.h b/ape.h
index f0b97b5..010522b 100644
--- a/ape.h
+++ b/ape.h
@@ -19,7 +19,7 @@
#ifndef _APE_H
#define _APE_H

-#include <inttypes.h>
+#include <stdint.h>
#include <stdlib.h>

struct ape_header {
diff --git a/debug.h b/debug.h
index fe19141..5cd6b64 100644
--- a/debug.h
+++ b/debug.h
@@ -23,7 +23,7 @@
#include "config/debug.h"

#include <errno.h>
-#include <inttypes.h>
+#include <stdint.h>

void debug_init(void);
void __debug_bug(const char *function, const char *fmt, ...) __FORMAT(2, 3) __NORETURN;
diff --git a/flac.c b/flac.c
index 64b1d0d..5d82833 100644
--- a/flac.c
+++ b/flac.c
@@ -36,7 +36,7 @@
#endif

#include <FLAC/metadata.h>
-#include <inttypes.h>
+#include <stdint.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
diff --git a/id3.c b/id3.c
index 8c6d82a..a48e0e3 100644
--- a/id3.c
+++ b/id3.c
@@ -25,7 +25,7 @@
#include "utils.h"

#include <unistd.h>
-#include <inttypes.h>
+#include <stdint.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
diff --git a/mpc.c b/mpc.c
index 8320191..3599573 100644
--- a/mpc.c
+++ b/mpc.c
@@ -39,7 +39,7 @@
#define get_ip_data(d) (d)
#endif

-#include <inttypes.h>
+#include <stdint.h>
#include <errno.h>

struct mpc_private {
diff --git a/pcm.c b/pcm.c
index bd127a1..e2ed62f 100644
--- a/pcm.c
+++ b/pcm.c
@@ -19,7 +19,7 @@
#include "pcm.h"
#include "utils.h"

-#include <inttypes.h>
+#include <stdint.h>
#include <stdlib.h>

/*
diff --git a/utils.h b/utils.h
index be22a01..cd95426 100644
--- a/utils.h
+++ b/utils.h
@@ -27,7 +27,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
-#include <inttypes.h>
+#include <stdint.h>
#ifdef HAVE_BYTESWAP_H
#include <byteswap.h>
#endif
--
1.7.5
Johannes Weißl
2011-05-05 15:20:07 UTC
Permalink
Setting memory of pointers to 0 violates the C standard. Also this
solution is more readable!
---
ao.c | 14 ++++++--------
id3.c | 3 ++-
input.c | 22 ++++++++++++----------
waveout.c | 19 +++++++++----------
4 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/ao.c b/ao.c
index 668eb32..0c79ae7 100644
--- a/ao.c
+++ b/ao.c
@@ -57,7 +57,12 @@ static int op_ao_exit(void)

static int op_ao_open(sample_format_t sf)
{
- ao_sample_format format;
+ ao_sample_format format = {
+ .bits = sf_get_bits(sf),
+ .rate = sf_get_rate(sf),
+ .channels = sf_get_channels(sf),
+ .byte_format = sf_get_bigendian(sf) ? AO_FMT_BIG : AO_FMT_LITTLE
+ };
int driver;

if (libao_driver == NULL) {
@@ -71,13 +76,6 @@ static int op_ao_open(sample_format_t sf)
return -OP_ERROR_ERRNO;
}

- memset(&format, 0, sizeof format);
-
- format.bits = sf_get_bits(sf);
- format.rate = sf_get_rate(sf);
- format.channels = sf_get_channels(sf);
- format.byte_format = sf_get_bigendian(sf) ? AO_FMT_BIG : AO_FMT_LITTLE;
-
if (is_wav) {
char file[512];

diff --git a/id3.c b/id3.c
index ea6352e..47b605a 100644
--- a/id3.c
+++ b/id3.c
@@ -1111,7 +1111,8 @@ int id3_tag_size(const char *buf, int buf_size)

void id3_init(struct id3tag *id3)
{
- memset(id3, 0, sizeof(*id3));
+ const struct id3tag t = { .has_v1 = 0, .has_v2 = 0 };
+ *id3 = t;
}

void id3_free(struct id3tag *id3)
diff --git a/input.c b/input.c
index e82af16..e203528 100644
--- a/input.c
+++ b/input.c
@@ -378,16 +378,18 @@ static int open_remote(struct input_plugin *ip)

static void ip_init(struct input_plugin *ip, char *filename)
{
- memset(ip, 0, sizeof(*ip));
- ip->http_code = -1;
- ip->pcm_convert_scale = -1;
- ip->duration = -1;
- ip->bitrate = -1;
- ip->codec = NULL;
- ip->codec_profile = NULL;
- ip->data.fd = -1;
- ip->data.filename = filename;
- ip->data.remote = is_url(filename);
+ const struct input_plugin t = {
+ .http_code = -1,
+ .pcm_convert_scale = -1,
+ .duration = -1,
+ .bitrate = -1,
+ .data = {
+ .fd = -1,
+ .filename = filename,
+ .remote = is_url(filename)
+ }
+ };
+ *ip = t;
}

static void ip_reset(struct input_plugin *ip, int close_fd)
diff --git a/waveout.c b/waveout.c
index 90dac1d..9c2a326 100644
--- a/waveout.c
+++ b/waveout.c
@@ -77,7 +77,15 @@ static void clean_buffers(void)

static int waveout_open(sample_format_t sf)
{
- WAVEFORMATEX format;
+ WAVEFORMATEX format = {
+ .cbSize = sizeof(format),
+ .wFormatTag = WAVE_FORMAT_PCM,
+ .nChannels = sf_get_channels(sf),
+ .nSamplesPerSec = sf_get_rate(sf),
+ .wBitsPerSample = sf_get_bits(sf),
+ .nAvgBytesPerSec = sf_get_second_size(sf),
+ .nBlockAlign = sf_get_frame_size(sf)
+ };
int rc, i;

/* WAVEFORMATEX does not support channels > 2, waveOutWrite() wants little endian signed PCM */
@@ -85,15 +93,6 @@ static int waveout_open(sample_format_t sf)
return -OP_ERROR_SAMPLE_FORMAT;
}

- memset(&format, 0, sizeof(format));
- format.cbSize = sizeof(format);
- format.wFormatTag = WAVE_FORMAT_PCM;
- format.nChannels = sf_get_channels(sf);
- format.nSamplesPerSec = sf_get_rate(sf);
- format.wBitsPerSample = sf_get_bits(sf);
- format.nAvgBytesPerSec = sf_get_second_size(sf);
- format.nBlockAlign = sf_get_frame_size(sf);
-
rc = waveOutOpen(&wave_out, WAVE_MAPPER, &format, 0, 0, CALLBACK_NULL);
if (rc != MMSYSERR_NOERROR) {
switch (rc) {
--
1.7.5
Johannes Weißl
2011-05-05 15:20:08 UTC
Permalink
Setting memory of pointers to 0 violates the C standard. Also this
solution is more readable!
---
ffmpeg.c | 2 +-
flac.c | 2 +-
keyval.c | 12 ++++++++++++
keyval.h | 1 +
vorbis.c | 2 +-
5 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index c789757..a5336fd 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -404,7 +404,7 @@ static int ffmpeg_read_comments(struct input_plugin_data *ip_data, struct keyval
char buff[16];
int i = 0;

- *comments = xnew0(struct keyval, NUM_FFMPEG_KEYS + 1);
+ *comments = keyvals_new(NUM_FFMPEG_KEYS);

i = set_comment(*comments, i, "artist", ic->author);
i = set_comment(*comments, i, "album", ic->album);
diff --git a/flac.c b/flac.c
index 49f9b2c..3b02a77 100644
--- a/flac.c
+++ b/flac.c
@@ -522,7 +522,7 @@ static int flac_read_comments(struct input_plugin_data *ip_data, struct keyval *
if (priv->comments) {
*comments = keyvals_dup(priv->comments);
} else {
- *comments = xnew0(struct keyval, 1);
+ *comments = keyvals_new(0);
}
return 0;
}
diff --git a/keyval.c b/keyval.c
index 9ffa473..1336a88 100644
--- a/keyval.c
+++ b/keyval.c
@@ -22,6 +22,18 @@

#include <strings.h>

+struct keyval *keyvals_new(int num)
+{
+ struct keyval *c = xnew(struct keyval, num + 1);
+ int i;
+
+ for (i = 0; i <= num; i++) {
+ c[i].key = NULL;
+ c[i].val = NULL;
+ }
+ return c;
+}
+
struct keyval *keyvals_dup(const struct keyval *keyvals)
{
struct keyval *c;
diff --git a/keyval.h b/keyval.h
index 8192baa..9915499 100644
--- a/keyval.h
+++ b/keyval.h
@@ -32,6 +32,7 @@ struct growing_keyvals {

#define GROWING_KEYVALS(name) struct growing_keyvals name = { NULL, 0, 0 }

+struct keyval *keyvals_new(int num);
void keyvals_init(struct growing_keyvals *c, const struct keyval *keyvals);
void keyvals_add(struct growing_keyvals *c, const char *key, char *val);
const char *keyvals_get_val_growing(const struct growing_keyvals *c, const char *key);
diff --git a/vorbis.c b/vorbis.c
index 5143960..4e406a9 100644
--- a/vorbis.c
+++ b/vorbis.c
@@ -256,7 +256,7 @@ static int vorbis_read_comments(struct input_plugin_data *ip_data,
vc = ov_comment(&priv->vf, -1);
if (vc == NULL) {
d_print("vc == NULL\n");
- *comments = xnew0(struct keyval, 1);
+ *comments = keyvals_new(0);
return 0;
}
for (i = 0; i < vc->comments; i++) {
--
1.7.5
Johannes Weißl
2011-05-05 15:20:13 UTC
Permalink
---
browser.c | 2 ++
browser.h | 1 -
cache.c | 1 +
file.h | 4 ++--
job.c | 1 +
5 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/browser.c b/browser.c
index d715b63..71edfbd 100644
--- a/browser.c
+++ b/browser.c
@@ -24,6 +24,7 @@
#include "file.h"
#include "misc.h"
#include "options.h"
+#include "uchar.h"

#include <sys/types.h>
#include <sys/stat.h>
@@ -31,6 +32,7 @@
#include <dirent.h>
#include <string.h>
#include <errno.h>
+#include <sys/mman.h>

struct window *browser_win;
struct searchable *browser_searchable;
diff --git a/browser.h b/browser.h
index 261b13b..833c9de 100644
--- a/browser.h
+++ b/browser.h
@@ -22,7 +22,6 @@
#include "list.h"
#include "window.h"
#include "search.h"
-#include "uchar.h"

struct browser_entry {
struct list_head node;
diff --git a/cache.c b/cache.c
index 3a1e608..b334cc6 100644
--- a/cache.c
+++ b/cache.c
@@ -33,6 +33,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
+#include <sys/mman.h>

#define CACHE_64_BIT 0x01
#define CACHE_BE 0x02
diff --git a/file.h b/file.h
index 174c3ef..665eb64 100644
--- a/file.h
+++ b/file.h
@@ -19,8 +19,8 @@
#ifndef _FILE_H
#define _FILE_H

-#include <unistd.h>
-#include <sys/mman.h>
+#include <stddef.h> /* size_t */
+#include <sys/types.h> /* ssize_t */

ssize_t read_all(int fd, void *buf, size_t count);
ssize_t write_all(int fd, const void *buf, size_t count);
diff --git a/job.c b/job.c
index 802b626..d10e391 100644
--- a/job.c
+++ b/job.c
@@ -33,6 +33,7 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
+#include <sys/mman.h>

static struct track_info *ti_buffer[32];
static int ti_buffer_fill;
--
1.7.5
Johannes Weißl
2011-05-05 15:20:14 UTC
Permalink
does not need anything from comment.h
---
ffmpeg.c | 1 +
input.h | 2 +-
ip.h | 2 +-
mad.c | 1 +
mikmod.c | 1 +
modplug.c | 1 +
mp4.c | 1 +
vorbis.c | 1 +
wav.c | 1 +
wavpack.c | 1 +
10 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index a5336fd..4d65388 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -20,6 +20,7 @@
#include "xmalloc.h"
#include "debug.h"
#include "utils.h"
+#include "comment.h"
#include "config/ffmpeg.h"

#include <stdio.h>
diff --git a/input.h b/input.h
index 23c53e6..7fd4a63 100644
--- a/input.h
+++ b/input.h
@@ -19,7 +19,7 @@
#ifndef _INPUT_H
#define _INPUT_H

-#include "comment.h"
+#include "keyval.h"
#include "sf.h"

struct input_plugin;
diff --git a/ip.h b/ip.h
index 5179339..29f1975 100644
--- a/ip.h
+++ b/ip.h
@@ -19,7 +19,7 @@
#ifndef _IP_H
#define _IP_H

-#include "comment.h"
+#include "keyval.h"
#include "sf.h"

#ifndef __GNUC__
diff --git a/mad.c b/mad.c
index d7c925e..2d868ce 100644
--- a/mad.c
+++ b/mad.c
@@ -24,6 +24,7 @@
#include "read_wrapper.h"
#include "debug.h"
#include "utils.h"
+#include "comment.h"

#include <stdio.h>
#include <math.h>
diff --git a/mikmod.c b/mikmod.c
index f8a5631..259bd9c 100644
--- a/mikmod.c
+++ b/mikmod.c
@@ -23,6 +23,7 @@
#include "xmalloc.h"
#include <mikmod.h>
#include "debug.h"
+#include "comment.h"

struct mik_private {
MODULE *file;
diff --git a/modplug.c b/modplug.c
index 95dbe98..c00ecea 100644
--- a/modplug.c
+++ b/modplug.c
@@ -19,6 +19,7 @@
#include "ip.h"
#include "file.h"
#include "xmalloc.h"
+#include "comment.h"
#include "config/modplug.h"

#include <modplug.h>
diff --git a/mp4.c b/mp4.c
index 8afc5fe..53aa574 100644
--- a/mp4.c
+++ b/mp4.c
@@ -21,6 +21,7 @@
#include "debug.h"
#include "file.h"
#include "config/mp4.h"
+#include "comment.h"

#if USE_MPEG4IP
#include <mp4.h>
diff --git a/vorbis.c b/vorbis.c
index 4e406a9..a086d65 100644
--- a/vorbis.c
+++ b/vorbis.c
@@ -21,6 +21,7 @@
#include "read_wrapper.h"
#include "debug.h"
#include "config/tremor.h"
+#include "comment.h"

#ifdef CONFIG_TREMOR
#include <tremor/ivorbisfile.h>
diff --git a/wav.c b/wav.c
index 6675ba8..70efc98 100644
--- a/wav.c
+++ b/wav.c
@@ -21,6 +21,7 @@
#include "xmalloc.h"
#include "debug.h"
#include "utils.h"
+#include "comment.h"

#include <stdio.h>
#include <string.h>
diff --git a/wavpack.c b/wavpack.c
index 257d5b5..6694cba 100644
--- a/wavpack.c
+++ b/wavpack.c
@@ -23,6 +23,7 @@
#include "read_wrapper.h"
#include "debug.h"
#include "buffer.h"
+#include "comment.h"

#include <wavpack/wavpack.h>
--
1.7.5
Johannes Weißl
2011-05-05 15:20:15 UTC
Permalink
---
command_mode.c | 1 +
output.h | 2 --
ui_curses.c | 1 +
3 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/command_mode.c b/command_mode.c
index e13c2a4..642d21e 100644
--- a/command_mode.c
+++ b/command_mode.c
@@ -46,6 +46,7 @@
#include "load_dir.h"
#include "config/datadir.h"
#include "help.h"
+#include "op.h"

#include <stdlib.h>
#include <ctype.h>
diff --git a/output.h b/output.h
index 89a469d..8445d7c 100644
--- a/output.h
+++ b/output.h
@@ -19,8 +19,6 @@
#ifndef _OUTPUT_H
#define _OUTPUT_H

-#include "mixer.h"
-#include "op.h"
#include "sf.h"

extern int volume_max;
diff --git a/ui_curses.c b/ui_curses.c
index f716e7c..7b665ef 100644
--- a/ui_curses.c
+++ b/ui_curses.c
@@ -45,6 +45,7 @@
#include "worker.h"
#include "input.h"
#include "file.h"
+#include "mixer.h"
#include "config/curses.h"
#include "config/iconv.h"
--
1.7.5
Johannes Weißl
2011-05-05 15:20:17 UTC
Permalink
---
mpc.c | 2 ++
read_wrapper.c | 1 +
read_wrapper.h | 3 ++-
3 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/mpc.c b/mpc.c
index 3599573..6561328 100644
--- a/mpc.c
+++ b/mpc.c
@@ -40,6 +40,8 @@
#endif

#include <stdint.h>
+#include <sys/types.h>
+#include <unistd.h>
#include <errno.h>

struct mpc_private {
diff --git a/read_wrapper.c b/read_wrapper.c
index df2e961..328ddee 100644
--- a/read_wrapper.c
+++ b/read_wrapper.c
@@ -20,6 +20,7 @@
#include "ip.h"
#include "file.h"

+#include <unistd.h>

ssize_t read_wrapper(struct input_plugin_data *ip_data, void *buffer, size_t count)
{
diff --git a/read_wrapper.h b/read_wrapper.h
index 0dfb2f1..a391a3f 100644
--- a/read_wrapper.h
+++ b/read_wrapper.h
@@ -21,7 +21,8 @@

#include "ip.h"

-#include <unistd.h>
+#include <stddef.h> /* size_t */
+#include <sys/types.h> /* ssize_t */

ssize_t read_wrapper(struct input_plugin_data *ip_data, void *buffer, size_t count);
--
1.7.5
Johannes Weißl
2011-05-05 15:20:11 UTC
Permalink
---
gbuf.h | 2 +-
http.h | 2 +-
iter.h | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gbuf.h b/gbuf.h
index fdddcfc..2ce7f26 100644
--- a/gbuf.h
+++ b/gbuf.h
@@ -23,7 +23,7 @@

#include "compiler.h"

-#include <string.h>
+#include <stddef.h> /* size_t */

struct gbuf {
char *buffer;
diff --git a/http.h b/http.h
index bfdcc6b..c964aae 100644
--- a/http.h
+++ b/http.h
@@ -21,7 +21,7 @@

#include "keyval.h"

-#include <unistd.h>
+#include <stddef.h> /* size_t */

/*
* 1xx indicates an informational message only
diff --git a/iter.h b/iter.h
index 6915d6c..4be4c74 100644
--- a/iter.h
+++ b/iter.h
@@ -19,7 +19,7 @@
#ifndef _ITER_H
#define _ITER_H

-#include <stdlib.h>
+#include <stddef.h> /* NULL */

struct iter {
/* this usually points to the list head */
--
1.7.5
Johannes Weißl
2011-05-05 15:20:16 UTC
Permalink
---
player.h | 1 -
server.c | 1 +
ui_curses.c | 1 +
3 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/player.h b/player.h
index b8a0d87..5e9efe1 100644
--- a/player.h
+++ b/player.h
@@ -20,7 +20,6 @@
#define _PLAYER_H

#include "locking.h"
-#include "comment.h"
#include "track_info.h"

#include <pthread.h>
diff --git a/server.c b/server.c
index 88593af..2d4e231 100644
--- a/server.c
+++ b/server.c
@@ -31,6 +31,7 @@
#include "gbuf.h"
#include "ui_curses.h"
#include "misc.h"
+#include "keyval.h"

#include <unistd.h>
#include <sys/types.h>
diff --git a/ui_curses.c b/ui_curses.c
index 7b665ef..c70c16d 100644
--- a/ui_curses.c
+++ b/ui_curses.c
@@ -34,6 +34,7 @@
#include "xstrjoin.h"
#include "window.h"
#include "format_print.h"
+#include "comment.h"
#include "misc.h"
#include "prog.h"
#include "uchar.h"
--
1.7.5
Gregory Petrosyan
2011-05-05 16:55:17 UTC
Permalink
Merged all 17 to master, thanks! Although I don't get what is wrong with
setting pointer's memory to 0, to be honest.

Gregory
Johannes Weißl
2011-05-05 17:44:04 UTC
Permalink
Hi Gregory,
Post by Gregory Petrosyan
Merged all 17 to master, thanks! Although I don't get what is wrong with
setting pointer's memory to 0, to be honest.
Thanks! It's just that pointers and floating point numbers which are
equal to 0 don't necessarily have all bits 0 (you probably know that).
But since it works on all (modern) known systems, it is more an
aesthetical than a portability issue. Why not write standard conform
code if it is possible and not harder/longer/slower?

Johannes
Gregory Petrosyan
2011-05-05 19:30:39 UTC
Permalink
Post by Johannes Weißl
Hi Gregory,
Post by Gregory Petrosyan
Merged all 17 to master, thanks! Although I don't get what is wrong with
setting pointer's memory to 0, to be honest.
Thanks! It's just that pointers and floating point numbers which are
equal to 0 don't necessarily have all bits 0 (you probably know that).
Not sure about FP, but AFAIK NULL = 0 everywhere, even Stroustroup
advised to use 0 instead of NULL at some time.
Post by Johannes Weißl
But since it works on all (modern) known systems, it is more an
aesthetical than a portability issue. Why not write standard conform
code if it is possible and not harder/longer/slower?
Yep, nothing against that!

                Gregory
Johannes Weißl
2011-05-05 19:51:06 UTC
Permalink
Post by Gregory Petrosyan
Not sure about FP, but AFAIK NULL = 0 everywhere, even Stroustroup
advised to use 0 instead of NULL at some time.
Yes, NULL is mostly equivalent to 0 (using NULL is more like a comment
saying: "this is a pointer, not a number").

The case is different here. On some machines [1] this is possible:

void *p = 0; /* The compiler knows that p is a pointer, and translates
the constant "0" to a valid null pointer of this machine,
which can be any bit pattern. */

void *q;
memset(&q, 0, sizeof(q)); /* q has all-zero bit-pattern */

if (p != q)
printf("you have a really rare system!\n");


But, as said before, it has no practical impacts...


[1] http://c-faq.com/null/machexamp.html
http://c-faq.com/null/confusion4.html


Johannes

Loading...