1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
/*
* Zapping (TV viewer for the Gnome Desktop)
*
* Copyright (C) 2003 Michael H. Schimek
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: device.h,v 1.9 2006/05/14 13:47:55 mschimek Exp $ */
#ifndef DEVICE_H
#define DEVICE_H
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#if defined (_IOC_SIZE) /* Linux */
#define IOCTL_ARG_SIZE(cmd) _IOC_SIZE (cmd)
#define IOCTL_READ(cmd) (_IOC_DIR (cmd) & _IOC_READ)
#define IOCTL_WRITE(cmd) (_IOC_DIR (cmd) & _IOC_WRITE)
#define IOCTL_READ_WRITE(cmd) (_IOC_DIR (cmd) == (_IOC_READ | _IOC_WRITE))
#define IOCTL_NUMBER(cmd) _IOC_NR (cmd)
#elif defined (IOCPARM_LEN) /* FreeBSD */
#define IOCTL_ARG_SIZE(cmd) IOCPARM_LEN (cmd)
#define IOCTL_READ(cmd) ((cmd) & IOC_OUT)
#define IOCTL_WRITE(cmd) ((cmd) & IOC_IN)
#define IOCTL_READ_WRITE(cmd) (((cmd) & IOC_DIRMASK) == (IOC_IN | IOC_OUT))
#define IOCTL_NUMBER(cmd) ((cmd) & 0xFF)
#else /* Don't worry, only used for debugging */
#define IOCTL_ARG_SIZE(cmd) 0
#define IOCTL_READ(cmd) 0
#define IOCTL_WRITE(cmd) 0
#define IOCTL_READ_WRITE(cmd) 0
#define IOCTL_NUMBER(cmd) 0
#endif
typedef void (ioctl_log_fn) (FILE * fp,
unsigned int cmd,
int rw,
void * arg);
extern void
fprint_symbolic (FILE * fp,
int mode,
unsigned long value,
...);
extern void
fprint_unknown_ioctl (FILE * fp,
unsigned int cmd,
void * arg);
static __inline__ void
timeval_add (struct timeval * sum,
const struct timeval * tv1,
const struct timeval * tv2)
{
long usec;
usec = tv1->tv_usec + tv2->tv_usec;
if (usec > 1000000) {
sum->tv_sec = tv1->tv_sec + tv2->tv_sec + 1;
sum->tv_usec = usec - 1000000;
} else {
sum->tv_sec = tv1->tv_sec + tv2->tv_sec;
sum->tv_usec = usec;
}
}
static __inline__ void
timeval_subtract (struct timeval * diff,
const struct timeval * tv1,
const struct timeval * tv2)
{
if (tv1->tv_usec < tv2->tv_usec) {
diff->tv_sec = tv1->tv_sec - tv2->tv_sec - 1;
diff->tv_usec = 1000000 + tv1->tv_usec - tv2->tv_usec;
} else {
diff->tv_sec = tv1->tv_sec - tv2->tv_sec;
diff->tv_usec = tv1->tv_usec - tv2->tv_usec;
}
}
static __inline__ long
timeval_cmp (const struct timeval * tv1,
const struct timeval * tv2)
{
if (tv1->tv_sec == tv2->tv_sec)
return tv1->tv_usec - tv2->tv_usec;
else
return tv1->tv_sec - tv2->tv_sec;
}
extern void
timeout_subtract_elapsed (struct timeval * result,
const struct timeval * timeout,
const struct timeval * now,
const struct timeval * start);
extern int
device_open (FILE * fp,
const char * pathname,
int flags,
mode_t mode);
extern int
device_close (FILE * fp,
int fd);
extern int
device_ioctl (FILE * fp,
ioctl_log_fn * fn,
int fd,
unsigned int cmd,
void * arg);
extern void *
device_mmap (FILE * fp,
void * start,
size_t length,
int prot,
int flags,
int fd,
off_t offset);
extern int
device_munmap (FILE * fp,
void * start,
size_t length);
extern ssize_t
device_read (FILE * fp,
int fd,
void * buf,
size_t count);
#endif /* DEVICE_H */
|