1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * MKS header file. Defines that make programming easier for us. 31*0Sstevel@tonic-gate * Includes MKS-specific things and posix routines. 32*0Sstevel@tonic-gate * 33*0Sstevel@tonic-gate * Copyright 1985, 1993 by Mortice Kern Systems Inc. All rights reserved. 34*0Sstevel@tonic-gate * 35*0Sstevel@tonic-gate * $Header: /rd/h/rcs/mks.h 1.233 1995/09/28 19:45:19 mark Exp $ 36*0Sstevel@tonic-gate */ 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate #ifndef __M_MKS_H__ 39*0Sstevel@tonic-gate #define __M_MKS_H__ 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate /* 42*0Sstevel@tonic-gate * This should be a feature test macro defined in the Makefile or 43*0Sstevel@tonic-gate * cc command line. 44*0Sstevel@tonic-gate */ 45*0Sstevel@tonic-gate #ifndef MKS 46*0Sstevel@tonic-gate #define MKS 1 47*0Sstevel@tonic-gate #endif 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate /* 50*0Sstevel@tonic-gate * Write function declarations as follows: 51*0Sstevel@tonic-gate * extern char *function ANSI((char *cp, int flags, NODE *np)); 52*0Sstevel@tonic-gate * Expansion of this happens only when __STDC__ is set. 53*0Sstevel@tonic-gate */ 54*0Sstevel@tonic-gate #ifdef __STDC__ 55*0Sstevel@tonic-gate #define ANSI(x) x 56*0Sstevel@tonic-gate #define _VOID void /* Used in VOID *malloc() */ 57*0Sstevel@tonic-gate #else 58*0Sstevel@tonic-gate #define const 59*0Sstevel@tonic-gate #define signed 60*0Sstevel@tonic-gate #define volatile 61*0Sstevel@tonic-gate #define ANSI(x) () 62*0Sstevel@tonic-gate #define _VOID char /* Used in _VOID *malloc() */ 63*0Sstevel@tonic-gate #endif 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate #ifndef STATIC 66*0Sstevel@tonic-gate # define STATIC static /* Used for function definition */ 67*0Sstevel@tonic-gate #endif /*STATIC*/ 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate #ifndef STATREF 70*0Sstevel@tonic-gate # ifdef __STDC__ 71*0Sstevel@tonic-gate # define STATREF static 72*0Sstevel@tonic-gate # else 73*0Sstevel@tonic-gate # define STATREF /* Used in local function forward declaration */ 74*0Sstevel@tonic-gate # endif 75*0Sstevel@tonic-gate #endif /*STATREF*/ 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate #define LEXTERN extern /* Library external reference */ 78*0Sstevel@tonic-gate #define LDEFN /* Define Loadable library entry */ 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate typedef void (*_sigfun_t)(int); 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate #include <mkslocal.h> 83*0Sstevel@tonic-gate #include <stdio.h> 84*0Sstevel@tonic-gate #include <unistd.h> 85*0Sstevel@tonic-gate #include <limits.h> 86*0Sstevel@tonic-gate #include <sys/stat.h> /* required for m_samefile() prototype. */ 87*0Sstevel@tonic-gate #include <m_wchar.h> 88*0Sstevel@tonic-gate #include <m_i18n.h> 89*0Sstevel@tonic-gate #include <m_invari.h> 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate #if M_TFGETC || M_STTY_CC 92*0Sstevel@tonic-gate #include <termios.h> 93*0Sstevel@tonic-gate #endif 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate #ifndef M_LIBDIR 96*0Sstevel@tonic-gate # error "You must define M_LIBDIR in mkslocal.h" 97*0Sstevel@tonic-gate #endif 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate #ifndef M_ETCDIR 100*0Sstevel@tonic-gate # error "You must define M_ETCDIR in mkslocal.h" 101*0Sstevel@tonic-gate #endif 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate #ifndef M_SPOOLDIR 104*0Sstevel@tonic-gate # error "You must define M_SPOOLDIR in mkslocal.h" 105*0Sstevel@tonic-gate #endif 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate #ifndef M_MANPATH 108*0Sstevel@tonic-gate # error "You must define M_MANPATH in mkslocal.h" 109*0Sstevel@tonic-gate #endif 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate #if defined(I18N) && !defined(M_NLSDIR) 112*0Sstevel@tonic-gate # error "You must define M_NLSDIR in mkslocal.h" 113*0Sstevel@tonic-gate #endif 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate #if (defined(M_I18N_MKS_FULL) || defined(M_I18N_MKS_XPG)) && !defined(I18N) 116*0Sstevel@tonic-gate # error I18N must be defined 117*0Sstevel@tonic-gate #endif 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate /* P_tmpdir - used by tmpnam.c and tempnam.c. 120*0Sstevel@tonic-gate * Could be in <stdio.h>. But in case it is not .. 121*0Sstevel@tonic-gate */ 122*0Sstevel@tonic-gate #ifndef P_tmpdir 123*0Sstevel@tonic-gate # ifndef M_TMPDIR 124*0Sstevel@tonic-gate # error M_TMPDIR must be defined in mkslocal.h 125*0Sstevel@tonic-gate # endif 126*0Sstevel@tonic-gate # define P_tmpdir M_TMPDIR 127*0Sstevel@tonic-gate #endif /* P_tmpdir */ 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate /* L_cuserid - used by cuserid.c 130*0Sstevel@tonic-gate * Could be in <stdio.h>. But in case it is not .. 131*0Sstevel@tonic-gate */ 132*0Sstevel@tonic-gate #ifndef L_cuserid 133*0Sstevel@tonic-gate # ifndef M_L_CUSERID 134*0Sstevel@tonic-gate # error M_L_CUSERID must be defined in mkslocal.h 135*0Sstevel@tonic-gate # endif 136*0Sstevel@tonic-gate # define L_cuserid M_L_CUSERID 137*0Sstevel@tonic-gate #endif /* L_cuserid */ 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate #ifdef M_AUDIT 140*0Sstevel@tonic-gate LEXTERN char *m_audmode (int, int); 141*0Sstevel@tonic-gate #if !defined(M_AUDITW1) || !defined(M_AUDITW2) 142*0Sstevel@tonic-gate # error "With M_AUDIT set, you must define M_AUDITW1 and M_AUDITW2" 143*0Sstevel@tonic-gate #endif 144*0Sstevel@tonic-gate #endif /*M_AUDIT*/ 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate #ifndef M_CS_PATH 147*0Sstevel@tonic-gate # error "You must define M_CS_PATH in mkslocal.h" 148*0Sstevel@tonic-gate #endif 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate #ifndef M_CS_SHELL 151*0Sstevel@tonic-gate # error "You must define M_CS_SHELL in mkslocal.h" 152*0Sstevel@tonic-gate #endif 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate #ifndef M_SH_USER_FDS 155*0Sstevel@tonic-gate /* 156*0Sstevel@tonic-gate * default number of user file descriptors to be used in the shell 157*0Sstevel@tonic-gate * Must be >= 10, should be <= OPEN_MAX/2. 158*0Sstevel@tonic-gate */ 159*0Sstevel@tonic-gate #define M_SH_USER_FDS 10 160*0Sstevel@tonic-gate #endif /*M_SH_USER_FDS*/ 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate #ifndef M_SH_MAX_FUNCTION_EVAL_DEPTH 163*0Sstevel@tonic-gate #define M_SH_MAX_FUNCTION_EVAL_DEPTH 100 164*0Sstevel@tonic-gate #endif 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate #ifndef M_MANPAGER 167*0Sstevel@tonic-gate #define M_MANPAGER "more -A -s" 168*0Sstevel@tonic-gate #endif 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate /* set up alert and verticalTab characters - This assumes an ANSI-C compiler */ 171*0Sstevel@tonic-gate #undef M_ALERT 172*0Sstevel@tonic-gate #undef M_VTAB 173*0Sstevel@tonic-gate #define M_ALERT '\a' 174*0Sstevel@tonic-gate #define M_VTAB '\v' 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate #ifndef M_ESCAPE 177*0Sstevel@tonic-gate # define M_ESCAPE '\033' /* default to ASCII code for <ESC> */ 178*0Sstevel@tonic-gate #endif /*M_ESCAPE*/ 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate #ifndef SETVBUF 181*0Sstevel@tonic-gate /* if SETVBUF not previously defined, then use default ANSI-C definition */ 182*0Sstevel@tonic-gate # define SETVBUF setvbuf 183*0Sstevel@tonic-gate #endif 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate #ifdef M_NULL 186*0Sstevel@tonic-gate /* if M_NULL defined in <mkslocal.h> then want to redefine NULL */ 187*0Sstevel@tonic-gate #undef NULL 188*0Sstevel@tonic-gate #define NULL (M_NULL) 189*0Sstevel@tonic-gate #endif /*M_NULL*/ 190*0Sstevel@tonic-gate 191*0Sstevel@tonic-gate /* 192*0Sstevel@tonic-gate * Useful additions to sys/stat.h. 193*0Sstevel@tonic-gate */ 194*0Sstevel@tonic-gate #ifndef S_IRALL 195*0Sstevel@tonic-gate #define S_IRALL (S_IRUSR|S_IRGRP|S_IROTH) 196*0Sstevel@tonic-gate #endif 197*0Sstevel@tonic-gate #ifndef S_IWALL 198*0Sstevel@tonic-gate #define S_IWALL (S_IWUSR|S_IWGRP|S_IWOTH) 199*0Sstevel@tonic-gate #endif 200*0Sstevel@tonic-gate #ifndef S_IXALL 201*0Sstevel@tonic-gate #define S_IXALL (S_IXUSR|S_IXGRP|S_IXOTH) 202*0Sstevel@tonic-gate #endif 203*0Sstevel@tonic-gate 204*0Sstevel@tonic-gate #ifndef M_DEFMODE /* Default directory creation mode */ 205*0Sstevel@tonic-gate #define M_DEFMODE ((mode_t)S_IRALL|S_IWALL)/* Default file creation mode*/ 206*0Sstevel@tonic-gate #endif 207*0Sstevel@tonic-gate #ifndef M_DIRMODE 208*0Sstevel@tonic-gate #define M_DIRMODE ((mode_t)S_IRALL|S_IWALL|S_IXALL) 209*0Sstevel@tonic-gate #endif 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate #ifndef M_FLDSEP 212*0Sstevel@tonic-gate #define M_FLDSEP ':' /* UNIX field separator for passwd, PATH */ 213*0Sstevel@tonic-gate #endif 214*0Sstevel@tonic-gate 215*0Sstevel@tonic-gate #ifndef M_TTYNAME 216*0Sstevel@tonic-gate #define M_TTYNAME "/dev/tty" 217*0Sstevel@tonic-gate #endif 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate #ifndef M_NULLNAME 220*0Sstevel@tonic-gate #define M_NULLNAME "/dev/null" 221*0Sstevel@tonic-gate #endif 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate #ifndef M_FSDELIM 224*0Sstevel@tonic-gate #define M_FSDELIM(c) ((c)=='/') 225*0Sstevel@tonic-gate #endif 226*0Sstevel@tonic-gate 227*0Sstevel@tonic-gate #ifndef M_DRDELIM 228*0Sstevel@tonic-gate #define M_DRDELIM(c) (0) 229*0Sstevel@tonic-gate #endif 230*0Sstevel@tonic-gate 231*0Sstevel@tonic-gate #ifndef M_DIRSTAT 232*0Sstevel@tonic-gate #define M_DIRSTAT(name, dp, sb) stat((name), (sb)) 233*0Sstevel@tonic-gate #endif 234*0Sstevel@tonic-gate 235*0Sstevel@tonic-gate #ifndef M_HIDDEN 236*0Sstevel@tonic-gate #define M_HIDDEN(dirp, dp) ((dp)->d_name[0] == '.') 237*0Sstevel@tonic-gate #endif 238*0Sstevel@tonic-gate 239*0Sstevel@tonic-gate #ifndef M_FSMOUNT /* for use by setmnt routine */ 240*0Sstevel@tonic-gate #define M_FSMOUNT M_ETCDIR(mtab) 241*0Sstevel@tonic-gate #endif 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate #ifndef M_FSALL /* for use by setmnt routine */ 244*0Sstevel@tonic-gate #define M_FSALL M_ETCDIR(fstab) 245*0Sstevel@tonic-gate #endif 246*0Sstevel@tonic-gate 247*0Sstevel@tonic-gate #ifndef M_NLSCHARMAP /* Default charmap file for localedef */ 248*0Sstevel@tonic-gate #define M_NLSCHARMAP M_NLSDIR(charmap/ISO_8859-1) 249*0Sstevel@tonic-gate #endif 250*0Sstevel@tonic-gate 251*0Sstevel@tonic-gate #ifndef M_POSIXPATH /* used when I18N undefined, default posix path */ 252*0Sstevel@tonic-gate #define M_POSIXPATH M_NLSDIR(locale/POSIX) 253*0Sstevel@tonic-gate #endif 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate #ifndef M_ISEOV 256*0Sstevel@tonic-gate #define M_ISEOV(error) 0 257*0Sstevel@tonic-gate #endif 258*0Sstevel@tonic-gate 259*0Sstevel@tonic-gate #ifndef M_IS_NATIVE_LOCALE 260*0Sstevel@tonic-gate #define M_IS_NATIVE_LOCALE(s) (strcmp(s, "POSIX")==0 || strcmp(s, "C")==0) 261*0Sstevel@tonic-gate #endif 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gate #ifndef M_FSCLOSE 264*0Sstevel@tonic-gate #define M_FSCLOSE(fp) 265*0Sstevel@tonic-gate #endif 266*0Sstevel@tonic-gate 267*0Sstevel@tonic-gate #ifndef ROOTUID /* default superuser uid = 0 */ 268*0Sstevel@tonic-gate #define ROOTUID 0 269*0Sstevel@tonic-gate #endif 270*0Sstevel@tonic-gate 271*0Sstevel@tonic-gate #ifndef ROOTGID /* default superuser gid = 0 */ 272*0Sstevel@tonic-gate #define ROOTGID 0 273*0Sstevel@tonic-gate #endif 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gate #ifndef M_GROUP_PASSWD 276*0Sstevel@tonic-gate #define M_GROUP_PASSWD(grp) (grp->gr_passwd) 277*0Sstevel@tonic-gate #endif 278*0Sstevel@tonic-gate 279*0Sstevel@tonic-gate 280*0Sstevel@tonic-gate #ifndef M_NUMSIZE 281*0Sstevel@tonic-gate /* 282*0Sstevel@tonic-gate * define the expected max length of a printed number. (used in awk) 283*0Sstevel@tonic-gate * This should be the longest expected size for any type of number 284*0Sstevel@tonic-gate * ie. float, long etc. 285*0Sstevel@tonic-gate * This number is used to calculate the approximate 286*0Sstevel@tonic-gate * number of bytes needed to hold the number. 287*0Sstevel@tonic-gate */ 288*0Sstevel@tonic-gate #define M_NUMSIZE 30 289*0Sstevel@tonic-gate #endif /* M_NUMSIZE */ 290*0Sstevel@tonic-gate 291*0Sstevel@tonic-gate /* 292*0Sstevel@tonic-gate * VARARG[12345]: declare variadic functions. 293*0Sstevel@tonic-gate * Expands to either a standard C prototype or a K&R declaration. 294*0Sstevel@tonic-gate * For example: 295*0Sstevel@tonic-gate * 296*0Sstevel@tonic-gate * #include <stdarg.h> 297*0Sstevel@tonic-gate * int 298*0Sstevel@tonic-gate * fprintf VARARG2(FILE*, fp, char*, fmt) 299*0Sstevel@tonic-gate * { 300*0Sstevel@tonic-gate * va_list ap; 301*0Sstevel@tonic-gate * 302*0Sstevel@tonic-gate * va_start(ap, fmt); 303*0Sstevel@tonic-gate * cp = va_arg(ap, char*); 304*0Sstevel@tonic-gate * va_end(ap); 305*0Sstevel@tonic-gate * } 306*0Sstevel@tonic-gate */ 307*0Sstevel@tonic-gate #ifndef VARARG1 308*0Sstevel@tonic-gate #ifdef __STDC__ 309*0Sstevel@tonic-gate #define VARARG1(type, name) (type name, ...) 310*0Sstevel@tonic-gate #define VARARG2(t1, n1, t2, n2) (t1 n1, t2 n2, ...) 311*0Sstevel@tonic-gate #define VARARG3(t1, n1, t2, n2, t3, n3) (t1 n1, t2 n2, t3 n3, ...) 312*0Sstevel@tonic-gate #define VARARG4(t1, n1, t2, n2, t3, n3, t4, n4) \ 313*0Sstevel@tonic-gate (t1 n1, t2 n2, t3 n3, t4 n4, ...) 314*0Sstevel@tonic-gate #define VARARG5(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5) \ 315*0Sstevel@tonic-gate (t1 n1, t2 n2, t3 n3, t4 n4, t5 n5, ...) 316*0Sstevel@tonic-gate #else 317*0Sstevel@tonic-gate #define VARARG1(type, name) (name, va_alist) type name; int va_alist 318*0Sstevel@tonic-gate #define VARARG2(t1, n1, t2, n2) (n1, n2, va_alist) t1 n1; t2 n2; int va_alist 319*0Sstevel@tonic-gate #define VARARG3(t1, n1, t2, n2, t3, n3) (n1, n2, n3, va_alist) \ 320*0Sstevel@tonic-gate t1 n1; t2 n2; t3 n3; int va_alist 321*0Sstevel@tonic-gate #define VARARG4(t1, n1, t2, n2, t3, n3, t4, n4) (n1, n2, n3, n4, va_alist) \ 322*0Sstevel@tonic-gate t1 n1; t2 n2; t3 n3; t4 n4; int va_alist 323*0Sstevel@tonic-gate #define VARARG5(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5) \ 324*0Sstevel@tonic-gate (n1, n2, n3, n4, n5, va_alist) \ 325*0Sstevel@tonic-gate t1 n1; t2 n2; t3 n3; t4 n4; t5 n5; int va_alist 326*0Sstevel@tonic-gate #endif 327*0Sstevel@tonic-gate #endif 328*0Sstevel@tonic-gate 329*0Sstevel@tonic-gate 330*0Sstevel@tonic-gate /* 331*0Sstevel@tonic-gate * MKS-specific library entry points. 332*0Sstevel@tonic-gate */ 333*0Sstevel@tonic-gate extern char *_cmdname; 334*0Sstevel@tonic-gate LEXTERN char *basename (char *); 335*0Sstevel@tonic-gate LEXTERN void crc16 (ushort *, ushort); 336*0Sstevel@tonic-gate LEXTERN void crcccitt (ushort *, ushort); 337*0Sstevel@tonic-gate LEXTERN int eprintf (const char *, ...); 338*0Sstevel@tonic-gate LEXTERN void eputs (const char *); 339*0Sstevel@tonic-gate LEXTERN pid_t fexecve (const char *, char *const *, char *const *); 340*0Sstevel@tonic-gate LEXTERN pid_t fexecvp (const char *, char *const *); 341*0Sstevel@tonic-gate LEXTERN pid_t fexecvep (const char *, char *const *, char *const *); 342*0Sstevel@tonic-gate LEXTERN int execvep (const char *, char *const *, char *const *); 343*0Sstevel@tonic-gate LEXTERN int isabsname (const char *); 344*0Sstevel@tonic-gate LEXTERN const char *m_cescape (wint_t); 345*0Sstevel@tonic-gate LEXTERN int m_escapec (char **); 346*0Sstevel@tonic-gate LEXTERN const char *m_toprint (wint_t); 347*0Sstevel@tonic-gate #if M_STTY_CC 348*0Sstevel@tonic-gate LEXTERN int m_stty_cc (cc_t* cp, char *str); 349*0Sstevel@tonic-gate #endif 350*0Sstevel@tonic-gate LEXTERN char *m_cmdname (char *); 351*0Sstevel@tonic-gate LEXTERN char *m_strmode (mode_t); 352*0Sstevel@tonic-gate LEXTERN char *m_readmode (const char *); 353*0Sstevel@tonic-gate LEXTERN char *m_readnum (long *, char *, char **, int); 354*0Sstevel@tonic-gate LEXTERN char *m_readunum (unsigned long *, char *, char **, int); 355*0Sstevel@tonic-gate LEXTERN mode_t m_getmode (mode_t); 356*0Sstevel@tonic-gate LEXTERN int m_wallow (int, const char *); 357*0Sstevel@tonic-gate LEXTERN char *m_pathcat (const char *, const char *); 358*0Sstevel@tonic-gate LEXTERN void m_sigcleanup (void (*__handler)(int __signo) ); 359*0Sstevel@tonic-gate LEXTERN void m_defaction (int __signo); 360*0Sstevel@tonic-gate LEXTERN char *m_strdup (const char *s); 361*0Sstevel@tonic-gate LEXTERN int m_stricmp (const char *, const char *); 362*0Sstevel@tonic-gate LEXTERN char *m_self (int, char *, char *); 363*0Sstevel@tonic-gate LEXTERN int m_grouplist (char *user, gid_t *gidlist[]); 364*0Sstevel@tonic-gate LEXTERN int m_setgroups (int gidsetsize, gid_t grouplist[]); 365*0Sstevel@tonic-gate LEXTERN uint m_binsrch (uint n, int (*cmp)(uint i)); 366*0Sstevel@tonic-gate LEXTERN char *m_dirname (const char*); 367*0Sstevel@tonic-gate LEXTERN char *m_confstr (int); 368*0Sstevel@tonic-gate 369*0Sstevel@tonic-gate LEXTERN void m_crcposix (ulong *, const uchar *, size_t); 370*0Sstevel@tonic-gate LEXTERN int m_setprio (int, unsigned int, int); 371*0Sstevel@tonic-gate LEXTERN int m_getprio (int, unsigned int); 372*0Sstevel@tonic-gate LEXTERN int m_incrnice (int, unsigned int, int); 373*0Sstevel@tonic-gate LEXTERN char *m_devname (dev_t); 374*0Sstevel@tonic-gate LEXTERN char *m_mountdir (const char *); 375*0Sstevel@tonic-gate LEXTERN int m_absname(char *, char *, char *, size_t); 376*0Sstevel@tonic-gate LEXTERN int m_samefile(char *, struct stat *, char *, struct stat *); 377*0Sstevel@tonic-gate 378*0Sstevel@tonic-gate /* __m_system() : alternate interface into system() */ 379*0Sstevel@tonic-gate LEXTERN int __m_system (const char *, const char *, const char *); 380*0Sstevel@tonic-gate 381*0Sstevel@tonic-gate 382*0Sstevel@tonic-gate /* conversion routines - between single byte and UNICODE (wide) strings. 383*0Sstevel@tonic-gate * These return a pointer to malloc'd memory. 384*0Sstevel@tonic-gate * It is the caller's responsiblity to free() it, if necessary 385*0Sstevel@tonic-gate * These are for use primarily on NT 386*0Sstevel@tonic-gate */ 387*0Sstevel@tonic-gate extern char *m_unicodetosb(const wchar_t*); 388*0Sstevel@tonic-gate extern wchar_t *m_sbtounicode(const char*); 389*0Sstevel@tonic-gate 390*0Sstevel@tonic-gate 391*0Sstevel@tonic-gate /* 392*0Sstevel@tonic-gate * things that could go into an "m_stdio.h" 393*0Sstevel@tonic-gate */ 394*0Sstevel@tonic-gate 395*0Sstevel@tonic-gate /* m_unlink() : alternate unlink() for use with vendor-provided 396*0Sstevel@tonic-gate * libraries that do not have a satisfactory unlink() */ 397*0Sstevel@tonic-gate #ifndef M_UNLINK 398*0Sstevel@tonic-gate #define m_unlink(s) unlink(s) 399*0Sstevel@tonic-gate #endif 400*0Sstevel@tonic-gate 401*0Sstevel@tonic-gate /* __m_popen() : alternate interface into popen() */ 402*0Sstevel@tonic-gate LEXTERN FILE *__m_popen (const char *, const char *, 403*0Sstevel@tonic-gate const char *, const char *); 404*0Sstevel@tonic-gate LEXTERN FILE *__m_popenvp (const char *mode, const char *shell, 405*0Sstevel@tonic-gate char const * const *args); 406*0Sstevel@tonic-gate 407*0Sstevel@tonic-gate #if M_TFGETC 408*0Sstevel@tonic-gate LEXTERN int m_tfgetc (FILE *fp, struct termios *tp); 409*0Sstevel@tonic-gate #else 410*0Sstevel@tonic-gate #define m_tfgetc(fp,tp) fgetc(fp) 411*0Sstevel@tonic-gate #endif 412*0Sstevel@tonic-gate 413*0Sstevel@tonic-gate /* m_fsopen() - special routine for curses */ 414*0Sstevel@tonic-gate LEXTERN FILE *m_fsopen (char *, size_t, const char *, FILE *); 415*0Sstevel@tonic-gate 416*0Sstevel@tonic-gate #ifndef M_FFLUSH_NOT_POSIX_1 417*0Sstevel@tonic-gate # define m_fflush fflush 418*0Sstevel@tonic-gate #else 419*0Sstevel@tonic-gate LEXTERN int m_fflush (FILE *); 420*0Sstevel@tonic-gate #endif 421*0Sstevel@tonic-gate 422*0Sstevel@tonic-gate /* m_fgets return values */ 423*0Sstevel@tonic-gate enum { 424*0Sstevel@tonic-gate M_FGETS_OK, /* Normal return */ 425*0Sstevel@tonic-gate M_FGETS_EOF, /* 426*0Sstevel@tonic-gate * Regular EOF (same as NULL from fgets). 427*0Sstevel@tonic-gate * Buffer is *untouched*. 428*0Sstevel@tonic-gate */ 429*0Sstevel@tonic-gate M_FGETS_SHORT, /* 430*0Sstevel@tonic-gate * Short input (buf[strlen(buf)-1] != '\n') 431*0Sstevel@tonic-gate * This is a trailing line, without a newline at the 432*0Sstevel@tonic-gate * end of the file. The buffer is valid, ending in 433*0Sstevel@tonic-gate * a \0, with no newline. The case of terminal input 434*0Sstevel@tonic-gate * ending with an EOF in the middle of the line will 435*0Sstevel@tonic-gate * restart -- typing two EOF's will result in this 436*0Sstevel@tonic-gate * case. 437*0Sstevel@tonic-gate */ 438*0Sstevel@tonic-gate M_FGETS_LONG, /* 439*0Sstevel@tonic-gate * Line too long: newline not found within len bytes 440*0Sstevel@tonic-gate * (buf[len-1] != '\n'). 441*0Sstevel@tonic-gate * At this point, while((c=getc(fp)) != '\n') ... 442*0Sstevel@tonic-gate * is a valid method to get the rest of the line. 443*0Sstevel@tonic-gate */ 444*0Sstevel@tonic-gate M_FGETS_BINARY, /* 445*0Sstevel@tonic-gate * Input contained an invalid character (e.g. \0) 446*0Sstevel@tonic-gate * Buffer contents *undefined*. 447*0Sstevel@tonic-gate */ 448*0Sstevel@tonic-gate M_FGETS_ERROR /* 449*0Sstevel@tonic-gate * A system call returned an error, errno is set. 450*0Sstevel@tonic-gate * Buffer contents *undefined*. 451*0Sstevel@tonic-gate */ 452*0Sstevel@tonic-gate }; 453*0Sstevel@tonic-gate LEXTERN int m_fgets (char *, size_t, FILE *); 454*0Sstevel@tonic-gate 455*0Sstevel@tonic-gate /* 456*0Sstevel@tonic-gate * end of things that could go into an "m_stdio.h" 457*0Sstevel@tonic-gate */ 458*0Sstevel@tonic-gate 459*0Sstevel@tonic-gate LEXTERN int m_winsize (int *, int *); 460*0Sstevel@tonic-gate LEXTERN char *m_cuserid (); 461*0Sstevel@tonic-gate 462*0Sstevel@tonic-gate /* m_ctype: generic character classification */ 463*0Sstevel@tonic-gate typedef int m_ctype_t; /* ctype property */ 464*0Sstevel@tonic-gate LEXTERN m_ctype_t m_ctype (const char *property); 465*0Sstevel@tonic-gate LEXTERN int m_isctype (int c, m_ctype_t ctype); 466*0Sstevel@tonic-gate LEXTERN char *m_readdate (char *, time_t *, int); 467*0Sstevel@tonic-gate 468*0Sstevel@tonic-gate #ifndef M_READDATE_SYSV 469*0Sstevel@tonic-gate #define M_READDATE_SYSV 0 470*0Sstevel@tonic-gate #endif 471*0Sstevel@tonic-gate #ifndef M_READDATE_BSD 472*0Sstevel@tonic-gate #define M_READDATE_BSD 1 473*0Sstevel@tonic-gate #endif 474*0Sstevel@tonic-gate 475*0Sstevel@tonic-gate #ifdef M_MALLOC 476*0Sstevel@tonic-gate LEXTERN _VOID *m_malloc (size_t size); 477*0Sstevel@tonic-gate #else 478*0Sstevel@tonic-gate # define m_malloc(size) malloc(size) 479*0Sstevel@tonic-gate #endif /*M_MALLOC*/ 480*0Sstevel@tonic-gate 481*0Sstevel@tonic-gate #ifdef M_REALLOC 482*0Sstevel@tonic-gate LEXTERN _VOID *m_realloc (void* ptr, size_t size); 483*0Sstevel@tonic-gate #else 484*0Sstevel@tonic-gate # define m_realloc realloc 485*0Sstevel@tonic-gate #endif /*M_MALLOC*/ 486*0Sstevel@tonic-gate 487*0Sstevel@tonic-gate #ifdef NAME_MAX 488*0Sstevel@tonic-gate #define m_namemax(path) NAME_MAX 489*0Sstevel@tonic-gate #else 490*0Sstevel@tonic-gate LEXTERN int m_namemax (char *path); 491*0Sstevel@tonic-gate #endif /*NAME_MAX*/ 492*0Sstevel@tonic-gate 493*0Sstevel@tonic-gate #ifdef PATH_MAX 494*0Sstevel@tonic-gate #define m_pathmax(path) PATH_MAX 495*0Sstevel@tonic-gate #else 496*0Sstevel@tonic-gate LEXTERN int m_pathmax (char *path); 497*0Sstevel@tonic-gate #endif /* PATH_MAX */ 498*0Sstevel@tonic-gate 499*0Sstevel@tonic-gate #ifdef M_DEVBIN 500*0Sstevel@tonic-gate LEXTERN int m_devbin (int fd); /* begin raw I/O transfer */ 501*0Sstevel@tonic-gate LEXTERN void m_devstd (int fd, int mode); /* end raw I/O transfer */ 502*0Sstevel@tonic-gate #else 503*0Sstevel@tonic-gate # define m_devbin(fd) 0 504*0Sstevel@tonic-gate # define m_devstd(fd, mode) 505*0Sstevel@tonic-gate #endif /*M_DEVBIN*/ 506*0Sstevel@tonic-gate 507*0Sstevel@tonic-gate #ifndef m_setbinary 508*0Sstevel@tonic-gate #define m_setbinary(fp) 509*0Sstevel@tonic-gate #endif /*m_setbinary*/ 510*0Sstevel@tonic-gate 511*0Sstevel@tonic-gate #ifndef M_PRIO_PROCESS 512*0Sstevel@tonic-gate #define M_PRIO_PROCESS 0 513*0Sstevel@tonic-gate #endif 514*0Sstevel@tonic-gate #ifndef M_PRIO_PGRP 515*0Sstevel@tonic-gate #define M_PRIO_PGRP 1 516*0Sstevel@tonic-gate #endif 517*0Sstevel@tonic-gate #ifndef M_PRIO_USER 518*0Sstevel@tonic-gate #define M_PRIO_USER 2 519*0Sstevel@tonic-gate #endif 520*0Sstevel@tonic-gate 521*0Sstevel@tonic-gate /* m_wallow type values */ 522*0Sstevel@tonic-gate #ifndef MWA_NO 523*0Sstevel@tonic-gate #define MWA_NO 0 /* Deny talk, write */ 524*0Sstevel@tonic-gate #endif 525*0Sstevel@tonic-gate #ifndef MWA_YES 526*0Sstevel@tonic-gate #define MWA_YES 1 /* Allow talk, write */ 527*0Sstevel@tonic-gate #endif 528*0Sstevel@tonic-gate #ifndef MWA_TEST 529*0Sstevel@tonic-gate #define MWA_TEST 2 /* Test for YES/NO */ 530*0Sstevel@tonic-gate #endif 531*0Sstevel@tonic-gate 532*0Sstevel@tonic-gate /* Interface for compression (m_cm_*) and decompression (m_dc_*) */ 533*0Sstevel@tonic-gate LEXTERN int m_cm_open (int (*wrtfn) (const uchar *,int), int); 534*0Sstevel@tonic-gate LEXTERN int m_cm_write (const uchar *, int); 535*0Sstevel@tonic-gate LEXTERN int m_cm_close (int); 536*0Sstevel@tonic-gate LEXTERN char *m_cm_error (void); 537*0Sstevel@tonic-gate LEXTERN int m_dc_open (ssize_t (*rdfn)(uchar *, int)); 538*0Sstevel@tonic-gate LEXTERN ssize_t m_dc_read (uchar *, size_t); 539*0Sstevel@tonic-gate LEXTERN int m_dc_close (int); 540*0Sstevel@tonic-gate LEXTERN char *m_dc_error (void); 541*0Sstevel@tonic-gate 542*0Sstevel@tonic-gate LEXTERN int m_mkpardir (char *); 543*0Sstevel@tonic-gate 544*0Sstevel@tonic-gate /* 545*0Sstevel@tonic-gate * Some UNIX routines that aren't in SVID 546*0Sstevel@tonic-gate */ 547*0Sstevel@tonic-gate LEXTERN void cfree (void *, size_t, size_t); 548*0Sstevel@tonic-gate LEXTERN void swaw (const short *, short *, int); 549*0Sstevel@tonic-gate 550*0Sstevel@tonic-gate /* Some dos routines we sometimes want from posix utilities */ 551*0Sstevel@tonic-gate LEXTERN void _uttoof (time_t, ushort *, ushort *); 552*0Sstevel@tonic-gate LEXTERN time_t _oftout (ushort, ushort); 553*0Sstevel@tonic-gate 554*0Sstevel@tonic-gate 555*0Sstevel@tonic-gate #ifndef M_SETENV 556*0Sstevel@tonic-gate #define m_setenv() environ 557*0Sstevel@tonic-gate #endif 558*0Sstevel@tonic-gate 559*0Sstevel@tonic-gate #ifdef M_NON_STATIC_GETENV 560*0Sstevel@tonic-gate #define __m_getenv getenv 561*0Sstevel@tonic-gate #else 562*0Sstevel@tonic-gate LEXTERN char *__m_getenv(char const *); /* Library safe getenv() */ 563*0Sstevel@tonic-gate #endif 564*0Sstevel@tonic-gate 565*0Sstevel@tonic-gate #ifndef M_CRON_MAILER 566*0Sstevel@tonic-gate /* 567*0Sstevel@tonic-gate * Default case: assume only POSIX.2 mailx is available. 568*0Sstevel@tonic-gate * Must be careful when cron sends output to mailx. 569*0Sstevel@tonic-gate * We must ensure that lines with leading '~' are escaped 570*0Sstevel@tonic-gate * so mailx doesn't interpret these lines 571*0Sstevel@tonic-gate * This string MUST include a trailing space character. 572*0Sstevel@tonic-gate */ 573*0Sstevel@tonic-gate #define M_CRON_MAILER "sed -e s/^~/~~/ | mailx " 574*0Sstevel@tonic-gate #endif 575*0Sstevel@tonic-gate 576*0Sstevel@tonic-gate /* 577*0Sstevel@tonic-gate * m_cp() - copy a file in an O/S specific way. See m_cp.3 578*0Sstevel@tonic-gate * for details 579*0Sstevel@tonic-gate */ 580*0Sstevel@tonic-gate 581*0Sstevel@tonic-gate /* Return codes */ 582*0Sstevel@tonic-gate #define M_CP_ERR -1 583*0Sstevel@tonic-gate #define M_CP_NOOP -2 584*0Sstevel@tonic-gate 585*0Sstevel@tonic-gate /* processing flags */ 586*0Sstevel@tonic-gate #define M_CP_PRESERVE 1 587*0Sstevel@tonic-gate 588*0Sstevel@tonic-gate /* 589*0Sstevel@tonic-gate * MKS MEMORY MANIPULATIONS: 590*0Sstevel@tonic-gate * Specific to MKS and non-portable. 591*0Sstevel@tonic-gate */ 592*0Sstevel@tonic-gate LEXTERN _VOID *membtst (const char *s, size_t m, int c); 593*0Sstevel@tonic-gate 594*0Sstevel@tonic-gate #ifdef M_LDATA 595*0Sstevel@tonic-gate #define memLchr memchr 596*0Sstevel@tonic-gate #define memSLccpy memccpy 597*0Sstevel@tonic-gate #define memLbtst membtst 598*0Sstevel@tonic-gate #define memLset memset 599*0Sstevel@tonic-gate #define memLLcpy memcpy 600*0Sstevel@tonic-gate #define memLLrlcpy memrlcpy 601*0Sstevel@tonic-gate #define memLLcmp memcmp 602*0Sstevel@tonic-gate #else 603*0Sstevel@tonic-gate /* for machines with small data models (e.g PC's - DOS, OS2) */ 604*0Sstevel@tonic-gate LEXTERN void far*memLchr (const void far*s, int c, size_t n); 605*0Sstevel@tonic-gate LEXTERN void *memSLccpy (_VOID *s1, const _VOID far*s2, int, size_t n); 606*0Sstevel@tonic-gate LEXTERN void far*memLbtst (const char far*s, size_t m, int n); 607*0Sstevel@tonic-gate LEXTERN void far*memLset (void far*s, int c, size_t n); 608*0Sstevel@tonic-gate LEXTERN void far*memLsetl (void far*p, int value, long count); 609*0Sstevel@tonic-gate LEXTERN void far*memLLcpy (void far*s1, const void far*s2, size_t n); 610*0Sstevel@tonic-gate LEXTERN void far*memLLrlcpy (void far*s1, const void far*s2, size_t); 611*0Sstevel@tonic-gate LEXTERN int memLLcmp (const void far *s1,const void far *s2,size_t n); 612*0Sstevel@tonic-gate #endif /* M_LDATA */ 613*0Sstevel@tonic-gate 614*0Sstevel@tonic-gate 615*0Sstevel@tonic-gate /* mks error handling routines */ 616*0Sstevel@tonic-gate #include <stdarg.h> 617*0Sstevel@tonic-gate LEXTERN void m_error (const char * fmt, ...); 618*0Sstevel@tonic-gate LEXTERN void m_errorexit (const char *fmt, va_list args); 619*0Sstevel@tonic-gate LEXTERN void m_errorret (const char *fmt, va_list args); 620*0Sstevel@tonic-gate LEXTERN void m_errorjmp (const char *fmt, va_list args); 621*0Sstevel@tonic-gate LEXTERN void m_errornull (const char *fmt, va_list args); 622*0Sstevel@tonic-gate LEXTERN void (*m_errorfn) (const char *fmt, va_list args); 623*0Sstevel@tonic-gate #define M_ERROR(fn) void (*m_errorfn) (const char *fmt, va_list args) = fn 624*0Sstevel@tonic-gate 625*0Sstevel@tonic-gate /* 626*0Sstevel@tonic-gate * The filesystem type and attribute routine 627*0Sstevel@tonic-gate */ 628*0Sstevel@tonic-gate #ifndef M_FSTYPE 629*0Sstevel@tonic-gate #define m_fstype(path) M_FSTYPE_POSIX 630*0Sstevel@tonic-gate #endif 631*0Sstevel@tonic-gate 632*0Sstevel@tonic-gate /* File system types */ 633*0Sstevel@tonic-gate #define M_FSTYPE_MASK 0x1 634*0Sstevel@tonic-gate #define M_FSTYPE_POSIX 0 635*0Sstevel@tonic-gate #define M_FSTYPE_FAT 1 636*0Sstevel@tonic-gate 637*0Sstevel@tonic-gate /* File system attributes */ 638*0Sstevel@tonic-gate #define M_FSATTR_NO_LEADING_DOT 0x08 639*0Sstevel@tonic-gate #define M_FSATTR_ONE_DOT 0x10 640*0Sstevel@tonic-gate #define M_FSATTR_SHORT_FILENAME 0x20 641*0Sstevel@tonic-gate #define M_FSATTR_SHORT_EXT 0x40 642*0Sstevel@tonic-gate #define M_FSATTR_LOWER_CASE 0x80 643*0Sstevel@tonic-gate 644*0Sstevel@tonic-gate /* This one should be ifdef'ed on something else */ 645*0Sstevel@tonic-gate #ifndef M_FNMATCH_DUALCASE 646*0Sstevel@tonic-gate #define m_get_original_filename_case(path) /* nil */ 647*0Sstevel@tonic-gate #endif 648*0Sstevel@tonic-gate 649*0Sstevel@tonic-gate /* 650*0Sstevel@tonic-gate * m_tempname() generates a filename for a temp file using "code" 651*0Sstevel@tonic-gate * in the name. 652*0Sstevel@tonic-gate */ 653*0Sstevel@tonic-gate #ifndef M_TEMPNAME 654*0Sstevel@tonic-gate #define m_tempname(code) tempnam(__m_getenv("TMPDIR"), (code)) 655*0Sstevel@tonic-gate #else 656*0Sstevel@tonic-gate char *m_tempname(char const *code); 657*0Sstevel@tonic-gate #endif 658*0Sstevel@tonic-gate 659*0Sstevel@tonic-gate /* 660*0Sstevel@tonic-gate * __m_getopt() alternate "stateless" entry into getopt(). 661*0Sstevel@tonic-gate */ 662*0Sstevel@tonic-gate 663*0Sstevel@tonic-gate struct getopt_state { 664*0Sstevel@tonic-gate char *optarg; /* Argument */ 665*0Sstevel@tonic-gate int optind; /* Index into argv */ 666*0Sstevel@tonic-gate int opterr; /* Print error message */ 667*0Sstevel@tonic-gate int optopt; /* Invalid option */ 668*0Sstevel@tonic-gate int index; /* argv[optind] index */ 669*0Sstevel@tonic-gate #ifdef M_I18N_MB 670*0Sstevel@tonic-gate mbstate_t st; /* State of argv[optind][index] */ 671*0Sstevel@tonic-gate #endif 672*0Sstevel@tonic-gate }; 673*0Sstevel@tonic-gate 674*0Sstevel@tonic-gate int __m_getopt(int argc, char * const *argv, char const *optstring, 675*0Sstevel@tonic-gate struct getopt_state *state); 676*0Sstevel@tonic-gate 677*0Sstevel@tonic-gate 678*0Sstevel@tonic-gate #ifdef M_MKSEXTRA_H 679*0Sstevel@tonic-gate /* Any overrides etcetera for a particular system can go in here */ 680*0Sstevel@tonic-gate #include <mksextra.h> 681*0Sstevel@tonic-gate #endif /* M_MKSEXTRA_H */ 682*0Sstevel@tonic-gate 683*0Sstevel@tonic-gate #endif /* __M_MKS_H__ */ 684