blob: 6a58eda3f101d819be52c9fab5cc6308388be901 [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
20#include <stdio.h>
21#include <libgen.h> // for basename
22
23#define off_t loff_t
24
25#ifndef MAX
26#define MAX(x,y) ((x) > (y) ? (x) : (y))
27#endif
28
29#ifndef MIN
30#define MIN(x,y) ((x) < (y) ? (x) : (y))
31#endif
32
33#ifndef powerof2
34#define powerof2(x) (((x - 1) & (x)) == 0)
35#endif
36
37/* workaround for canonicalize_file_name */
38#define canonicalize_file_name(path) realpath(path, NULL)
39
40/* workaround for open64 */
41#define open64(path, flags) open(path, ((flags) | O_LARGEFILE))
42
43/* no internalization */
44#define gettext(x) (x)
45
46/* _mempcpy and mempcpy */
47#ifndef __mempcpy
48#define __mempcpy(dest, src, n) mempcpy(dest, src, n)
49#endif
50
51#ifndef mempcpy
52#include <string.h>
53
54static inline void *mempcpy(void *dest, const void *src, size_t n)
55{
56 char *ptr = memcpy(dest, src, n);
57 return ptr + n;
58}
59#endif
60
61/* rawmemchr */
62static inline void *rawmemchr(const void *s, int c)
63{
64 const unsigned char *ptr = s;
65 while (1) {
66 if (*ptr == c) return (void *) ptr;
67 ptr++;
68 }
69}
70
71/* workaround for stpcpy */
72static inline char *stpcpy(char *dst, const char *src)
73{
74 while (*src) {
75 *dst++ = *src++;
76 }
77 return dst;
78}
79
80/* forward declarations */
81char * dgettext (const char * domainname, const char * msgid);
82
83#endif /* ANDROID_FIXUP_H */