Logo Search packages:      
Sourcecode: libmpdclient version File versions  Download package

mpd_malloc struct mpd_song* mpd_song_dup ( const struct mpd_song song  )  [read]

Duplicates the specified mpd_song object.

the copy, or NULL if out of memory

Definition at line 151 of file song.c.

References mpd_song::duration, mpd_song::finished, mpd_song::id, mpd_song::last_modified, mpd_song_dup(), mpd_song_free(), mpd_song::pos, mpd_song::tags, and mpd_song::uri.

Referenced by mpd_song_dup().

      struct mpd_song *ret;
      bool success;

      assert(song != NULL);

      ret = mpd_song_new(song->uri);
      if (ret == NULL)
            /* out of memory */
            return NULL;

      for (unsigned i = 0; i < MPD_TAG_COUNT; ++i) {
            const struct mpd_tag_value *src_tag = &song->tags[i];

            if (src_tag->value == NULL)

            do {
                  success = mpd_song_add_tag(ret, i, src_tag->value);
                  if (!success) {
                        return NULL;

                  src_tag = src_tag->next;
            } while (src_tag != NULL);

      ret->duration = song->duration;
      ret->last_modified = song->last_modified;
      ret->pos = song->pos;
      ret->id = song->id;

#ifndef NDEBUG
      ret->finished = true;

      return ret;

Generated by  Doxygen 1.6.0   Back to index