da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/***********************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* This software is part of the ast package *
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner* Copyright (c) 1985-2010 AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* and is licensed under the *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Common Public License, Version 1.0 *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* by AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* A copy of the License is available at *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Information and Software Systems Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* AT&T Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Florham Park NJ *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Glenn Fowler <gsf@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* David Korn <dgk@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Phong Vo <kpv@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin***********************************************************************/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Advanced Software Technology Library
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * AT&T Research
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * std + posix + ast
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * workaround botched headers that assume <stdio.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * exit() support -- this matches shell exit codes
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define EXIT_QUIT ((1<<(EXIT_BITS))-1) /* parent should quit */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define EXIT_NOTFOUND ((1<<(EXIT_BITS-1))-1) /* command not found */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define EXIT_NOEXEC ((1<<(EXIT_BITS-1))-2) /* other exec error */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define EXIT_CORE(x) (EXIT_CODE(x)|(1<<EXIT_BITS)|(1<<(EXIT_BITS-1)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * NOTE: for compatibility the following work for EXIT_BITS={7,8}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define EXIT_STATUS(x) (((x)&((1<<(EXIT_BITS-2))-1))?(x):EXIT_CODE((x)>>EXIT_BITS))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#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))))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define EXITED_TERM(x) ((x)&((1<<EXIT_BITS)|(1<<(EXIT_BITS-1))))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * astconflist() flags
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * pathcanon() flags
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * pathaccess() flags
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * touch() flags
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * pathcheck() info
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef struct
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * strgrpmatch() flags
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * fmtquote() flags
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define FMT_PARAM 0x10 /* disable FMT_SHELL ${$( quote */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * multibyte macros
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#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++)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define mbinit() (mbwide()?(*ast.mb_towc)((wchar_t*)0,(char*)0,mbmax()):0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define mbsize(p) (mbwide()?(*ast.mb_len)((char*)(p),mbmax()):((p),1))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define mbconv(s,w) (ast.mb_conv?(*ast.mb_conv)(s,w):((*(s)=(w)),1))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define mbwidth(w) (ast.mb_width&&((ast.tmp_int=(*ast.mb_width)(w))>=0||(w)>UCHAR_MAX)?ast.tmp_int:1)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define mbxfrm(t,f,n) (mbcoll()?(*ast.mb_xfrm)((char*)(t),(char*)(f),n):0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * common macros
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define newof(p,t,n,x) ((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)calloc(1,sizeof(t)*(n)+(x)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define oldof(p,t,n,x) ((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)malloc(sizeof(t)*(n)+(x)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if !defined(NoF)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if !defined(_DATA_)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if !defined(NoN)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if !defined(_STUB_)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef int (*Ast_confdisc_f)(const char*, const char*, const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef int (*Strcmp_context_f)(const char*, const char*, void*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define extern __EXPORT__
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* astgetconf(const char*, const char*, const char*, int, Error_f);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* astconf(const char*, const char*, const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern void astconflist(Sfio_t*, const char*, int, const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int astlicense(char*, int, char*, char*, int, int, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int astquery(int, const char*, ...);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern void astwinsize(int, int*, int*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern ssize_t base64encode(const void*, size_t, void**, void*, size_t, void**);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern ssize_t base64decode(const void*, size_t, void**, void*, size_t, void**);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int chresc(const char*, char**);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int chrtoi(const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int eaccess(const char*, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtbase(long, int, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define fmtbase(a,b,c) fmtbasell((intmax_t)(a),b,c) /* until 2003-09-01 */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtelapsed(unsigned long, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmterror(int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtesc(const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtesq(const char*, const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtident(const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtfmt(const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtgid(int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtmatch(const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtmode(int, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtnum(unsigned long, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtperm(int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtquote(const char*, const char*, const char*, size_t, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtre(const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtsignal(int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtuid(int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* fmtversion(unsigned long);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern void memfatal(void);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern unsigned int memhash(const void*, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern unsigned long memsum(const void*, int, unsigned long);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* pathaccess(char*, const char*, const char*, const char*, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* pathbin(void);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* pathcanon(char*, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* pathcat(char*, const char*, int, const char*, const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int pathcd(const char*, const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int pathcheck(const char*, const char*, Pathcheck_t*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int pathexists(char*, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* pathfind(const char*, const char*, const char*, char*, size_t);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int pathgetlink(const char*, char*, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int pathinclude(const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* pathkey(char*, char*, const char*, const char*, const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* pathpath(char*, const char*, const char*, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* pathprobe(char*, char*, const char*, const char*, const char*, int);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzextern size_t pathprog(const char*, char*, size_t);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* pathrepl(char*, const char*, const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int pathsetlink(const char*, const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* pathshell(void);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* pathtemp(char*, size_t, const char*, const char*, int*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* pathtmp(char*, const char*, const char*, int*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* setenviron(const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int stracmp(const char*, const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* strcopy(char*, const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern unsigned long strelapsed(const char*, char**, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int stresc(char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern long streval(const char*, char**, long(*)(const char*, char**));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern long strexpr(const char*, char**, long(*)(const char*, char**, void*), void*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int strgid(const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int strgrpmatch(const char*, const char*, int*, int, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern unsigned int strhash(const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int strmatch(const char*, const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int strmode(const char*);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzextern int strnpcmp(const char*, const char*, size_t);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern _ast_fltmax_t strntold(const char*, size_t, char**);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern intmax_t strntoll(const char*, size_t, char**, int);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinextern long strnton(const char*, size_t, char**, char*, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern unsigned long strntoul(const char*, size_t, char**, int);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinextern intmax_t strntonll(const char*, size_t, char**, char*, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern uintmax_t strntoull(const char*, size_t, char**, int);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzextern int strnvcmp(const char*, const char*, size_t);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int stropt(const char*, const void*, int, int(*)(void*, const void*, int, const char*), void*);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzextern int strpcmp(const char*, const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int strperm(const char*, char**, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern void* strpsearch(const void*, size_t, size_t, const char*, char**);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern void* strsearch(const void*, size_t, size_t, Strcmp_f, const char*, void*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern void strsort(char**, int, int(*)(const char*, const char*));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* strsubmatch(const char*, const char*, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern unsigned long strsum(const char*, unsigned long);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* strtape(const char*, char**);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int strtoip4(const char*, char**, uint32_t*, unsigned char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern long strton(const char*, char**, char*, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern intmax_t strtonll(const char*, char**, char*, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int struid(const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int struniq(char**, int);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzextern int strvcmp(const char*, const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * C library global data symbols not prototyped by <unistd.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char** environ;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * really handy malloc()/free() (__FILE__,__LINE__,__FUNCTION__) tracing
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * make with VMDEBUG==1 or debug=1 or CCFLAGS=$(CC.DEBUG)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * VMDEBUG==0 disables
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * at runtime export VMDEBUG or VMTRACE per vmalloc.3
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * to list originating call locations
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if !_std_malloc && !defined(VMFL) && !defined(_VMHDR_H) && \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (!defined(VMDEBUG) || VMDEBUG) && (VMDEBUG || _BLD_DEBUG)