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