00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 /* ==================================================================== 00036 * ==================================================================== 00037 * 00038 * Module: inttypes.h 00039 * $Revision: 1.1.1.1 $ 00040 * $Date: 2005/10/21 19:00:00 $ 00041 * 00042 * Revision history: 00043 * 14-Sep-92 - Original Version 00044 * 28-Oct-92 - Revisions from 7 October committee meeting. 00045 * 29-Oct-92 - Minor adjustments based on comments. 00046 * 26-Feb-93 - Revisions from November committee meeting. 00047 * 17-Aug-93 - Converted template to SGI-specific form. 00048 * 00049 * Description: 00050 * 00051 * This header defines types (via typedefs) with size attributes which 00052 * are independent of the definitions of the base C types provided by 00053 * the implementation. It also defines facilities for manipulating 00054 * objects of those types, i.e. defining constants, printf/scanf 00055 * support, and conversions. 00056 * 00057 * The intent is that, using this header file and the facilities it 00058 * describes, a user can write C code with fixed-size objects which 00059 * is interoperable and portable among a broad range of target 00060 * environments, including 16-bit or 32-bit PCs as well as 32-bit or 00061 * 64-bit workstations. 00062 * 00063 * ==================================================================== 00064 * ==================================================================== 00065 */ 00066 00067 #ifndef __INTTYPES_H__ 00068 #define __INTTYPES_H__ 00069 00070 /* The following values encode the current revision of the template. 00071 * The first "official" release will be 1.0. Subsequent releases will 00072 * increment the major ID for significant or incompatible changes, and 00073 * the minor ID for minor extensions. 00074 */ 00075 #define __INTTYPES_MAJOR 0 00076 #define __INTTYPES_MINOR 1 00077 00078 /* =========================== TYPES ============================= */ 00079 00080 /* Define the basic fixed-size integer types. Their intended semantics 00081 * are to produce objects of precisely the implied size, and to cause 00082 * (as operands) expression evaluation of either that size or the size 00083 * of the underlying 'int' type if larger (the normal ANSI C promotion 00084 * rules). 00085 * 00086 * intmax_t and uintmax_t are integer types guaranteed to be the 00087 * largest supported by the implementation. They are intended for 00088 * use in places where code must be able to cope with any integer 00089 * value. 00090 * 00091 * intptr_t and uintptr_t are integer types guaranteed to be exactly 00092 * the size of a pointer. 00093 */ 00094 00095 #include <standards.h> 00096 #ifndef _LP64 00097 #include <sgidefs.h> 00098 00099 #ifndef __inttypes_INCLUDED 00100 #define __inttypes_INCLUDED 00101 /* 00102 * These definitions are also in sys/types.h and need to be kept consistent 00103 */ 00104 00105 typedef signed char int8_t; 00106 typedef unsigned char uint8_t; 00107 typedef signed short int16_t; 00108 typedef unsigned short uint16_t; 00109 typedef signed int int32_t; 00110 typedef unsigned int uint32_t; 00111 typedef __int64_t int64_t; 00112 typedef __uint64_t uint64_t; 00113 typedef __int64_t intmax_t; 00114 typedef __uint64_t uintmax_t; 00115 typedef signed long int intptr_t; 00116 typedef unsigned long int uintptr_t; 00117 00118 #endif 00119 #else 00120 typedef unsigned char uint8_t; 00121 typedef unsigned short uint16_t; 00122 typedef unsigned int uint32_t; 00123 typedef __uint64_t uint64_t; 00124 typedef __int64_t intmax_t; 00125 typedef __uint64_t uintmax_t; 00126 #endif /* _LP64 */ 00127 00128 #if _SGIAPI 00129 /* Define limits for the types, in the manner of limits.h: */ 00130 #define INT8_MIN (-127-1) 00131 #define INT8_MAX (127) 00132 #define UINT8_MAX (255u) 00133 #define INT16_MIN (-32767-1) 00134 #define INT16_MAX (32767) 00135 #define UINT16_MAX (65535u) 00136 #define INT32_MIN (-2147483647-1) 00137 #define INT32_MAX (2147483647) 00138 #define UINT32_MAX (4294967295u) 00139 #define INT64_MIN (-9223372036854775807LL-1) 00140 #define INT64_MAX (9223372036854775807LL) 00141 #define UINT64_MAX (18446744073709551615uLL) 00142 #define INTMAX_MIN (-9223372036854775807LL-1) 00143 #define INTMAX_MAX (9223372036854775807LL) 00144 #define UINTMAX_MAX (18446744073709551615uLL) 00145 00146 /* ======================== CONSTANTS ============================ */ 00147 00148 /* Define macros for constants of the above types. The intent is that: 00149 * 00150 * - Constants defined using these macros have a specific length and 00151 * signedness. 00152 * 00153 * - Their extensions in contexts requiring extension (e.g. 00154 * expressions of greater precision than the specified length) 00155 * will be totally determined by that signedness and length. 00156 * For example: 00157 * INT32_C(0xffffffff) 00158 * should define a 32-bit signed negative one, to be sign extended 00159 * if the context requires a 64-bit value. Observe that the 00160 * identity macro in an LP64 model would yield a 32-bit unsigned 00161 * 4 billion something (unsigned int, because the value doesn't 00162 * fit in a 32-bit int), whereas in an ILP64 model it would yield 00163 * a 64-bit signed 4 billion something (signed int). 00164 * 00165 * - Use of such a constant will not itself force greater precision 00166 * than the specified length. For example: 00167 * UINT32_C(3000000000) 00168 * should define a 32-bit unsigned 3 billion, even in an LP64 00169 * implementation where the simple constant 3000000000 would be 00170 * treated as a signed long 3 billion, forcing the containing 00171 * expression to be long. 00172 */ 00173 00174 /* The __CONCAT__ macro may require redefinition for some non-ANSI 00175 * implementations. It should concatenate its two arguments without 00176 * forcing separate tokens. 00177 */ 00178 #define __CONCAT__(A,B) A ## B 00179 00180 #define INT8_C(c) ((int8_t) c) 00181 #define UINT8_C(c) ((uint8_t) __CONCAT__(c,u)) 00182 #define INT16_C(c) ((int16_t) c) 00183 #define UINT16_C(c) ((uint16_t) __CONCAT__(c,u)) 00184 #define INT32_C(c) ((int32_t) c) 00185 #define UINT32_C(c) ((uint32_t) __CONCAT__(c,u)) 00186 #define INT64_C(c) ((int64_t) __CONCAT__(c,ll)) 00187 #define UINT64_C(c) ((uint64_t) __CONCAT__(c,ull)) 00188 #define INTMAX_C(c) ((int64_t) __CONCAT__(c,ll)) 00189 #define UINTMAX_C(c) ((uint64_t) __CONCAT__(c,ull)) 00190 00191 /* Constants are not defined for the pointer-sized integers, since the 00192 * size of the constant value will be known and should be adequate for 00193 * use in the very rare cases where pointer constants must be defined. 00194 */ 00195 00196 /* ====================== FORMATTED I/O ========================== */ 00197 00198 /* Define extended versions of the printf/scanf libc routines. These 00199 * extended routines accept an extended format syntax as follows, and 00200 * are otherwise identical to the corresponding libc routines. 00201 * 00202 * The size specifiers specified by the ANSI standard (i.e. 'h' 'l' and 00203 * 'L' preceding the conversion specifier) are extended to allow "wNN" 00204 * instead, indicating that the relevant object has width NN bits, or 00205 * "wmax" for an intmax_t object. The valid values of NN are 16, 32, 00206 * and 64. For example: 00207 * 00208 * uint16_t u16; 00209 * int32_t s32; 00210 * uint64_t u64; 00211 * ... 00212 * i_printf ( "int16 is %w16u; int32 is %#8w32x\n", u16, s32 ); 00213 * i_scanf ( "%w16o%w64x", &u16, &u64 ); 00214 * 00215 * The extensions are sequences with explicitly undefined semantics in 00216 * the ANSI standard, so create no conflicts. 00217 * 00218 * The implementation must provide these names as macros, matching the 00219 * prototypes below. Therefore, they may be #undefined by a user, and 00220 * their addresses may NOT be taken. (The expectation is that they 00221 * will ultimately be obsoleted by extensions to the underlying ANSI 00222 * routines' format processing.) 00223 * 00224 * The ANSI standard does not specify conversion characters for 00225 * char-sized integers. Accordingly, no "w8" modifier is required. 00226 */ 00227 #include <stdarg.h> 00228 #include <stdio.h> 00229 00230 extern int i_fprintf ( FILE *stream, const char *format, ... ); 00231 extern int i_vfprintf ( FILE *stream, const char *format, va_list va ); 00232 extern int i_printf ( const char *format, ... ); 00233 extern int i_vprintf ( const char *format, va_list va ); 00234 extern int i_sprintf ( char *s, const char *format, ... ); 00235 extern int i_vsprintf ( char *s, const char *format, va_list va ); 00236 00237 extern int i_fscanf ( FILE *stream, const char *format, ... ); 00238 extern int i_scanf ( const char *format, ... ); 00239 extern int i_sscanf ( char *s, const char *format, ... ); 00240 00241 /* ====================== CONVERSIONS ============================ */ 00242 00243 /* The following routines are provided as analogues of the ANSI strtol 00244 * routines, with analogous semantics. They must be provided as 00245 * functions, though the functions may be hidden by macro 00246 * implementations. Users may therefore take their addresses, or pass 00247 * them as actual parameters, by first #undefining the names. 00248 */ 00249 extern int8_t strtoi8 (const char *, char **, int); 00250 extern int16_t strtoi16 (const char *, char **, int); 00251 extern int32_t strtoi32 (const char *, char **, int); 00252 extern int64_t strtoi64 (const char *, char **, int); 00253 extern intmax_t strtoimax (const char *, char **, int); 00254 extern uint8_t strtou8 (const char *, char **, int); 00255 extern uint16_t strtou16 (const char *, char **, int); 00256 extern uint32_t strtou32 (const char *, char **, int); 00257 extern uint64_t strtou64 (const char *, char **, int); 00258 extern uintmax_t strtoumax (const char *, char **, int); 00259 00260 /* ====================== ARITHMETIC ============================ */ 00261 00262 /* The following routines are provided as analogues of the ANSI stdlib 00263 * routines, with analogous semantics. They must be provided as 00264 * functions, though the functions may be hidden by macro 00265 * implementations. Users may therefore take their addresses, or pass 00266 * them as actual parameters, by first #undefining the names. 00267 */ 00268 extern int32_t abs_32 ( int32_t ); 00269 extern int64_t abs_64 ( int64_t ); 00270 extern intmax_t abs_max ( intmax_t ); 00271 00272 typedef struct { int32_t quot; int32_t rem; } div32_t; 00273 typedef struct { int64_t quot; int64_t rem; } div64_t; 00274 typedef struct { intmax_t quot; intmax_t rem; } divmax_t; 00275 extern div32_t div_32 ( int32_t numer, int32_t denom ); 00276 extern div64_t div_64 ( int64_t numer, int64_t denom ); 00277 extern divmax_t div_max ( intmax_t numer, intmax_t denom ); 00278 #endif /* _SGIAPI */ 00279 00280 #endif /* __INTTYPES_H__ */
1.5.6