1*c0746c1eSchristos /* $NetBSD: fa_spawn_utils.c,v 1.1 2021/11/07 15:46:20 christos Exp $ */
2*c0746c1eSchristos
3*c0746c1eSchristos /*-
4*c0746c1eSchristos * Copyright (c) 2012 The NetBSD Foundation, Inc.
5*c0746c1eSchristos * All rights reserved.
6*c0746c1eSchristos *
7*c0746c1eSchristos * This code is derived from software contributed to The NetBSD Foundation
8*c0746c1eSchristos * by Charles Zhang <charles@NetBSD.org> and
9*c0746c1eSchristos * Martin Husemann <martin@NetBSD.org>.
10*c0746c1eSchristos *
11*c0746c1eSchristos * Redistribution and use in source and binary forms, with or without
12*c0746c1eSchristos * modification, are permitted provided that the following conditions
13*c0746c1eSchristos * are met:
14*c0746c1eSchristos * 1. Redistributions of source code must retain the above copyright
15*c0746c1eSchristos * notice, this list of conditions and the following disclaimer.
16*c0746c1eSchristos * 2. Redistributions in binary form must reproduce the above copyright
17*c0746c1eSchristos * notice, this list of conditions and the following disclaimer in the
18*c0746c1eSchristos * documentation and/or other materials provided with the distribution.
19*c0746c1eSchristos *
20*c0746c1eSchristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21*c0746c1eSchristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22*c0746c1eSchristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23*c0746c1eSchristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24*c0746c1eSchristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25*c0746c1eSchristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26*c0746c1eSchristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27*c0746c1eSchristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28*c0746c1eSchristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29*c0746c1eSchristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30*c0746c1eSchristos * POSSIBILITY OF SUCH DAMAGE.
31*c0746c1eSchristos */
32*c0746c1eSchristos #include <sys/cdefs.h>
33*c0746c1eSchristos __RCSID("$NetBSD: fa_spawn_utils.c,v 1.1 2021/11/07 15:46:20 christos Exp $");
34*c0746c1eSchristos
35*c0746c1eSchristos #include <atf-c.h>
36*c0746c1eSchristos #include <stdio.h>
37*c0746c1eSchristos #include <errno.h>
38*c0746c1eSchristos #include <string.h>
39*c0746c1eSchristos #include <sys/stat.h>
40*c0746c1eSchristos
41*c0746c1eSchristos #include "fa_spawn_utils.h"
42*c0746c1eSchristos
43*c0746c1eSchristos off_t
filesize(const char * restrict fname)44*c0746c1eSchristos filesize(const char * restrict fname)
45*c0746c1eSchristos {
46*c0746c1eSchristos struct stat st;
47*c0746c1eSchristos int err;
48*c0746c1eSchristos
49*c0746c1eSchristos err = stat(fname, &st);
50*c0746c1eSchristos ATF_REQUIRE_MSG(err == 0, "Can't stat %s (%s)", fname, strerror(errno));
51*c0746c1eSchristos return st.st_size;
52*c0746c1eSchristos }
53*c0746c1eSchristos
54*c0746c1eSchristos void
empty_outfile(const char * restrict fname)55*c0746c1eSchristos empty_outfile(const char * restrict fname)
56*c0746c1eSchristos {
57*c0746c1eSchristos FILE *f;
58*c0746c1eSchristos
59*c0746c1eSchristos f = fopen(fname, "w");
60*c0746c1eSchristos ATF_REQUIRE_MSG(f != NULL, "Can't open %s (%s)", fname, strerror(errno));
61*c0746c1eSchristos fclose(f);
62*c0746c1eSchristos }
63