test-bus-memfd.c revision ddeb424198649c3993a54efc81652325b6e3bfa5
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "log.h"
#include "macro.h"
#include "util.h"
#include "sd-memfd.h"
sd_memfd *m;
char *s;
int r, fd;
r = sd_memfd_new(&m);
if (r == -ENOENT)
return EXIT_TEST_SKIP;
r = sd_memfd_map(m, 0, 6, (void**) &s);
assert_se(r >= 0);
strcpy(s, "hallo");
r = sd_memfd_get_sealed(m);
assert_se(r == 0);
r = sd_memfd_set_sealed(m, 1);
assert_se(r >= 0);
r = sd_memfd_get_sealed(m);
assert_se(r == 1);
r = sd_memfd_get_size(m, &sz);
assert_se(r >= 0);
r = sd_memfd_set_size(m, 6);
assert_se(r >= 0);
fd = sd_memfd_dup_fd(m);
sd_memfd_free(m);
r = sd_memfd_make(fd, &m);
assert_se(r >= 0);
r = sd_memfd_get_size(m, &sz);
assert_se(r >= 0);
r = sd_memfd_map(m, 0, 6, (void**) &s);
assert_se(r >= 0);
return 0;
}