2 * Automated Testing Framework (atf)
4 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/types.h>
39 #include "atf-c/dynstr.h"
40 #include "atf-c/error.h"
43 #include "atf-c/sanity.h"
46 atf_io_readline(int fd
, atf_dynstr_t
*dest
, bool *eof
)
52 while ((cnt
= read(fd
, &ch
, sizeof(ch
))) == sizeof(ch
) &&
54 err
= atf_dynstr_append_fmt(dest
, "%c", ch
);
55 if (atf_is_error(err
))
60 err
= atf_libc_error(errno
, "Failed to read line from file "
73 atf_io_write_ap(int fd
, const char *fmt
, va_list ap
)
78 err
= atf_dynstr_init_ap(&str
, fmt
, ap
);
79 if (!atf_is_error(err
)) {
80 ssize_t cnt
= write(fd
, atf_dynstr_cstring(&str
),
81 atf_dynstr_length(&str
));
84 err
= atf_libc_error(errno
, "Failed to write '%s' to file "
85 "descriptor %d", atf_dynstr_cstring(&str
),
89 INV((size_t)cnt
== atf_dynstr_length(&str
));
93 atf_dynstr_fini(&str
);
100 atf_io_write_fmt(int fd
, const char *fmt
, ...)
106 err
= atf_io_write_ap(fd
, fmt
, ap
);
113 atf_io_cmp(int *result
, const atf_fs_path_t
*p1
, const atf_fs_path_t
*p2
)
116 const char *path1
, *path2
;
119 err
= atf_no_error();
121 path1
= atf_fs_path_cstring(p1
);
122 path2
= atf_fs_path_cstring(p2
);
124 fd1
= open(path1
, O_RDONLY
);
126 err
= atf_libc_error(errno
, "Cannot open file: %s", path1
);
130 fd2
= open(path2
, O_RDONLY
);
132 err
= atf_libc_error(errno
, "Cannot open file: %s", path2
);
138 char buf1
[512], buf2
[512];
140 r1
= read(fd1
, buf1
, sizeof(buf1
));
142 err
= atf_libc_error(errno
, "Cannot read file: %s", path1
);
146 r2
= read(fd2
, buf2
, sizeof(buf2
));
148 err
= atf_libc_error(errno
, "Cannot read file: %s", path2
);
152 if ((r1
== 0) && (r2
== 0)) {
157 if ((r1
!= r2
) || (memcmp(buf1
, buf2
, r1
) != 0)) {
169 if (err
== atf_no_error())