github.com/akaros/go-akaros@v0.0.0-20181004170632-85005d477eab/include/u.h (about)

     1  /*
     2  Plan 9 from User Space include/u.h
     3  http://code.swtch.com/plan9port/src/tip/include/u.h
     4  
     5  Copyright 2001-2007 Russ Cox.  All Rights Reserved.
     6  
     7  Permission is hereby granted, free of charge, to any person obtaining a copy
     8  of this software and associated documentation files (the "Software"), to deal
     9  in the Software without restriction, including without limitation the rights
    10  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    11  copies of the Software, and to permit persons to whom the Software is
    12  furnished to do so, subject to the following conditions:
    13  
    14  The above copyright notice and this permission notice shall be included in
    15  all copies or substantial portions of the Software.
    16  
    17  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    18  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    19  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    20  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    21  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    22  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    23  THE SOFTWARE.
    24  */
    25  
    26  #ifndef _U_H_
    27  #define _U_H_ 1
    28  #if defined(__cplusplus)
    29  extern "C" {
    30  #endif
    31  
    32  #define __BSD_VISIBLE 1 /* FreeBSD 5.x */
    33  #if defined(__sun__)
    34  #	define __EXTENSIONS__ 1 /* SunOS */
    35  #	if defined(__SunOS5_6__) || defined(__SunOS5_7__) || defined(__SunOS5_8__)
    36  		/* NOT USING #define __MAKECONTEXT_V2_SOURCE 1 / * SunOS */
    37  #	else
    38  #		define __MAKECONTEXT_V2_SOURCE 1
    39  #	endif
    40  #endif
    41  #define _DEFAULT_SOURCE 1	/* glibc > 2.19 */
    42  #if !defined(__APPLE__) && !defined(__OpenBSD__)
    43  #	define _XOPEN_SOURCE 1000
    44  #	define _XOPEN_SOURCE_EXTENDED 1
    45  #endif
    46  #if defined(__FreeBSD__)
    47  #	include <sys/cdefs.h>
    48  	/* for strtoll */
    49  #	undef __ISO_C_VISIBLE
    50  #	define __ISO_C_VISIBLE 1999
    51  #	undef __LONG_LONG_SUPPORTED
    52  #	define __LONG_LONG_SUPPORTED
    53  #endif
    54  #define _LARGEFILE64_SOURCE 1
    55  #define _FILE_OFFSET_BITS 64
    56  
    57  #include <inttypes.h>
    58  
    59  #include <unistd.h>
    60  #include <string.h>
    61  #include <stdlib.h>
    62  #include <stdarg.h>
    63  #include <fcntl.h>
    64  #include <assert.h>
    65  #include <setjmp.h>
    66  #include <stddef.h>
    67  #include <math.h>
    68  #include <ctype.h>	/* for tolower */
    69  #include <signal.h>
    70  #include <time.h>
    71  
    72  /*
    73   * OS-specific crap
    74   */
    75  #define _NEEDUCHAR 1
    76  #define _NEEDUSHORT 1
    77  #define _NEEDUINT 1
    78  #define _NEEDULONG 1
    79  
    80  #ifdef _WIN32
    81  typedef jmp_buf sigjmp_buf;
    82  #endif
    83  typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
    84  
    85  #if defined(__linux__) || defined(__akaros__)
    86  #	include <sys/types.h>
    87  #	if defined(__Linux26__)
    88  #		include <pthread.h>
    89  #		define PLAN9PORT_USING_PTHREADS 1
    90  #	endif
    91  #	if defined(__USE_MISC)
    92  #		undef _NEEDUSHORT
    93  #		undef _NEEDUINT
    94  #		undef _NEEDULONG
    95  #	endif
    96  #elif defined(__sun__)
    97  #	include <sys/types.h>
    98  #	include <pthread.h>
    99  #	define PLAN9PORT_USING_PTHREADS 1
   100  #	undef _NEEDUSHORT
   101  #	undef _NEEDUINT
   102  #	undef _NEEDULONG
   103  #	define nil 0	/* no cast to void* */
   104  #elif defined(__FreeBSD__)
   105  #	include <sys/types.h>
   106  #	include <osreldate.h>
   107  #	if __FreeBSD_version >= 500000
   108  #		define PLAN9PORT_USING_PTHREADS 1
   109  #		include <pthread.h>
   110  #	endif
   111  #	if !defined(_POSIX_SOURCE)
   112  #		undef _NEEDUSHORT
   113  #		undef _NEEDUINT
   114  #	endif
   115  #elif defined(__APPLE__)
   116  #	include <sys/types.h>
   117  #	include <pthread.h>
   118  #	define PLAN9PORT_USING_PTHREADS 1
   119  #	if __GNUC__ < 4
   120  #		undef _NEEDUSHORT
   121  #		undef _NEEDUINT
   122  #	endif
   123  #	undef _ANSI_SOURCE
   124  #	undef _POSIX_C_SOURCE
   125  #	undef _XOPEN_SOURCE
   126  #	if !defined(NSIG)
   127  #		define NSIG 32
   128  #	endif
   129  #	define _NEEDLL 1
   130  #elif defined(__NetBSD__)
   131  #	include <sched.h>
   132  #	include <sys/types.h>
   133  #	undef _NEEDUSHORT
   134  #	undef _NEEDUINT
   135  #	undef _NEEDULONG
   136  #elif defined(__OpenBSD__)
   137  #	include <sys/types.h>
   138  #	undef _NEEDUSHORT
   139  #	undef _NEEDUINT
   140  #	undef _NEEDULONG
   141  #elif defined(_WIN32)
   142  #else
   143  	/* No idea what system this is -- try some defaults */
   144  #	include <pthread.h>
   145  #	define PLAN9PORT_USING_PTHREADS 1
   146  #endif
   147  
   148  #ifndef O_DIRECT
   149  #define O_DIRECT 0
   150  #endif
   151  
   152  typedef signed char schar;
   153  
   154  #ifdef _NEEDUCHAR
   155  	typedef unsigned char uchar;
   156  #endif
   157  #ifdef _NEEDUSHORT
   158  	typedef unsigned short ushort;
   159  #endif
   160  #ifdef _NEEDUINT
   161  	typedef unsigned int uint;
   162  #endif
   163  #ifdef _NEEDULONG
   164  	typedef unsigned long ulong;
   165  #endif
   166  typedef unsigned long long uvlong;
   167  typedef long long vlong;
   168  
   169  typedef uint64_t u64int;
   170  typedef int64_t s64int;
   171  typedef uint8_t u8int;
   172  typedef int8_t s8int;
   173  typedef uint16_t u16int;
   174  typedef int16_t s16int;
   175  typedef uintptr_t uintptr;
   176  typedef intptr_t intptr;
   177  typedef uint32_t u32int;
   178  typedef int32_t s32int;
   179  
   180  typedef s8int int8;
   181  typedef u8int uint8;
   182  typedef s16int int16;
   183  typedef u16int uint16;
   184  typedef s32int int32;
   185  typedef u32int uint32;
   186  typedef s64int int64;
   187  typedef u64int uint64;
   188  
   189  typedef float float32;
   190  typedef double float64;
   191  
   192  #undef _NEEDUCHAR
   193  #undef _NEEDUSHORT
   194  #undef _NEEDUINT
   195  #undef _NEEDULONG
   196  
   197  #define getcallerpc(x)	__builtin_return_address(0)
   198  
   199  #ifndef SIGBUS
   200  #define SIGBUS SIGSEGV /* close enough */
   201  #endif
   202  
   203  /*
   204   * Funny-named symbols to tip off 9l to autolink.
   205   */
   206  #define AUTOLIB(x)	static int __p9l_autolib_ ## x = 1;
   207  #define AUTOFRAMEWORK(x) static int __p9l_autoframework_ ## x = 1;
   208  
   209  /*
   210   * Gcc is too smart for its own good.
   211   */
   212  #if defined(__GNUC__)
   213  #	undef strcmp	/* causes way too many warnings */
   214  #	if __GNUC__ >= 4 || (__GNUC__==3 && !defined(__APPLE_CC__) && !defined(_WIN32))
   215  #		undef AUTOLIB
   216  #		define AUTOLIB(x) int __p9l_autolib_ ## x __attribute__ ((weak));
   217  #		undef AUTOFRAMEWORK
   218  #		define AUTOFRAMEWORK(x) int __p9l_autoframework_ ## x __attribute__ ((weak));
   219  #	else
   220  #		undef AUTOLIB
   221  #		define AUTOLIB(x) static int __p9l_autolib_ ## x __attribute__ ((unused));
   222  #		undef AUTOFRAMEWORK
   223  #		define AUTOFRAMEWORK(x) static int __p9l_autoframework_ ## x __attribute__ ((unused));
   224  #	endif
   225  #endif
   226  
   227  #if defined(__cplusplus)
   228  }
   229  #endif
   230  #endif