blob: db324c47650bff6d434a8326dc82a5a8ffb0bcaa [file] [log] [blame]
Ben Cheng65b38192013-11-20 15:54:16 -08001/*
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 Cheng01135f82013-11-26 16:25:30 -080020#include <libgen.h> // for basename
Ben Cheng65b38192013-11-20 15:54:16 -080021
Ben Cheng65b38192013-11-20 15:54:16 -080022#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 Cheng01135f82013-11-26 16:25:30 -080030/* workaround for stpcpy */
31static 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 Cheng65b38192013-11-20 15:54:16 -080040
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
49static 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 */
57static 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 Cheng01135f82013-11-26 16:25:30 -080066/* workaround for canonicalize_file_name */
67#define canonicalize_file_name(path) realpath(path, NULL)
Ben Cheng65b38192013-11-20 15:54:16 -080068
Ben Cheng01135f82013-11-26 16:25:30 -080069/* workaround for open64 */
70#define open64(path, flags) open(path, ((flags) | O_LARGEFILE))
Ben Cheng65b38192013-11-20 15:54:16 -080071
72#endif /* ANDROID_FIXUP_H */