Home | History | Annotate | Download | only in host-darwin-fixup
      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 
     20 #define loff_t off_t
     21 #define off64_t off_t
     22 
     23 #include <string.h>
     24 #include <stdarg.h>
     25 #include <stdlib.h>
     26 #include <stdio.h>
     27 #include <errno.h>
     28 #include <locale.h> //LC_MESSAGES
     29 
     30 #ifndef TEMP_FAILURE_RETRY
     31 #define TEMP_FAILURE_RETRY(exp) ({         \
     32     typeof (exp) _rc;                      \
     33     do {                                   \
     34         _rc = (exp);                       \
     35     } while (_rc == -1 && errno == EINTR); \
     36     _rc; })
     37 #endif
     38 
     39 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1070
     40 static 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 #endif
     48 
     49 static inline void *mempcpy (void * __dest, const void * __src, size_t __n)
     50 {
     51         memcpy(__dest, __src, __n);
     52         return ((char *)__dest) + __n;
     53 }
     54 
     55 #define __mempcpy mempcpy
     56 
     57 #define dgettext(domainname, msgid)  dcgettext (domainname, msgid, LC_MESSAGES)
     58 
     59 static 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 }
     68 
     69 static inline char *dcgettext (char *__domainname, char *__msgid, int __category)
     70 {
     71         error(EXIT_FAILURE, 0, "%s not implemented!", __FUNCTION__);
     72         return NULL;
     73 }
     74 
     75 /* workaround for canonicalize_file_name */
     76 #define canonicalize_file_name(path) realpath(path, NULL)
     77 
     78 /* workaround for open64 */
     79 #define open64(path, flags)     open(path, flags)
     80 
     81 /* rawmemchr */
     82 static 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 }
     90 
     91 #define strndup(str, size) strdup(str)
     92 
     93 static void tdestroy(void *root, void (*free_node)(void *nodep))
     94 {
     95 }
     96 
     97 #endif /* ANDROID_FIXUP_H */
     98