chiark / gitweb /
Ask for -std=gnu99 if necessary to get full <limits.h>.
[disorder] / lib / t-syscalls.c
CommitLineData
c3c40090
RK
1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 2008 Richard Kettlewell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20#include "test.h"
21
22void test_syscalls(void) {
23 int p[2];
24 char buf[128], *e;
25 long n;
26 long long nn;
27
28 printf("test_syscalls\n");
29
30 xpipe(p);
31 nonblock(p[1]);
32 memset(buf, 99, sizeof buf);
33 errno = 0;
34 while(write(p[1], buf, sizeof buf) > 0)
35 errno = 0;
36 insist(errno == EAGAIN);
37 memset(buf, 0, sizeof buf);
38 insist(read(p[0], buf, sizeof buf) == sizeof buf);
39 insist(buf[0] == 99);
40 insist(buf[(sizeof buf) - 1] == 99);
41
42 xclose(p[0]);
43 xclose(p[1]);
44 errno = 0;
45 insist(read(p[0], buf, sizeof buf) < 0);
46 insist(errno == EBADF);
47 errno = 0;
48 insist(write(p[1], buf, sizeof buf) < 0);
49 insist(errno == EBADF);
50
51 n = 0;
52 e = 0;
53 sprintf(buf, "%ld", LONG_MAX);
54 insist(xstrtol(&n, buf, &e, 0) == 0);
55 insist(n == LONG_MAX);
56 insist(e == buf + strlen(buf));
57
58 n = 0;
59 e = 0;
60 sprintf(buf, "%ld0", LONG_MAX);
61 insist(xstrtol(&n, buf, &e, 0) == ERANGE);
62 insist(n == LONG_MAX);
63 insist(e == buf + strlen(buf));
64
65 n = 0;
66 e = 0;
67 sprintf(buf, "%ldxyzzy", LONG_MAX);
68 insist(xstrtol(&n, buf, &e, 0) == 0);
69 insist(n == LONG_MAX);
70 insist(e != 0);
71 check_string(e, "xyzzy");
72
73 nn = 0;
74 e = 0;
75 sprintf(buf, "%lld", LLONG_MAX);
76 insist(xstrtoll(&nn, buf, &e, 0) == 0);
77 insist(nn == LLONG_MAX);
78 insist(e == buf + strlen(buf));
79
80 nn = 0;
81 e = 0;
82 sprintf(buf, "%lld0", LLONG_MAX);
83 insist(xstrtoll(&nn, buf, &e, 0) == ERANGE);
84 insist(nn == LLONG_MAX);
85 insist(e == buf + strlen(buf));
86
87 nn = 0;
88 e = 0;
89 sprintf(buf, "%lldxyzzy", LLONG_MAX);
90 insist(xstrtoll(&nn, buf, &e, 0) == 0);
91 insist(nn == LLONG_MAX);
92 insist(e != 0);
93 check_string(e, "xyzzy");
94}
95
96/*
97Local Variables:
98c-basic-offset:2
99comment-column:40
100fill-column:79
101indent-tabs-mode:nil
102End:
103*/