* timzeone/asia: Update from tzdata2008b.
[glibc.git] / rt / tst-aio3.c
blob95da4c13251625a6dcc4cfaaa696395e7c5188d8
1 /* Test for notification mechanism in lio_listio.
2 Copyright (C) 2000, 2002, 2006 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <aio.h>
21 #include <signal.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <errno.h>
27 static pthread_barrier_t b;
30 static void
31 thrfct (sigval_t arg)
33 int e = pthread_barrier_wait (&b);
34 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
36 puts ("child: barrier_wait failed");
37 exit (1);
42 static int
43 do_test (int argc, char *argv[])
45 char name[] = "/tmp/aio3.XXXXXX";
46 int fd;
47 struct aiocb *arr[1];
48 struct aiocb cb;
49 static const char buf[] = "Hello World\n";
51 fd = mkstemp (name);
52 if (fd == -1)
54 printf ("cannot open temp name: %m\n");
55 return 1;
58 unlink (name);
60 if (pthread_barrier_init (&b, NULL, 2) != 0)
62 puts ("barrier_init failed");
63 return 1;
66 arr[0] = &cb;
68 cb.aio_fildes = fd;
69 cb.aio_lio_opcode = LIO_WRITE;
70 cb.aio_reqprio = 0;
71 cb.aio_buf = (void *) buf;
72 cb.aio_nbytes = sizeof (buf) - 1;
73 cb.aio_offset = 0;
74 cb.aio_sigevent.sigev_notify = SIGEV_THREAD;
75 cb.aio_sigevent.sigev_notify_function = thrfct;
76 cb.aio_sigevent.sigev_notify_attributes = NULL;
77 cb.aio_sigevent.sigev_value.sival_ptr = NULL;
79 if (lio_listio (LIO_NOWAIT, arr, 1, NULL) < 0)
81 if (errno == ENOSYS)
83 puts ("no aio support in this configuration");
84 return 0;
86 printf ("lio_listio failed: %m\n");
87 return 1;
90 if (aio_suspend ((const struct aiocb *const *) arr, 1, NULL) < 0)
92 printf ("aio_suspend failed: %m\n");
93 return 1;
96 int e = pthread_barrier_wait (&b);
97 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
99 puts ("parent: barrier_wait failed");
100 return 1;
103 puts ("all OK");
105 return 0;
108 #include "../test-skeleton.c"