diff options
author | Max Kellermann <max@duempel.org> | 2014-02-19 09:08:29 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-02-19 09:22:08 +0100 |
commit | 0bbfb28992d0684a59fd518a4e16333d82bcf716 (patch) | |
tree | f009e50f1f173c3d8bb6dc4f082c4f94036ea6e0 /src/output/plugins/httpd/Page.cxx | |
parent | ee7bd695fd31d164a8a3ade1c2fb7fe019744ceb (diff) | |
download | mpd-0bbfb28992d0684a59fd518a4e16333d82bcf716.tar.gz mpd-0bbfb28992d0684a59fd518a4e16333d82bcf716.tar.xz mpd-0bbfb28992d0684a59fd518a4e16333d82bcf716.zip |
output/httpd: move to dedicated directory
Diffstat (limited to 'src/output/plugins/httpd/Page.cxx')
-rw-r--r-- | src/output/plugins/httpd/Page.cxx | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/output/plugins/httpd/Page.cxx b/src/output/plugins/httpd/Page.cxx new file mode 100644 index 000000000..e22134bbc --- /dev/null +++ b/src/output/plugins/httpd/Page.cxx @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2003-2014 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include "Page.hxx" +#include "util/Alloc.hxx" + +#include <new> + +#include <assert.h> +#include <string.h> +#include <stdlib.h> + +Page * +Page::Create(size_t size) +{ + void *p = xalloc(sizeof(Page) + size - + sizeof(Page::data)); + return ::new(p) Page(size); +} + +Page * +Page::Copy(const void *data, size_t size) +{ + assert(data != nullptr); + + Page *page = Create(size); + memcpy(page->data, data, size); + return page; +} + +Page * +Page::Concat(const Page &a, const Page &b) +{ + Page *page = Create(a.size + b.size); + + memcpy(page->data, a.data, a.size); + memcpy(page->data + a.size, b.data, b.size); + + return page; +} + +bool +Page::Unref() +{ + bool unused = ref.Decrement(); + + if (unused) { + this->Page::~Page(); + free(this); + } + + return unused; +} |