1/*2 * Copyright 2012, The Android Open Source Project3 *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 at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617#ifndef ANDROID_FIXUP_H18#define ANDROID_FIXUP_H1920#define loff_t off_t21#define off64_t off_t2223#include <string.h>24#include <stdarg.h>25#include <stdlib.h>26#include <stdio.h>27#include <errno.h>28#include <locale.h> //LC_MESSAGES2930#ifndef TEMP_FAILURE_RETRY31#define TEMP_FAILURE_RETRY(exp) ({ 32 typeof (exp) _rc; 33 do { 34 _rc = (exp); 35 } while (_rc == -1 && errno == EINTR); 36 _rc; })37#endif3839#if __MAC_OS_X_VERSION_MIN_REQUIRED < 107040static inline size_t strnlen (const char *__string, size_t __maxlen)41{42 int len = 0;43 while (__maxlen-- && *__string++)44 len++;45 return len;46}47#endif4849static inline void *mempcpy (void * __dest, const void * __src, size_t __n)50{51 memcpy(__dest, __src, __n);52 return ((char *)__dest) + __n;53}5455#define __mempcpy mempcpy5657#define dgettext(domainname, msgid) dcgettext (domainname, msgid, LC_MESSAGES)5859static inline void __attribute__((noreturn)) error(int status, int errnum, const char *fmt, ...)60{61 va_list lst;62 va_start(lst, fmt);63 vfprintf(stderr, fmt, lst);64 fprintf(stderr, "error %d: %s\n", errnum, strerror(errno));65 va_end(lst);66 exit(status);67}6869static inline char *dcgettext (char *__domainname, char *__msgid, int __category)70{71 error(EXIT_FAILURE, 0, "%s not implemented!", __FUNCTION__);72 return NULL;73}7475/* workaround for canonicalize_file_name */76#define canonicalize_file_name(path) realpath(path, NULL)7778/* workaround for open64 */79#define open64(path, flags) open(path, flags)8081/* rawmemchr */82static inline void *rawmemchr(const void *s, int c)83{84 const unsigned char *ptr = s;85 while (1) {86 if (*ptr == c) return (void *) ptr;87 ptr++;88 }89}9091#define strndup(str, size) strdup(str)9293static void tdestroy(void *root, void (*free_node)(void *nodep))94{95}9697#endif /* ANDROID_FIXUP_H */98
联系客服