17c478bd9Sstevel@tonic-gate /* 2*6c02b4a4Smuffin * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 37c478bd9Sstevel@tonic-gate * Use is subject to license terms. 47c478bd9Sstevel@tonic-gate */ 57c478bd9Sstevel@tonic-gate 67c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 77c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 87c478bd9Sstevel@tonic-gate 97c478bd9Sstevel@tonic-gate /* 107c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California. 117c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley Software License Agreement 127c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 137c478bd9Sstevel@tonic-gate */ 147c478bd9Sstevel@tonic-gate 157c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 167c478bd9Sstevel@tonic-gate 177c478bd9Sstevel@tonic-gate #include "sh.h" 187c478bd9Sstevel@tonic-gate #include "sh.tconst.h" 197c478bd9Sstevel@tonic-gate #include <fcntl.h> 207c478bd9Sstevel@tonic-gate #include <unistd.h> 217c478bd9Sstevel@tonic-gate 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * C Shell 247c478bd9Sstevel@tonic-gate */ 25*6c02b4a4Smuffin tchar **blkcat(tchar **, tchar **); 26*6c02b4a4Smuffin tchar **blkend(tchar **); 277c478bd9Sstevel@tonic-gate 28*6c02b4a4Smuffin int 29*6c02b4a4Smuffin any(int c, tchar *s) 307c478bd9Sstevel@tonic-gate { 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate while (s && *s) 337c478bd9Sstevel@tonic-gate if (*s++ == c) 347c478bd9Sstevel@tonic-gate return (1); 357c478bd9Sstevel@tonic-gate return (0); 367c478bd9Sstevel@tonic-gate } 377c478bd9Sstevel@tonic-gate 38*6c02b4a4Smuffin int 39*6c02b4a4Smuffin onlyread(tchar *cp) 407c478bd9Sstevel@tonic-gate { 417c478bd9Sstevel@tonic-gate extern char end[]; 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate return ((char *)cp < end); 447c478bd9Sstevel@tonic-gate } 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* 487c478bd9Sstevel@tonic-gate * WARNING: changes here also need to occur in the XFREE macro in sh.h. 497c478bd9Sstevel@tonic-gate */ 50*6c02b4a4Smuffin void 51*6c02b4a4Smuffin xfree(char *cp) 527c478bd9Sstevel@tonic-gate { 537c478bd9Sstevel@tonic-gate extern char end[]; 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #if defined(sparc) 567c478bd9Sstevel@tonic-gate if ((char *)cp >= end && (char *)cp < (char *)&cp) 577c478bd9Sstevel@tonic-gate free(cp); 587c478bd9Sstevel@tonic-gate #elif defined(i386) 597c478bd9Sstevel@tonic-gate if ((char *)cp >= end) 607c478bd9Sstevel@tonic-gate free(cp); 617c478bd9Sstevel@tonic-gate #else 627c478bd9Sstevel@tonic-gate #error xfree function is machine dependent and no machine type is recognized 637c478bd9Sstevel@tonic-gate #endif 647c478bd9Sstevel@tonic-gate } 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate tchar * 67*6c02b4a4Smuffin savestr(tchar *s) 687c478bd9Sstevel@tonic-gate { 697c478bd9Sstevel@tonic-gate tchar *n; 70*6c02b4a4Smuffin tchar *p; 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate if (s == 0) 737c478bd9Sstevel@tonic-gate s = S_ /* "" */; 747c478bd9Sstevel@tonic-gate #ifndef m32 757c478bd9Sstevel@tonic-gate for (p = s; *p++; ) 767c478bd9Sstevel@tonic-gate ; 777c478bd9Sstevel@tonic-gate n = p = (tchar *)xalloc((unsigned) (p - s)*sizeof (tchar)); 787c478bd9Sstevel@tonic-gate while (*p++ = *s++) 797c478bd9Sstevel@tonic-gate ; 807c478bd9Sstevel@tonic-gate return (n); 817c478bd9Sstevel@tonic-gate #else 827c478bd9Sstevel@tonic-gate p = (tchar *) xalloc((strlen_(s) + 1)*sizeof (tchar)); 837c478bd9Sstevel@tonic-gate strcpy_(p, s); 847c478bd9Sstevel@tonic-gate return (p); 857c478bd9Sstevel@tonic-gate #endif 867c478bd9Sstevel@tonic-gate } 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate void * 89*6c02b4a4Smuffin calloc(size_t i, size_t j) 907c478bd9Sstevel@tonic-gate { 91*6c02b4a4Smuffin char *cp; 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate i *= j; 947c478bd9Sstevel@tonic-gate cp = (char *)xalloc(i); 957c478bd9Sstevel@tonic-gate bzero(cp, (int)i); 967c478bd9Sstevel@tonic-gate return (cp); 977c478bd9Sstevel@tonic-gate } 987c478bd9Sstevel@tonic-gate 99*6c02b4a4Smuffin int 100*6c02b4a4Smuffin nomem(unsigned i) 1017c478bd9Sstevel@tonic-gate { 1027c478bd9Sstevel@tonic-gate #ifdef debug 1037c478bd9Sstevel@tonic-gate static tchar *av[2] = {0, 0}; 1047c478bd9Sstevel@tonic-gate #endif 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate child++; 1077c478bd9Sstevel@tonic-gate #ifndef debug 1087c478bd9Sstevel@tonic-gate error("Out of memory"); 1097c478bd9Sstevel@tonic-gate #ifdef lint 1107c478bd9Sstevel@tonic-gate i = i; 1117c478bd9Sstevel@tonic-gate #endif 1127c478bd9Sstevel@tonic-gate #else 1137c478bd9Sstevel@tonic-gate showall(av); 1147c478bd9Sstevel@tonic-gate printf("i=%d: Out of memory\n", i); 1157c478bd9Sstevel@tonic-gate chdir("/usr/bill/cshcore"); 1167c478bd9Sstevel@tonic-gate abort(); 1177c478bd9Sstevel@tonic-gate #endif 1187c478bd9Sstevel@tonic-gate return (0); /* fool lint */ 1197c478bd9Sstevel@tonic-gate } 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate tchar ** 122*6c02b4a4Smuffin blkend(tchar **up) 1237c478bd9Sstevel@tonic-gate { 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate while (*up) 1267c478bd9Sstevel@tonic-gate up++; 1277c478bd9Sstevel@tonic-gate return (up); 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate 130*6c02b4a4Smuffin void 131*6c02b4a4Smuffin blkpr(tchar **av) 1327c478bd9Sstevel@tonic-gate { 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate for (; *av; av++) { 1357c478bd9Sstevel@tonic-gate printf("%t", *av); 1367c478bd9Sstevel@tonic-gate if (av[1]) 1377c478bd9Sstevel@tonic-gate printf(" "); 1387c478bd9Sstevel@tonic-gate } 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate 141*6c02b4a4Smuffin int 142*6c02b4a4Smuffin blklen(tchar **av) 1437c478bd9Sstevel@tonic-gate { 144*6c02b4a4Smuffin int i = 0; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate while (*av++) 1477c478bd9Sstevel@tonic-gate i++; 1487c478bd9Sstevel@tonic-gate return (i); 1497c478bd9Sstevel@tonic-gate } 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate tchar ** 152*6c02b4a4Smuffin blkcpy(tchar **oav, tchar **bv) 1537c478bd9Sstevel@tonic-gate { 154*6c02b4a4Smuffin tchar **av = oav; 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate while (*av++ = *bv++) 1577c478bd9Sstevel@tonic-gate continue; 1587c478bd9Sstevel@tonic-gate return (oav); 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate tchar ** 162*6c02b4a4Smuffin blkcat(tchar **up, tchar **vp) 1637c478bd9Sstevel@tonic-gate { 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate (void) blkcpy(blkend(up), vp); 1667c478bd9Sstevel@tonic-gate return (up); 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate 169*6c02b4a4Smuffin void 170*6c02b4a4Smuffin blkfree(tchar **av0) 1717c478bd9Sstevel@tonic-gate { 172*6c02b4a4Smuffin tchar **av = av0; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate for (; *av; av++) 1757c478bd9Sstevel@tonic-gate XFREE(*av) 1767c478bd9Sstevel@tonic-gate XFREE((tchar *)av0) 1777c478bd9Sstevel@tonic-gate } 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate tchar ** 180*6c02b4a4Smuffin saveblk(tchar **v) 1817c478bd9Sstevel@tonic-gate { 182*6c02b4a4Smuffin tchar **newv = 1837c478bd9Sstevel@tonic-gate (tchar **) calloc((unsigned) (blklen(v) + 1), 1847c478bd9Sstevel@tonic-gate sizeof (tchar **)); 1857c478bd9Sstevel@tonic-gate tchar **onewv = newv; 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate while (*v) 1887c478bd9Sstevel@tonic-gate *newv++ = savestr(*v++); 1897c478bd9Sstevel@tonic-gate return (onewv); 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate tchar * 193*6c02b4a4Smuffin strspl(tchar *cp, tchar *dp) 1947c478bd9Sstevel@tonic-gate { 1957c478bd9Sstevel@tonic-gate tchar *ep; 196*6c02b4a4Smuffin tchar *p, *q; 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate #ifndef m32 1997c478bd9Sstevel@tonic-gate for (p = cp; *p++; ) 2007c478bd9Sstevel@tonic-gate ; 2017c478bd9Sstevel@tonic-gate for (q = dp; *q++; ) 2027c478bd9Sstevel@tonic-gate ; 2037c478bd9Sstevel@tonic-gate ep = (tchar *) xalloc((unsigned) (((p - cp) + 2047c478bd9Sstevel@tonic-gate (q - dp) - 1))*sizeof (tchar)); 2057c478bd9Sstevel@tonic-gate for (p = ep, q = cp; *p++ = *q++; ) 2067c478bd9Sstevel@tonic-gate ; 2077c478bd9Sstevel@tonic-gate for (p--, q = dp; *p++ = *q++; ) 2087c478bd9Sstevel@tonic-gate ; 2097c478bd9Sstevel@tonic-gate #else 2107c478bd9Sstevel@tonic-gate int len1 = strlen_(cp); 2117c478bd9Sstevel@tonic-gate int len2 = strlen_(dp); 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate ep = (tchar *)xalloc((unsigned) (len1 + len2 + 1)*sizeof (tchar)); 2147c478bd9Sstevel@tonic-gate strcpy_(ep, cp); 2157c478bd9Sstevel@tonic-gate strcat_(ep, dp); 2167c478bd9Sstevel@tonic-gate #endif 2177c478bd9Sstevel@tonic-gate return (ep); 2187c478bd9Sstevel@tonic-gate } 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate tchar ** 221*6c02b4a4Smuffin blkspl(tchar **up, tchar **vp) 2227c478bd9Sstevel@tonic-gate { 223*6c02b4a4Smuffin tchar **wp = 2247c478bd9Sstevel@tonic-gate (tchar **) calloc((unsigned) (blklen(up) + blklen(vp) + 1), 2257c478bd9Sstevel@tonic-gate sizeof (tchar **)); 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate (void) blkcpy(wp, up); 2287c478bd9Sstevel@tonic-gate return (blkcat(wp, vp)); 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate 231*6c02b4a4Smuffin int 232*6c02b4a4Smuffin lastchr(tchar *cp) 2337c478bd9Sstevel@tonic-gate { 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate if (!*cp) 2367c478bd9Sstevel@tonic-gate return (0); 2377c478bd9Sstevel@tonic-gate while (cp[1]) 2387c478bd9Sstevel@tonic-gate cp++; 2397c478bd9Sstevel@tonic-gate return (*cp); 2407c478bd9Sstevel@tonic-gate } 2417c478bd9Sstevel@tonic-gate 242*6c02b4a4Smuffin void 243*6c02b4a4Smuffin donefds(void) 2447c478bd9Sstevel@tonic-gate { 2457c478bd9Sstevel@tonic-gate (void) close(0); 2467c478bd9Sstevel@tonic-gate (void) close(1); 2477c478bd9Sstevel@tonic-gate (void) close(2); 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate /* 2507c478bd9Sstevel@tonic-gate * To avoid NIS+ functions to get hold of 0/1/2, 2517c478bd9Sstevel@tonic-gate * use descriptor 0, and dup it to 1 and 2. 2527c478bd9Sstevel@tonic-gate */ 2537c478bd9Sstevel@tonic-gate open("/dev/null", 0); 2547c478bd9Sstevel@tonic-gate dup(0); dup(0); 2557c478bd9Sstevel@tonic-gate didfds = 0; 2567c478bd9Sstevel@tonic-gate } 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate /* 2597c478bd9Sstevel@tonic-gate * Move descriptor i to j. 2607c478bd9Sstevel@tonic-gate * If j is -1 then we just want to get i to a safe place, 2617c478bd9Sstevel@tonic-gate * i.e. to a unit > 2. This also happens in dcopy. 2627c478bd9Sstevel@tonic-gate */ 263*6c02b4a4Smuffin int 264*6c02b4a4Smuffin dmove(int i, int j) 2657c478bd9Sstevel@tonic-gate { 2667c478bd9Sstevel@tonic-gate int fd; 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate if (i == j || i < 0) 2697c478bd9Sstevel@tonic-gate return (i); 2707c478bd9Sstevel@tonic-gate if (j >= 0) { 2717c478bd9Sstevel@tonic-gate fd = dup2(i, j); 2727c478bd9Sstevel@tonic-gate if (fd != -1) 2737c478bd9Sstevel@tonic-gate setfd(fd); 2747c478bd9Sstevel@tonic-gate } else 2757c478bd9Sstevel@tonic-gate j = dcopy(i, j); 2767c478bd9Sstevel@tonic-gate if (j != i) { 2777c478bd9Sstevel@tonic-gate (void) close(i); 2787c478bd9Sstevel@tonic-gate unsetfd(i); 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate return (j); 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate 283*6c02b4a4Smuffin int 284*6c02b4a4Smuffin dcopy(int i, int j) 2857c478bd9Sstevel@tonic-gate { 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate int fd; 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate if (i == j || i < 0 || j < 0 && i > 2) 2907c478bd9Sstevel@tonic-gate return (i); 2917c478bd9Sstevel@tonic-gate if (j >= 0) { 2927c478bd9Sstevel@tonic-gate fd = dup2(i, j); 2937c478bd9Sstevel@tonic-gate if (fd != -1) 2947c478bd9Sstevel@tonic-gate setfd(fd); 2957c478bd9Sstevel@tonic-gate return (j); 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate (void) close(j); 2987c478bd9Sstevel@tonic-gate unsetfd(j); 2997c478bd9Sstevel@tonic-gate return (renum(i, j)); 3007c478bd9Sstevel@tonic-gate } 3017c478bd9Sstevel@tonic-gate 302*6c02b4a4Smuffin int 303*6c02b4a4Smuffin renum(int i, int j) 3047c478bd9Sstevel@tonic-gate { 305*6c02b4a4Smuffin int k = dup(i); 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate if (k < 0) 3087c478bd9Sstevel@tonic-gate return (-1); 3097c478bd9Sstevel@tonic-gate if (j == -1 && k > 2) { 3107c478bd9Sstevel@tonic-gate setfd(k); 3117c478bd9Sstevel@tonic-gate return (k); 3127c478bd9Sstevel@tonic-gate } 3137c478bd9Sstevel@tonic-gate if (k != j) { 3147c478bd9Sstevel@tonic-gate j = renum(k, j); 3157c478bd9Sstevel@tonic-gate (void) close(k); /* no need ofr unsetfd() */ 3167c478bd9Sstevel@tonic-gate return (j); 3177c478bd9Sstevel@tonic-gate } 3187c478bd9Sstevel@tonic-gate return (k); 3197c478bd9Sstevel@tonic-gate } 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate #ifndef copy 322*6c02b4a4Smuffin void 323*6c02b4a4Smuffin copy(tchar *to, tchar *from, int size) 3247c478bd9Sstevel@tonic-gate { 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate if (size) 3277c478bd9Sstevel@tonic-gate do 3287c478bd9Sstevel@tonic-gate *to++ = *from++; 3297c478bd9Sstevel@tonic-gate while (--size != 0); 3307c478bd9Sstevel@tonic-gate } 3317c478bd9Sstevel@tonic-gate #endif 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate /* 3347c478bd9Sstevel@tonic-gate * Left shift a command argument list, discarding 3357c478bd9Sstevel@tonic-gate * the first c arguments. Used in "shift" commands 3367c478bd9Sstevel@tonic-gate * as well as by commands like "repeat". 3377c478bd9Sstevel@tonic-gate */ 338*6c02b4a4Smuffin void 339*6c02b4a4Smuffin lshift(tchar **v, int c) 3407c478bd9Sstevel@tonic-gate { 341*6c02b4a4Smuffin tchar **u = v; 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate while (*u && --c >= 0) 344*6c02b4a4Smuffin xfree((char *)*u++); 3457c478bd9Sstevel@tonic-gate (void) blkcpy(v, u); 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate 348*6c02b4a4Smuffin int 349*6c02b4a4Smuffin number(tchar *cp) 3507c478bd9Sstevel@tonic-gate { 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate if (*cp == '-') { 3537c478bd9Sstevel@tonic-gate cp++; 3547c478bd9Sstevel@tonic-gate if (!digit(*cp++)) 3557c478bd9Sstevel@tonic-gate return (0); 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate while (*cp && digit(*cp)) 3587c478bd9Sstevel@tonic-gate cp++; 3597c478bd9Sstevel@tonic-gate return (*cp == 0); 3607c478bd9Sstevel@tonic-gate } 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate tchar ** 363*6c02b4a4Smuffin copyblk(tchar **v) 3647c478bd9Sstevel@tonic-gate { 365*6c02b4a4Smuffin tchar **nv = 3667c478bd9Sstevel@tonic-gate (tchar **) calloc((unsigned) (blklen(v) + 1), 3677c478bd9Sstevel@tonic-gate sizeof (tchar **)); 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate return (blkcpy(nv, v)); 3707c478bd9Sstevel@tonic-gate } 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate tchar * 373*6c02b4a4Smuffin strend(tchar *cp) 3747c478bd9Sstevel@tonic-gate { 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate while (*cp) 3777c478bd9Sstevel@tonic-gate cp++; 3787c478bd9Sstevel@tonic-gate return (cp); 3797c478bd9Sstevel@tonic-gate } 3807c478bd9Sstevel@tonic-gate 3817c478bd9Sstevel@tonic-gate tchar * 382*6c02b4a4Smuffin strip(tchar *cp) 3837c478bd9Sstevel@tonic-gate { 384*6c02b4a4Smuffin tchar *dp = cp; 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate while (*dp++ &= TRIM) 3877c478bd9Sstevel@tonic-gate continue; 3887c478bd9Sstevel@tonic-gate return (cp); 3897c478bd9Sstevel@tonic-gate } 3907c478bd9Sstevel@tonic-gate 391*6c02b4a4Smuffin void 392*6c02b4a4Smuffin udvar(tchar *name) 3937c478bd9Sstevel@tonic-gate { 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate setname(name); 3967c478bd9Sstevel@tonic-gate bferr("Undefined variable"); 3977c478bd9Sstevel@tonic-gate } 3987c478bd9Sstevel@tonic-gate 399*6c02b4a4Smuffin int 400*6c02b4a4Smuffin prefix(tchar *sub, tchar *str) 4017c478bd9Sstevel@tonic-gate { 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate for (;;) { 4047c478bd9Sstevel@tonic-gate if (*sub == 0) 4057c478bd9Sstevel@tonic-gate return (1); 4067c478bd9Sstevel@tonic-gate if (*str == 0) 4077c478bd9Sstevel@tonic-gate return (0); 4087c478bd9Sstevel@tonic-gate if (*sub++ != *str++) 4097c478bd9Sstevel@tonic-gate return (0); 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate } 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate /* 4147c478bd9Sstevel@tonic-gate * blk*_ routines 4157c478bd9Sstevel@tonic-gate */ 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate char ** 418*6c02b4a4Smuffin blkend_(char **up) 4197c478bd9Sstevel@tonic-gate { 4207c478bd9Sstevel@tonic-gate 4217c478bd9Sstevel@tonic-gate while (*up) 4227c478bd9Sstevel@tonic-gate up++; 4237c478bd9Sstevel@tonic-gate return (up); 4247c478bd9Sstevel@tonic-gate } 4257c478bd9Sstevel@tonic-gate 426*6c02b4a4Smuffin int 427*6c02b4a4Smuffin blklen_(char **av) 4287c478bd9Sstevel@tonic-gate { 429*6c02b4a4Smuffin int i = 0; 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate while (*av++) 4327c478bd9Sstevel@tonic-gate i++; 4337c478bd9Sstevel@tonic-gate return (i); 4347c478bd9Sstevel@tonic-gate } 4357c478bd9Sstevel@tonic-gate 4367c478bd9Sstevel@tonic-gate char ** 437*6c02b4a4Smuffin blkcpy_(char **oav, char **bv) 4387c478bd9Sstevel@tonic-gate { 439*6c02b4a4Smuffin char **av = oav; 4407c478bd9Sstevel@tonic-gate 4417c478bd9Sstevel@tonic-gate while (*av++ = *bv++) 4427c478bd9Sstevel@tonic-gate continue; 4437c478bd9Sstevel@tonic-gate return (oav); 4447c478bd9Sstevel@tonic-gate } 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate char ** 447*6c02b4a4Smuffin blkcat_(char **up, char **vp) 4487c478bd9Sstevel@tonic-gate { 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate (void) blkcpy_(blkend_(up), vp); 4517c478bd9Sstevel@tonic-gate return (up); 4527c478bd9Sstevel@tonic-gate } 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate char ** 455*6c02b4a4Smuffin blkspl_(char **up, char **vp) 4567c478bd9Sstevel@tonic-gate { 457*6c02b4a4Smuffin char **wp = 4587c478bd9Sstevel@tonic-gate (char **) calloc((unsigned) (blklen_(up) + blklen_(vp) + 1), 4597c478bd9Sstevel@tonic-gate sizeof (char **)); 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate (void) blkcpy_(wp, up); 4627c478bd9Sstevel@tonic-gate return (blkcat_(wp, vp)); 4637c478bd9Sstevel@tonic-gate } 464