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 <fcntl.h>
18#include <stdarg.h>
19#include <fcntl_portable.h>
20
21extern int __fcntl64(int, int, void *);
22
23int fcntl_portable(int fd, int cmd, ...)
24{
25    va_list ap;
26    void * arg;
27
28    va_start(ap, cmd);
29    arg = va_arg(ap, void *);
30    va_end(ap);
31
32    if (cmd == F_GETLK64 ||
33        cmd == F_SETLK64 ||
34        cmd == F_SETLKW64) {
35        struct flock64 x86_flock64;
36        int result = __fcntl64(fd, cmd, (void *) &x86_flock64);
37
38        struct flock64_portable * flock64 = (struct flock64_portable *) arg;
39
40        flock64->l_type = x86_flock64.l_type;
41        flock64->l_whence = x86_flock64.l_whence;
42        flock64->l_start = x86_flock64.l_start;
43        flock64->l_len = x86_flock64.l_len;
44        flock64->l_pid = x86_flock64.l_pid;
45
46        return result;
47    }
48    else {
49        return __fcntl64(fd, cmd, arg);
50    }
51}
52
53