| 31 | static int errs = 0; |
| 32 | |
| 33 | static void check(const char *label, int actual_rc, int expect_ok, |
| 34 | const char *path, mode_t expected_mode) |
| 35 | { |
| 36 | struct stat st; |
| 37 | int got_ok = (actual_rc == 0); |
| 38 | if (got_ok != expect_ok) { |
| 39 | fprintf(stderr, "FAIL [%s]: rc=%d errno=%d (%s), expected %s\n", |
| 40 | label, actual_rc, errno, strerror(errno), |
| 41 | expect_ok ? "success" : "rejection"); |
| 42 | errs++; |
| 43 | return; |
| 44 | } |
| 45 | if (path && stat(path, &st) < 0) { |
| 46 | fprintf(stderr, "FAIL [%s]: stat(%s) failed: %s\n", |
| 47 | label, path, strerror(errno)); |
| 48 | errs++; |
| 49 | return; |
| 50 | } |
| 51 | if (path && (st.st_mode & 07777) != expected_mode) { |
| 52 | fprintf(stderr, |
| 53 | "FAIL [%s]: %s mode is 0%o, expected 0%o\n", |
| 54 | label, path, st.st_mode & 07777, expected_mode); |
| 55 | errs++; |
| 56 | return; |
| 57 | } |
| 58 | fprintf(stderr, "OK [%s]\n", label); |
| 59 | } |
| 60 | |
| 61 | int main(int argc, char **argv) |
| 62 | { |