1 /*
2 * Copyright 2012, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <portability.h>
18 #include <fcntl.h>
19 #include <stdarg.h>
20 #include <fcntl_portable.h>
21
22 extern int __fcntl64(int, int, void *);
23
WRAP(fcntl)24 int WRAP(fcntl)(int fd, int cmd, ...)
25 {
26 va_list ap;
27 void * arg;
28
29 va_start(ap, cmd);
30 arg = va_arg(ap, void *);
31 va_end(ap);
32
33 if (cmd == F_GETLK64 ||
34 cmd == F_SETLK64 ||
35 cmd == F_SETLKW64) {
36 struct flock64 x86_flock64;
37 int result = __fcntl64(fd, cmd, (void *) &x86_flock64);
38
39 struct flock64_portable * flock64 = (struct flock64_portable *) arg;
40
41 flock64->l_type = x86_flock64.l_type;
42 flock64->l_whence = x86_flock64.l_whence;
43 flock64->l_start = x86_flock64.l_start;
44 flock64->l_len = x86_flock64.l_len;
45 flock64->l_pid = x86_flock64.l_pid;
46
47 return result;
48 }
49 else {
50 return __fcntl64(fd, cmd, arg);
51 }
52 }
53
54