From 5f79ffb27119766a5f946d912849ffb1bdface72 Mon Sep 17 00:00:00 2001 From: Chao-Ying Fu Date: Mon, 20 Aug 2012 18:08:30 -0700 Subject: [PATCH] Support fcntl for MIPS with different cmd. Change-Id: I8d180ab9e18d69f0fd2748ad317319b691a86f35 --- ndk/sources/android/libportable/Android.mk | 1 + .../android/libportable/arch-mips/fcntl.c | 61 +++++++++++++++++++ .../common/include/fcntl_portable.h | 16 +++++ 3 files changed, 78 insertions(+) create mode 100644 ndk/sources/android/libportable/arch-mips/fcntl.c diff --git a/ndk/sources/android/libportable/Android.mk b/ndk/sources/android/libportable/Android.mk index 9c0272f41..a4f5a6c1c 100644 --- a/ndk/sources/android/libportable/Android.mk +++ b/ndk/sources/android/libportable/Android.mk @@ -37,6 +37,7 @@ libportable_arch_src_files += \ arch-mips/open.c \ arch-mips/socket.c \ arch-mips/sockopt.c \ + arch-mips/fcntl.c \ arch-mips/epoll.c \ arch-mips/errno.c endif diff --git a/ndk/sources/android/libportable/arch-mips/fcntl.c b/ndk/sources/android/libportable/arch-mips/fcntl.c new file mode 100644 index 000000000..31874b5ce --- /dev/null +++ b/ndk/sources/android/libportable/arch-mips/fcntl.c @@ -0,0 +1,61 @@ +/* + * Copyright 2012, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#if F_GETLK_PORTABLE==F_GETLK +#error Bad build environment +#endif + +static inline int mips_change_cmd(int cmd) +{ + switch(cmd) { + case F_GETLK_PORTABLE: + return F_GETLK; + case F_SETLK_PORTABLE: + return F_SETLK; + case F_SETLKW_PORTABLE: + return F_SETLKW; + case F_SETOWN_PORTABLE: + return F_SETOWN; + case F_GETOWN_PORTABLE: + return F_GETOWN; + case F_GETLK64_PORTABLE: + return F_GETLK64; + case F_SETLK64_PORTABLE: + return F_SETLK64; + case F_SETLKW64_PORTABLE: + return F_SETLKW64; + } + return cmd; +} + +extern int __fcntl64(int, int, void *); + +int fcntl_portable(int fd, int cmd, ...) +{ + va_list ap; + void * arg; + + va_start(ap, cmd); + arg = va_arg(ap, void *); + va_end(ap); + + return __fcntl64(fd, mips_change_cmd(cmd), arg); +} + diff --git a/ndk/sources/android/libportable/common/include/fcntl_portable.h b/ndk/sources/android/libportable/common/include/fcntl_portable.h index d7bdb9f95..7240ad3ce 100644 --- a/ndk/sources/android/libportable/common/include/fcntl_portable.h +++ b/ndk/sources/android/libportable/common/include/fcntl_portable.h @@ -95,4 +95,20 @@ struct flock64 { }; */ +#ifndef F_GETLK_PORTABLE +#define F_GETLK_PORTABLE 5 +#define F_SETLK_PORTABLE 6 +#define F_SETLKW_PORTABLE 7 +#endif +#ifndef F_SETOWN_PORTABLE +#define F_SETOWN_PORTABLE 8 +#define F_GETOWN_PORTABLE 9 +#endif + +#ifndef F_GETLK64_PORTABLE +#define F_GETLK64_PORTABLE 12 +#define F_SETLK64_PORTABLE 13 +#define F_SETLKW64_PORTABLE 14 +#endif + #endif /* _FCNTL_PORTABLE_H */