1 /*********************************************************************** 2 * * 3 * This software is part of the ast package * 4 * Copyright (c) 1985-2012 AT&T Intellectual Property * 5 * and is licensed under the * 6 * Eclipse Public License, Version 1.0 * 7 * by AT&T Intellectual Property * 8 * * 9 * A copy of the License is available at * 10 * http://www.eclipse.org/org/documents/epl-v10.html * 11 * (with md5 checksum b35adb5213ca9657e911e9befb180842) * 12 * * 13 * Information and Software Systems Research * 14 * AT&T Research * 15 * Florham Park NJ * 16 * * 17 * Glenn Fowler <gsf@research.att.com> * 18 * David Korn <dgk@research.att.com> * 19 * Phong Vo <kpv@research.att.com> * 20 * * 21 ***********************************************************************/ 22 #pragma prototyped 23 /* 24 * Advanced Software Technology Library 25 * AT&T Research 26 * 27 * std + posix + ast 28 */ 29 30 #ifndef _AST_H 31 #define _AST_H 32 33 #ifndef _AST_STD_H 34 #include <ast_std.h> 35 #endif 36 37 #ifndef _SFIO_H 38 #include <sfio.h> 39 #endif 40 41 #ifndef ast 42 #define ast _ast_info 43 #endif 44 45 #ifndef PATH_MAX 46 #define PATH_MAX 1024 47 #endif 48 49 /* 50 * workaround botched headers that assume <stdio.h> 51 */ 52 53 #ifndef FILE 54 #ifndef _SFIO_H 55 struct _sfio_s; 56 #endif 57 #define FILE struct _sfio_s 58 #ifndef __FILE_typedef 59 #define __FILE_typedef 1 60 #endif 61 #ifndef _FILEDEFED 62 #define _FILEDEFED 1 63 #endif 64 #endif 65 66 /* 67 * exit() support -- this matches shell exit codes 68 */ 69 70 #define EXIT_BITS 8 /* # exit status bits */ 71 72 #define EXIT_USAGE 2 /* usage exit code */ 73 #define EXIT_QUIT ((1<<(EXIT_BITS))-1) /* parent should quit */ 74 #define EXIT_NOTFOUND ((1<<(EXIT_BITS-1))-1) /* command not found */ 75 #define EXIT_NOEXEC ((1<<(EXIT_BITS-1))-2) /* other exec error */ 76 77 #define EXIT_CODE(x) ((x)&((1<<EXIT_BITS)-1)) 78 #define EXIT_CORE(x) (EXIT_CODE(x)|(1<<EXIT_BITS)|(1<<(EXIT_BITS-1))) 79 #define EXIT_TERM(x) (EXIT_CODE(x)|(1<<EXIT_BITS)) 80 81 /* 82 * NOTE: for compatibility the following work for EXIT_BITS={7,8} 83 */ 84 85 #define EXIT_STATUS(x) (((x)&((1<<(EXIT_BITS-2))-1))?(x):EXIT_CODE((x)>>EXIT_BITS)) 86 87 #define EXITED_CORE(x) (((x)&((1<<EXIT_BITS)|(1<<(EXIT_BITS-1))))==((1<<EXIT_BITS)|(1<<(EXIT_BITS-1)))||((x)&((1<<(EXIT_BITS-1))|(1<<(EXIT_BITS-2))))==((1<<(EXIT_BITS-1))|(1<<(EXIT_BITS-2)))) 88 #define EXITED_TERM(x) ((x)&((1<<EXIT_BITS)|(1<<(EXIT_BITS-1)))) 89 90 /* 91 * astconflist() flags 92 */ 93 94 #define ASTCONF_parse 0x0001 95 #define ASTCONF_write 0x0002 96 #define ASTCONF_read 0x0004 97 #define ASTCONF_lower 0x0008 98 #define ASTCONF_base 0x0010 99 #define ASTCONF_defined 0x0020 100 #define ASTCONF_quote 0x0040 101 #define ASTCONF_table 0x0080 102 #define ASTCONF_matchcall 0x0100 103 #define ASTCONF_matchname 0x0200 104 #define ASTCONF_matchstandard 0x0400 105 #define ASTCONF_error 0x0800 106 #define ASTCONF_system 0x1000 107 #define ASTCONF_AST 0x2000 108 109 /* 110 * pathcanon() flags 111 */ 112 113 #define PATH_PHYSICAL 01 114 #define PATH_DOTDOT 02 115 #define PATH_EXISTS 04 116 #define PATH_VERIFIED(n) (((n)&01777)<<5) 117 118 /* 119 * pathaccess() flags 120 */ 121 122 #define PATH_READ 004 123 #define PATH_WRITE 002 124 #define PATH_EXECUTE 001 125 #define PATH_REGULAR 010 126 #define PATH_ABSOLUTE 020 127 128 /* 129 * touch() flags 130 */ 131 132 #define PATH_TOUCH_CREATE 01 133 #define PATH_TOUCH_VERBATIM 02 134 135 /* 136 * pathcheck() info 137 */ 138 139 typedef struct 140 { 141 unsigned long date; 142 char* feature; 143 char* host; 144 char* user; 145 } Pathcheck_t; 146 147 /* 148 * strgrpmatch() flags 149 */ 150 151 #define STR_MAXIMAL 01 /* maximal match */ 152 #define STR_LEFT 02 /* implicit left anchor */ 153 #define STR_RIGHT 04 /* implicit right anchor */ 154 #define STR_ICASE 010 /* ignore case */ 155 #define STR_GROUP 020 /* (|&) inside [@|&](...) only */ 156 157 /* 158 * fmtquote() flags 159 */ 160 161 #define FMT_ALWAYS 0x01 /* always quote */ 162 #define FMT_ESCAPED 0x02 /* already escaped */ 163 #define FMT_SHELL 0x04 /* escape $ ` too */ 164 #define FMT_WIDE 0x08 /* don't escape 8 bit chars */ 165 #define FMT_PARAM 0x10 /* disable FMT_SHELL ${$( quote */ 166 167 /* 168 * chrexp() flags 169 */ 170 171 #define FMT_EXP_CHAR 0x020 /* expand single byte chars */ 172 #define FMT_EXP_LINE 0x040 /* expand \n and \r */ 173 #define FMT_EXP_WIDE 0x080 /* expand \u \U \x wide chars */ 174 #define FMT_EXP_NOCR 0x100 /* skip \r */ 175 #define FMT_EXP_NONL 0x200 /* skip \n */ 176 177 /* 178 * multibyte macros 179 */ 180 181 #define mbmax() (ast.mb_cur_max) 182 #define mberr() (ast.tmp_int<0) 183 184 #define mbcoll() (ast.mb_xfrm!=0) 185 #define mbwide() (mbmax()>1) 186 187 #define mb2wc(w,p,n) (*ast.mb_towc)(&w,(char*)p,n) 188 #define mbchar(p) (mbwide()?((ast.tmp_int=(*ast.mb_towc)(&ast.tmp_wchar,(char*)(p),mbmax()))>0?((p+=ast.tmp_int),ast.tmp_wchar):(p+=ast.mb_sync+1,ast.tmp_int)):(*(unsigned char*)(p++))) 189 #define mbnchar(p,n) (mbwide()?((ast.tmp_int=(*ast.mb_towc)(&ast.tmp_wchar,(char*)(p),n))>0?((p+=ast.tmp_int),ast.tmp_wchar):(p+=ast.mb_sync+1,ast.tmp_int)):(*(unsigned char*)(p++))) 190 #define mbinit() (mbwide()?(*ast.mb_towc)((wchar_t*)0,(char*)0,mbmax()):0) 191 #define mbsize(p) (mbwide()?(*ast.mb_len)((char*)(p),mbmax()):((p),1)) 192 #define mbnsize(p,n) (mbwide()?(*ast.mb_len)((char*)(p),n):((p),1)) 193 #define mbconv(s,w) (ast.mb_conv?(*ast.mb_conv)(s,w):((*(s)=(w)),1)) 194 #define mbwidth(w) (ast.mb_width?(*ast.mb_width)(w):1) 195 #define mbxfrm(t,f,n) (mbcoll()?(*ast.mb_xfrm)((char*)(t),(char*)(f),n):0) 196 #define mbalpha(w) (ast.mb_alpha?(*ast.mb_alpha)(w):isalpha((w)&0xff)) 197 198 /* 199 * common macros 200 */ 201 202 #define elementsof(x) (sizeof(x)/sizeof(x[0])) 203 #define integralof(x) (((char*)(x))-((char*)0)) 204 #define newof(p,t,n,x) ((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)calloc(1,sizeof(t)*(n)+(x))) 205 #define oldof(p,t,n,x) ((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)malloc(sizeof(t)*(n)+(x))) 206 #define pointerof(x) ((void*)((char*)0+(x))) 207 #define roundof(x,y) (((x)+(y)-1)&~((y)-1)) 208 #define ssizeof(x) ((int)sizeof(x)) 209 210 #define streq(a,b) (*(a)==*(b)&&!strcmp(a,b)) 211 #define strneq(a,b,n) (*(a)==*(b)&&!strncmp(a,b,n)) 212 #define strsignal(s) fmtsignal(s) 213 214 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) 215 #define NiL 0 216 #define NoP(x) (void)(x) 217 #else 218 #define NiL ((char*)0) 219 #define NoP(x) (&x,1) 220 #endif 221 222 #if !defined(NoF) 223 #define NoF(x) void _DATA_ ## x () {} 224 #if !defined(_DATA_) 225 #define _DATA_ 226 #endif 227 #endif 228 229 #if !defined(NoN) 230 #define NoN(x) void _STUB_ ## x () {} 231 #if !defined(_STUB_) 232 #define _STUB_ 233 #endif 234 #endif 235 236 #define NOT_USED(x) NoP(x) 237 238 typedef int (*Error_f)(void*, void*, int, ...); 239 240 typedef int (*Ast_confdisc_f)(const char*, const char*, const char*); 241 typedef int (*Strcmp_context_f)(const char*, const char*, void*); 242 typedef int (*Strcmp_f)(const char*, const char*); 243 244 #if _BLD_ast && defined(__EXPORT__) 245 #define extern __EXPORT__ 246 #endif 247 248 extern char* astgetconf(const char*, const char*, const char*, int, Error_f); 249 extern char* astconf(const char*, const char*, const char*); 250 extern Ast_confdisc_f astconfdisc(Ast_confdisc_f); 251 extern void astconflist(Sfio_t*, const char*, int, const char*); 252 extern off_t astcopy(int, int, off_t); 253 extern int astlicense(char*, int, char*, char*, int, int, int); 254 extern int astquery(int, const char*, ...); 255 extern void astwinsize(int, int*, int*); 256 257 extern ssize_t base64encode(const void*, size_t, void**, void*, size_t, void**); 258 extern ssize_t base64decode(const void*, size_t, void**, void*, size_t, void**); 259 extern int chresc(const char*, char**); 260 extern int chrexp(const char*, char**, int*, int); 261 extern int chrtoi(const char*); 262 extern char* conformance(const char*, size_t); 263 extern int eaccess(const char*, int); 264 extern char* fmtbase(intmax_t, int, int); 265 #define fmtbasell(a,b,c) fmtbase(a,b,c) /* until 2014-01-01 */ 266 extern char* fmtbuf(size_t); 267 extern char* fmtclock(Sfulong_t); 268 extern char* fmtelapsed(unsigned long, int); 269 extern char* fmterror(int); 270 extern char* fmtesc(const char*); 271 extern char* fmtesq(const char*, const char*); 272 extern char* fmtident(const char*); 273 extern char* fmtip4(uint32_t, int); 274 extern char* fmtfmt(const char*); 275 extern char* fmtgid(int); 276 extern char* fmtint(intmax_t, int); 277 extern char* fmtmatch(const char*); 278 extern char* fmtmode(int, int); 279 extern char* fmtnesq(const char*, const char*, size_t); 280 extern char* fmtnum(unsigned long, int); 281 extern char* fmtperm(int); 282 extern char* fmtquote(const char*, const char*, const char*, size_t, int); 283 extern char* fmtre(const char*); 284 extern char* fmtscale(Sfulong_t, int); 285 extern char* fmtsignal(int); 286 extern char* fmttime(const char*, time_t); 287 extern char* fmtuid(int); 288 extern char* fmtversion(unsigned long); 289 extern void* memdup(const void*, size_t); 290 extern void memfatal(void); 291 extern unsigned int memhash(const void*, int); 292 extern unsigned long memsum(const void*, int, unsigned long); 293 extern char* pathaccess(char*, const char*, const char*, const char*, int); 294 extern char* pathaccess_20100601(const char*, const char*, const char*, int, char*, size_t); 295 extern char* pathbin(void); 296 extern char* pathcanon(char*, int); 297 extern char* pathcanon_20100601(char*, size_t, int); 298 extern char* pathcat(char*, const char*, int, const char*, const char*); 299 extern char* pathcat_20100601(const char*, int, const char*, const char*, char*, size_t); 300 extern int pathcd(const char*, const char*); 301 extern int pathcheck(const char*, const char*, Pathcheck_t*); 302 extern int pathexists(char*, int); 303 extern char* pathfind(const char*, const char*, const char*, char*, size_t); 304 extern int pathgetlink(const char*, char*, int); 305 extern int pathinclude(const char*); 306 extern char* pathkey(char*, char*, const char*, const char*, const char*); 307 extern char* pathkey_20100601(const char*, const char*, const char*, char*, size_t, char*, size_t); 308 extern size_t pathnative(const char*, char*, size_t); 309 extern char* pathpath(char*, const char*, const char*, int); 310 extern char* pathpath_20100601(const char*, const char*, int, char*, size_t); 311 extern size_t pathposix(const char*, char*, size_t); 312 extern char* pathprobe(char*, char*, const char*, const char*, const char*, int); 313 extern char* pathprobe_20100601(const char*, const char*, const char*, int, char*, size_t, char*, size_t); 314 extern size_t pathprog(const char*, char*, size_t); 315 extern char* pathrepl(char*, const char*, const char*); 316 extern char* pathrepl_20100601(char*, size_t, const char*, const char*); 317 extern int pathsetlink(const char*, const char*); 318 extern char* pathshell(void); 319 extern char* pathtemp(char*, size_t, const char*, const char*, int*); 320 extern char* pathtmp(char*, const char*, const char*, int*); 321 extern char* setenviron(const char*); 322 extern int stracmp(const char*, const char*); 323 extern char* strcopy(char*, const char*); 324 extern unsigned long strelapsed(const char*, char**, int); 325 extern int stresc(char*); 326 extern int strexp(char*, int); 327 extern long streval(const char*, char**, long(*)(const char*, char**)); 328 extern long strexpr(const char*, char**, long(*)(const char*, char**, void*), void*); 329 extern int strgid(const char*); 330 extern int strgrpmatch(const char*, const char*, int*, int, int); 331 extern int strgrpmatch_20120528(const char*, const char*, ssize_t*, int, int); 332 extern unsigned int strhash(const char*); 333 extern void* strlook(const void*, size_t, const char*); 334 extern int strmatch(const char*, const char*); 335 extern int strmode(const char*); 336 extern int strnacmp(const char*, const char*, size_t); 337 extern char* strncopy(char*, const char*, size_t); 338 extern int strnpcmp(const char*, const char*, size_t); 339 extern double strntod(const char*, size_t, char**); 340 extern _ast_fltmax_t strntold(const char*, size_t, char**); 341 extern long strntol(const char*, size_t, char**, int); 342 extern intmax_t strntoll(const char*, size_t, char**, int); 343 extern long strnton(const char*, size_t, char**, char*, int); 344 extern unsigned long strntoul(const char*, size_t, char**, int); 345 extern intmax_t strntonll(const char*, size_t, char**, char*, int); 346 extern uintmax_t strntoull(const char*, size_t, char**, int); 347 extern int strnvcmp(const char*, const char*, size_t); 348 extern int stropt(const char*, const void*, int, int(*)(void*, const void*, int, const char*), void*); 349 extern int strpcmp(const char*, const char*); 350 extern int strperm(const char*, char**, int); 351 extern void* strpsearch(const void*, size_t, size_t, const char*, char**); 352 extern void* strsearch(const void*, size_t, size_t, Strcmp_f, const char*, void*); 353 extern void strsort(char**, int, int(*)(const char*, const char*)); 354 extern char* strsubmatch(const char*, const char*, int); 355 extern unsigned long strsum(const char*, unsigned long); 356 extern char* strtape(const char*, char**); 357 extern int strtoip4(const char*, char**, uint32_t*, unsigned char*); 358 extern long strton(const char*, char**, char*, int); 359 extern intmax_t strtonll(const char*, char**, char*, int); 360 extern int struid(const char*); 361 extern int struniq(char**, int); 362 extern int strvcmp(const char*, const char*); 363 extern int wc2utf8(char*, uint32_t); 364 365 #undef extern 366 367 /* 368 * C library global data symbols not prototyped by <unistd.h> 369 */ 370 371 #if !defined(environ) && defined(__DYNAMIC__) 372 #define environ __DYNAMIC__(environ) 373 #else 374 extern char** environ; 375 #endif 376 377 /* 378 * really handy malloc()/free() (__FILE__,__LINE__,__FUNCTION__) tracing 379 * make with VMDEBUG==1 or debug=1 or CCFLAGS=$(CC.DEBUG) 380 * VMDEBUG==0 disables 381 * at runtime export VMALLOC_OPTIONS per vmalloc.3 382 * to list originating call locations 383 */ 384 385 #if !_std_malloc && !defined(VMFL) && !defined(_VMHDR_H) && \ 386 (VMDEBUG || !defined(VMDEBUG) && _BLD_DEBUG) 387 388 #define VMFL 1 389 #include <vmalloc.h> 390 391 #endif 392 393 #include <ast_api.h> 394 395 #undef AST_PLUGIN_VERSION 396 #define AST_PLUGIN_VERSION(v) ((v)>AST_VERSION?(v):AST_VERSION) 397 398 #if defined(__EXPORT__) 399 #define extern __EXPORT__ 400 #endif 401 402 extern unsigned long plugin_version(void); 403 404 #undef extern 405 406 #endif 407