Support fcntl for MIPS with different cmd.

Change-Id: I8d180ab9e18d69f0fd2748ad317319b691a86f35
diff --git a/ndk/sources/android/libportable/Android.mk b/ndk/sources/android/libportable/Android.mk
index 9c0272f..a4f5a6c 100644
--- a/ndk/sources/android/libportable/Android.mk
+++ b/ndk/sources/android/libportable/Android.mk
@@ -37,6 +37,7 @@
 			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 0000000..31874b5
--- /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 <fcntl.h>
+#include <stdarg.h>
+#include <fcntl_portable.h>
+
+#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 d7bdb9f..7240ad3 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 @@
 };
 */
 
+#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 */