Ben Cheng | 65b3819 | 2013-11-20 15:54:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013, 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 | #ifndef ANDROID_FIXUP_H |
| 18 | #define ANDROID_FIXUP_H |
| 19 | |
Ben Cheng | 01135f8 | 2013-11-26 16:25:30 -0800 | [diff] [blame] | 20 | #include <libgen.h> // for basename |
Ben Cheng | 65b3819 | 2013-11-20 15:54:16 -0800 | [diff] [blame] | 21 | |
Ben Cheng | 65b3819 | 2013-11-20 15:54:16 -0800 | [diff] [blame] | 22 | #ifndef MAX |
| 23 | #define MAX(x,y) ((x) > (y) ? (x) : (y)) |
| 24 | #endif |
| 25 | |
| 26 | #ifndef MIN |
| 27 | #define MIN(x,y) ((x) < (y) ? (x) : (y)) |
| 28 | #endif |
| 29 | |
Ben Cheng | 01135f8 | 2013-11-26 16:25:30 -0800 | [diff] [blame] | 30 | /* workaround for stpcpy */ |
| 31 | static inline char *stpcpy(char *dst, const char *src) |
| 32 | { |
| 33 | while (*src) { |
| 34 | *dst++ = *src++; |
| 35 | } |
| 36 | // Need to copy the NULL terminator |
| 37 | *dst = *src; |
| 38 | return dst; |
| 39 | } |
Ben Cheng | 65b3819 | 2013-11-20 15:54:16 -0800 | [diff] [blame] | 40 | |
| 41 | /* _mempcpy and mempcpy */ |
| 42 | #ifndef __mempcpy |
| 43 | #define __mempcpy(dest, src, n) mempcpy(dest, src, n) |
| 44 | #endif |
| 45 | |
| 46 | #ifndef mempcpy |
| 47 | #include <string.h> |
| 48 | |
| 49 | static inline void *mempcpy(void *dest, const void *src, size_t n) |
| 50 | { |
| 51 | char *ptr = memcpy(dest, src, n); |
| 52 | return ptr + n; |
| 53 | } |
| 54 | #endif |
| 55 | |
| 56 | /* rawmemchr */ |
| 57 | static inline void *rawmemchr(const void *s, int c) |
| 58 | { |
| 59 | const unsigned char *ptr = s; |
| 60 | while (1) { |
| 61 | if (*ptr == c) return (void *) ptr; |
| 62 | ptr++; |
| 63 | } |
| 64 | } |
| 65 | |
Ben Cheng | 01135f8 | 2013-11-26 16:25:30 -0800 | [diff] [blame] | 66 | /* workaround for canonicalize_file_name */ |
| 67 | #define canonicalize_file_name(path) realpath(path, NULL) |
Ben Cheng | 65b3819 | 2013-11-20 15:54:16 -0800 | [diff] [blame] | 68 | |
Ben Cheng | 01135f8 | 2013-11-26 16:25:30 -0800 | [diff] [blame] | 69 | /* workaround for open64 */ |
| 70 | #define open64(path, flags) open(path, ((flags) | O_LARGEFILE)) |
Ben Cheng | 65b3819 | 2013-11-20 15:54:16 -0800 | [diff] [blame] | 71 | |
| 72 | #endif /* ANDROID_FIXUP_H */ |