Debian Codegraph @

lib/libv4l1/v4l1compat.c

raw
1 /*
2 # open/close/ioctl/mmap/munmap library call wrapper doing v4l1 api emulation
3 # for v4l2 devices
4
5 # (C) 2008 Hans de Goede <[email protected]>
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation; either version 2.1 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
20 */
21
22 #include <stdlib.h>
23 #include <stdarg.h>
24 #include <fcntl.h>
25 #include <libv4l1.h>
26
27 #include <sys/ioctl.h>
28 #include <sys/mman.h>
29
30 /* Check that open/read/mmap is not a define */
31 #if defined open || defined read || defined mmap
32 #error open/read/mmap is a prepocessor macro !!
33 #endif
34
35 #if HAVE_VISIBILITY
36 #define LIBV4L_PUBLIC __attribute__ ((visibility("default")))
37 #else
38 #define LIBV4L_PUBLIC
39 #endif
40
41 LIBV4L_PUBLIC int open(const char *file, int oflag, ...)
42 {
43 int fd;
44
45 if (oflag & O_CREAT) {
46 va_list ap;
47 mode_t mode;
48
49 va_start(ap, oflag);
50 mode = va_arg(ap, PROMOTED_MODE_T);
51
52 fd = v4l1_open(file, oflag, mode);
53
54 va_end(ap);
55 } else
56 fd = v4l1_open(file, oflag);
57
58 return fd;
59 }
60
61 #if defined(linux) && defined(__GLIBC__)
62 LIBV4L_PUBLIC int open64(const char *file, int oflag, ...)
63 {
64 int fd;
65
66 if (oflag & O_CREAT) {
67 va_list ap;
68 mode_t mode;
69
70 va_start(ap, oflag);
71 mode = va_arg(ap, mode_t);
72
73 fd = v4l1_open(file, oflag | O_LARGEFILE, mode);
74
75 va_end(ap);
76 } else
77 fd = v4l1_open(file, oflag | O_LARGEFILE);
78
79 return fd;
80 }
81 #endif
82
83 LIBV4L_PUBLIC int close(int fd)
84 {
85 return v4l1_close(fd);
86 }
87
88 LIBV4L_PUBLIC int dup(int fd)
89 {
90 return v4l1_dup(fd);
91 }
92
93 #ifdef LIBV4L_HAVE_POSIX_IOCTL
94 LIBV4L_PUBLIC int ioctl(int fd, int request, ...)
95 #else
96 LIBV4L_PUBLIC int ioctl(int fd, unsigned long int request, ...)
97 #endif
98 {
99 void *arg;
100 va_list ap;
101
102 va_start(ap, request);
103 arg = va_arg(ap, void *);
104 va_end(ap);
105
106 return v4l1_ioctl(fd, request, arg);
107 }
108
109 LIBV4L_PUBLIC ssize_t read(int fd, void *buffer, size_t n)
110 {
111 return v4l1_read(fd, buffer, n);
112 }
113
114 LIBV4L_PUBLIC void *mmap(void *start, size_t length, int prot, int flags, int fd,
115 off_t offset)
116 {
117 return v4l1_mmap(start, length, prot, flags, fd, offset);
118 }
119
120 #if defined(linux) && defined(__GLIBC__)
121 LIBV4L_PUBLIC void *mmap64(void *start, size_t length, int prot, int flags, int fd,
122 __off64_t offset)
123 {
124 return v4l1_mmap(start, length, prot, flags, fd, offset);
125 }
126 #endif
127
128 LIBV4L_PUBLIC int munmap(void *start, size_t length)
129 {
130 return v4l1_munmap(start, length);
131 }
132