Import 2.3.18pre1
[davej-history.git] / drivers / char / drm / sigio.c
blobbb75087df2347a882a57e41db9e26d39f9e27c1a
1 /* sigio.c -- Support for SIGIO handler -*- linux-c -*-
2 * Created: Thu Jun 3 15:39:18 1999 by faith@precisioninsight.com
3 * Revised: Thu Jun 3 16:16:35 1999 by faith@precisioninsight.com
5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6 * All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
27 * $PI: xc/programs/Xserver/hw/xfree86/os-support/shared/sigio.c,v 1.2 1999/06/14 21:11:29 faith Exp $
28 * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/sigio.c,v 1.2 1999/06/14 12:02:11 dawes Exp $
33 #ifdef XFree86Server
34 # include "X.h"
35 # include "xf86.h"
36 # include "xf86drm.h"
37 # include "xf86_OSlib.h"
38 # include "xf86drm.h"
39 #else
40 # include <unistd.h>
41 # include <signal.h>
42 # include <fcntl.h>
43 #endif
46 * Linux libc5 defines FASYNC, but not O_ASYNC. Don't know if it is
47 * functional or not.
49 #if defined(FASYNC) && !defined(O_ASYNC)
50 # define O_ASYNC FASYNC
51 #endif
53 int
54 xf86InstallSIGIOHandler(int fd, void (*f)(int))
56 struct sigaction sa;
57 struct sigaction osa;
59 sigemptyset(&sa.sa_mask);
60 sigaddset(&sa.sa_mask, SIGIO);
61 sa.sa_flags = 0;
62 sa.sa_handler = f;
63 sigaction(SIGIO, &sa, &osa);
64 fcntl(fd, F_SETOWN, getpid());
65 fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_ASYNC);
66 return 0;
69 int
70 xf86RemoveSIGIOHandler(int fd)
72 struct sigaction sa;
73 struct sigaction osa;
75 sigemptyset(&sa.sa_mask);
76 sigaddset(&sa.sa_mask, SIGIO);
77 sa.sa_flags = 0;
78 sa.sa_handler = SIG_DFL;
79 fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_ASYNC);
80 sigaction(SIGIO, &sa, &osa);
81 return 0;