1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate /* 27*7c478bd9Sstevel@tonic-gate * Copyright (c) 1996, 1997 by Sun Microsystems, Inc. 28*7c478bd9Sstevel@tonic-gate * All rights reserved. 29*7c478bd9Sstevel@tonic-gate */ 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.12.6.1 */ 32*7c478bd9Sstevel@tonic-gate /* 33*7c478bd9Sstevel@tonic-gate * UNIX shell 34*7c478bd9Sstevel@tonic-gate * 35*7c478bd9Sstevel@tonic-gate */ 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #include "defs.h" 38*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 39*7c478bd9Sstevel@tonic-gate #include <locale.h> 40*7c478bd9Sstevel@tonic-gate #include <wctype.h> /* iswprint() */ 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #define BUFLEN 256 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate unsigned char numbuf[21]; 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate static unsigned char buffer[BUFLEN]; 47*7c478bd9Sstevel@tonic-gate static unsigned char *bufp = buffer; 48*7c478bd9Sstevel@tonic-gate static int index = 0; 49*7c478bd9Sstevel@tonic-gate static int buffd = 1; 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate void prc_buff(unsigned char c); 52*7c478bd9Sstevel@tonic-gate void prs_buff(unsigned char *s); 53*7c478bd9Sstevel@tonic-gate void prn_buff(int n); 54*7c478bd9Sstevel@tonic-gate void prs_cntl(unsigned char *s); 55*7c478bd9Sstevel@tonic-gate void prs(unsigned char *as); 56*7c478bd9Sstevel@tonic-gate void itos(int n); 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate /* 59*7c478bd9Sstevel@tonic-gate * printing and io conversion 60*7c478bd9Sstevel@tonic-gate */ 61*7c478bd9Sstevel@tonic-gate void 62*7c478bd9Sstevel@tonic-gate prp() 63*7c478bd9Sstevel@tonic-gate { 64*7c478bd9Sstevel@tonic-gate if ((flags & prompt) == 0 && cmdadr) { 65*7c478bd9Sstevel@tonic-gate prs_cntl(cmdadr); 66*7c478bd9Sstevel@tonic-gate prs((unsigned char *)colon); 67*7c478bd9Sstevel@tonic-gate } 68*7c478bd9Sstevel@tonic-gate } 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate void 71*7c478bd9Sstevel@tonic-gate prs(unsigned char *as) 72*7c478bd9Sstevel@tonic-gate { 73*7c478bd9Sstevel@tonic-gate char *s; 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate if ((s = gettext((char *)as)) != 0) { 76*7c478bd9Sstevel@tonic-gate write(output, s, length(s) - 1); 77*7c478bd9Sstevel@tonic-gate } 78*7c478bd9Sstevel@tonic-gate } 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate void 81*7c478bd9Sstevel@tonic-gate prc(unsigned char c) 82*7c478bd9Sstevel@tonic-gate { 83*7c478bd9Sstevel@tonic-gate if (c) { 84*7c478bd9Sstevel@tonic-gate write(output, &c, 1); 85*7c478bd9Sstevel@tonic-gate } 86*7c478bd9Sstevel@tonic-gate } 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate void 89*7c478bd9Sstevel@tonic-gate prwc(wchar_t c) 90*7c478bd9Sstevel@tonic-gate { 91*7c478bd9Sstevel@tonic-gate char mb[MB_LEN_MAX + 1]; 92*7c478bd9Sstevel@tonic-gate int len; 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate if (c == 0) { 95*7c478bd9Sstevel@tonic-gate return; 96*7c478bd9Sstevel@tonic-gate } 97*7c478bd9Sstevel@tonic-gate if ((len = wctomb(mb, c)) < 0) { 98*7c478bd9Sstevel@tonic-gate mb[0] = (unsigned char)c; 99*7c478bd9Sstevel@tonic-gate len = 1; 100*7c478bd9Sstevel@tonic-gate } 101*7c478bd9Sstevel@tonic-gate write(output, mb, len); 102*7c478bd9Sstevel@tonic-gate } 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate void 105*7c478bd9Sstevel@tonic-gate prt(long t) 106*7c478bd9Sstevel@tonic-gate { 107*7c478bd9Sstevel@tonic-gate int hr, min, sec; 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate t += HZ / 2; 110*7c478bd9Sstevel@tonic-gate t /= HZ; 111*7c478bd9Sstevel@tonic-gate sec = t % 60; 112*7c478bd9Sstevel@tonic-gate t /= 60; 113*7c478bd9Sstevel@tonic-gate min = t % 60; 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate if ((hr = t / 60) != 0) { 116*7c478bd9Sstevel@tonic-gate prn_buff(hr); 117*7c478bd9Sstevel@tonic-gate prc_buff('h'); 118*7c478bd9Sstevel@tonic-gate } 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate prn_buff(min); 121*7c478bd9Sstevel@tonic-gate prc_buff('m'); 122*7c478bd9Sstevel@tonic-gate prn_buff(sec); 123*7c478bd9Sstevel@tonic-gate prc_buff('s'); 124*7c478bd9Sstevel@tonic-gate } 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate void 127*7c478bd9Sstevel@tonic-gate prn(int n) 128*7c478bd9Sstevel@tonic-gate { 129*7c478bd9Sstevel@tonic-gate itos(n); 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate prs(numbuf); 132*7c478bd9Sstevel@tonic-gate } 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate void 135*7c478bd9Sstevel@tonic-gate itos(int n) 136*7c478bd9Sstevel@tonic-gate { 137*7c478bd9Sstevel@tonic-gate unsigned char buf[21]; 138*7c478bd9Sstevel@tonic-gate unsigned char *abuf = &buf[20]; 139*7c478bd9Sstevel@tonic-gate int d; 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate *--abuf = (unsigned char)'\0'; 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate do { 144*7c478bd9Sstevel@tonic-gate *--abuf = (unsigned char)('0' + n - 10 * (d = n / 10)); 145*7c478bd9Sstevel@tonic-gate } while ((n = d) != 0); 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate strncpy(numbuf, abuf, sizeof (numbuf)); 148*7c478bd9Sstevel@tonic-gate } 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate int 151*7c478bd9Sstevel@tonic-gate stoi(unsigned char *icp) 152*7c478bd9Sstevel@tonic-gate { 153*7c478bd9Sstevel@tonic-gate unsigned char *cp = icp; 154*7c478bd9Sstevel@tonic-gate int r = 0; 155*7c478bd9Sstevel@tonic-gate unsigned char c; 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate while ((c = *cp, digit(c)) && c && r >= 0) { 158*7c478bd9Sstevel@tonic-gate r = r * 10 + c - '0'; 159*7c478bd9Sstevel@tonic-gate cp++; 160*7c478bd9Sstevel@tonic-gate } 161*7c478bd9Sstevel@tonic-gate if (r < 0 || cp == icp) { 162*7c478bd9Sstevel@tonic-gate failed(icp, badnum); 163*7c478bd9Sstevel@tonic-gate } else { 164*7c478bd9Sstevel@tonic-gate return (r); 165*7c478bd9Sstevel@tonic-gate } 166*7c478bd9Sstevel@tonic-gate } 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate int 169*7c478bd9Sstevel@tonic-gate ltos(long n) 170*7c478bd9Sstevel@tonic-gate { 171*7c478bd9Sstevel@tonic-gate int i; 172*7c478bd9Sstevel@tonic-gate 173*7c478bd9Sstevel@tonic-gate numbuf[20] = '\0'; 174*7c478bd9Sstevel@tonic-gate for (i = 19; i >= 0; i--) { 175*7c478bd9Sstevel@tonic-gate numbuf[i] = n % 10 + '0'; 176*7c478bd9Sstevel@tonic-gate if ((n /= 10) == 0) { 177*7c478bd9Sstevel@tonic-gate break; 178*7c478bd9Sstevel@tonic-gate } 179*7c478bd9Sstevel@tonic-gate } 180*7c478bd9Sstevel@tonic-gate return (i); 181*7c478bd9Sstevel@tonic-gate } 182*7c478bd9Sstevel@tonic-gate 183*7c478bd9Sstevel@tonic-gate void 184*7c478bd9Sstevel@tonic-gate prl(long n) 185*7c478bd9Sstevel@tonic-gate { 186*7c478bd9Sstevel@tonic-gate int i; 187*7c478bd9Sstevel@tonic-gate i = ltos(n); 188*7c478bd9Sstevel@tonic-gate prs_buff(&numbuf[i]); 189*7c478bd9Sstevel@tonic-gate } 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate int 193*7c478bd9Sstevel@tonic-gate ulltos(u_longlong_t n) 194*7c478bd9Sstevel@tonic-gate { 195*7c478bd9Sstevel@tonic-gate int i; 196*7c478bd9Sstevel@tonic-gate 197*7c478bd9Sstevel@tonic-gate /* The max unsigned long long is 20 characters (+1 for '\0') */ 198*7c478bd9Sstevel@tonic-gate numbuf[20] = '\0'; 199*7c478bd9Sstevel@tonic-gate for (i = 19; i >= 0; i--) { 200*7c478bd9Sstevel@tonic-gate numbuf[i] = n % 10 + '0'; 201*7c478bd9Sstevel@tonic-gate if ((n /= 10) == 0) { 202*7c478bd9Sstevel@tonic-gate break; 203*7c478bd9Sstevel@tonic-gate } 204*7c478bd9Sstevel@tonic-gate } 205*7c478bd9Sstevel@tonic-gate return (i); 206*7c478bd9Sstevel@tonic-gate } 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate void 209*7c478bd9Sstevel@tonic-gate prull(u_longlong_t n) 210*7c478bd9Sstevel@tonic-gate { 211*7c478bd9Sstevel@tonic-gate int i; 212*7c478bd9Sstevel@tonic-gate i = ulltos(n); 213*7c478bd9Sstevel@tonic-gate prs_buff(&numbuf[i]); 214*7c478bd9Sstevel@tonic-gate } 215*7c478bd9Sstevel@tonic-gate 216*7c478bd9Sstevel@tonic-gate void 217*7c478bd9Sstevel@tonic-gate flushb() 218*7c478bd9Sstevel@tonic-gate { 219*7c478bd9Sstevel@tonic-gate if (index) { 220*7c478bd9Sstevel@tonic-gate bufp[index] = '\0'; 221*7c478bd9Sstevel@tonic-gate write(buffd, bufp, length(bufp) - 1); 222*7c478bd9Sstevel@tonic-gate index = 0; 223*7c478bd9Sstevel@tonic-gate } 224*7c478bd9Sstevel@tonic-gate } 225*7c478bd9Sstevel@tonic-gate 226*7c478bd9Sstevel@tonic-gate void 227*7c478bd9Sstevel@tonic-gate prc_buff(unsigned char c) 228*7c478bd9Sstevel@tonic-gate { 229*7c478bd9Sstevel@tonic-gate if (c) { 230*7c478bd9Sstevel@tonic-gate if (buffd != -1 && index + 1 >= BUFLEN) { 231*7c478bd9Sstevel@tonic-gate flushb(); 232*7c478bd9Sstevel@tonic-gate } 233*7c478bd9Sstevel@tonic-gate 234*7c478bd9Sstevel@tonic-gate bufp[index++] = c; 235*7c478bd9Sstevel@tonic-gate } else { 236*7c478bd9Sstevel@tonic-gate flushb(); 237*7c478bd9Sstevel@tonic-gate write(buffd, &c, 1); 238*7c478bd9Sstevel@tonic-gate } 239*7c478bd9Sstevel@tonic-gate } 240*7c478bd9Sstevel@tonic-gate 241*7c478bd9Sstevel@tonic-gate void 242*7c478bd9Sstevel@tonic-gate prs_buff(unsigned char *s) 243*7c478bd9Sstevel@tonic-gate { 244*7c478bd9Sstevel@tonic-gate int len = length(gettext((char *)s)) - 1; 245*7c478bd9Sstevel@tonic-gate 246*7c478bd9Sstevel@tonic-gate if (buffd != -1 && index + len >= BUFLEN) { 247*7c478bd9Sstevel@tonic-gate flushb(); 248*7c478bd9Sstevel@tonic-gate } 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate if (buffd != -1 && len >= BUFLEN) { 251*7c478bd9Sstevel@tonic-gate write(buffd, gettext((char *)s), len); 252*7c478bd9Sstevel@tonic-gate } else { 253*7c478bd9Sstevel@tonic-gate movstr(gettext((char *)s), &bufp[index]); 254*7c478bd9Sstevel@tonic-gate index += len; 255*7c478bd9Sstevel@tonic-gate } 256*7c478bd9Sstevel@tonic-gate } 257*7c478bd9Sstevel@tonic-gate 258*7c478bd9Sstevel@tonic-gate unsigned char * 259*7c478bd9Sstevel@tonic-gate octal(unsigned char c, unsigned char *ptr) 260*7c478bd9Sstevel@tonic-gate { 261*7c478bd9Sstevel@tonic-gate *ptr++ = '\\'; 262*7c478bd9Sstevel@tonic-gate *ptr++ = ((unsigned int)c >> 6) + '0'; 263*7c478bd9Sstevel@tonic-gate *ptr++ = (((unsigned int)c >> 3) & 07) + '0'; 264*7c478bd9Sstevel@tonic-gate *ptr++ = (c & 07) + '0'; 265*7c478bd9Sstevel@tonic-gate return (ptr); 266*7c478bd9Sstevel@tonic-gate } 267*7c478bd9Sstevel@tonic-gate 268*7c478bd9Sstevel@tonic-gate void 269*7c478bd9Sstevel@tonic-gate prs_cntl(unsigned char *s) 270*7c478bd9Sstevel@tonic-gate { 271*7c478bd9Sstevel@tonic-gate int n; 272*7c478bd9Sstevel@tonic-gate wchar_t wc; 273*7c478bd9Sstevel@tonic-gate unsigned char *olds = s; 274*7c478bd9Sstevel@tonic-gate unsigned char *ptr = bufp; 275*7c478bd9Sstevel@tonic-gate wchar_t c; 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate if ((n = mbtowc(&wc, (const char *)s, MB_LEN_MAX)) <= 0) { 278*7c478bd9Sstevel@tonic-gate n = 0; 279*7c478bd9Sstevel@tonic-gate } 280*7c478bd9Sstevel@tonic-gate while (n != 0) { 281*7c478bd9Sstevel@tonic-gate if (n < 0) { 282*7c478bd9Sstevel@tonic-gate ptr = octal(*s++, ptr); 283*7c478bd9Sstevel@tonic-gate } else { 284*7c478bd9Sstevel@tonic-gate c = wc; 285*7c478bd9Sstevel@tonic-gate s += n; 286*7c478bd9Sstevel@tonic-gate if (!iswprint(c)) { 287*7c478bd9Sstevel@tonic-gate if (c < '\040' && c > 0) { 288*7c478bd9Sstevel@tonic-gate /* 289*7c478bd9Sstevel@tonic-gate * assumes ASCII char 290*7c478bd9Sstevel@tonic-gate * translate a control character 291*7c478bd9Sstevel@tonic-gate * into a printable sequence 292*7c478bd9Sstevel@tonic-gate */ 293*7c478bd9Sstevel@tonic-gate *ptr++ = '^'; 294*7c478bd9Sstevel@tonic-gate *ptr++ = (c + 0100); 295*7c478bd9Sstevel@tonic-gate } else if (c == 0177) { 296*7c478bd9Sstevel@tonic-gate /* '\0177' does not work */ 297*7c478bd9Sstevel@tonic-gate *ptr++ = '^'; 298*7c478bd9Sstevel@tonic-gate *ptr++ = '?'; 299*7c478bd9Sstevel@tonic-gate } else { 300*7c478bd9Sstevel@tonic-gate /* 301*7c478bd9Sstevel@tonic-gate * unprintable 8-bit byte sequence 302*7c478bd9Sstevel@tonic-gate * assumes all legal multibyte 303*7c478bd9Sstevel@tonic-gate * sequences are 304*7c478bd9Sstevel@tonic-gate * printable 305*7c478bd9Sstevel@tonic-gate */ 306*7c478bd9Sstevel@tonic-gate ptr = octal(*olds, ptr); 307*7c478bd9Sstevel@tonic-gate } 308*7c478bd9Sstevel@tonic-gate } else { 309*7c478bd9Sstevel@tonic-gate while (n--) { 310*7c478bd9Sstevel@tonic-gate *ptr++ = *olds++; 311*7c478bd9Sstevel@tonic-gate } 312*7c478bd9Sstevel@tonic-gate } 313*7c478bd9Sstevel@tonic-gate } 314*7c478bd9Sstevel@tonic-gate if (buffd != -1 && ptr >= &bufp[BUFLEN-4]) { 315*7c478bd9Sstevel@tonic-gate *ptr = '\0'; 316*7c478bd9Sstevel@tonic-gate prs(bufp); 317*7c478bd9Sstevel@tonic-gate ptr = bufp; 318*7c478bd9Sstevel@tonic-gate } 319*7c478bd9Sstevel@tonic-gate olds = s; 320*7c478bd9Sstevel@tonic-gate if ((n = mbtowc(&wc, (const char *)s, MB_LEN_MAX)) <= 0) { 321*7c478bd9Sstevel@tonic-gate n = 0; 322*7c478bd9Sstevel@tonic-gate } 323*7c478bd9Sstevel@tonic-gate } 324*7c478bd9Sstevel@tonic-gate *ptr = '\0'; 325*7c478bd9Sstevel@tonic-gate prs(bufp); 326*7c478bd9Sstevel@tonic-gate } 327*7c478bd9Sstevel@tonic-gate 328*7c478bd9Sstevel@tonic-gate void 329*7c478bd9Sstevel@tonic-gate prl_buff(long lc) 330*7c478bd9Sstevel@tonic-gate { 331*7c478bd9Sstevel@tonic-gate prs_buff(&numbuf[ltos(lc)]); 332*7c478bd9Sstevel@tonic-gate } 333*7c478bd9Sstevel@tonic-gate 334*7c478bd9Sstevel@tonic-gate void 335*7c478bd9Sstevel@tonic-gate prull_buff(u_longlong_t lc) 336*7c478bd9Sstevel@tonic-gate { 337*7c478bd9Sstevel@tonic-gate prs_buff(&numbuf[ulltos(lc)]); 338*7c478bd9Sstevel@tonic-gate } 339*7c478bd9Sstevel@tonic-gate 340*7c478bd9Sstevel@tonic-gate void 341*7c478bd9Sstevel@tonic-gate prn_buff(int n) 342*7c478bd9Sstevel@tonic-gate { 343*7c478bd9Sstevel@tonic-gate itos(n); 344*7c478bd9Sstevel@tonic-gate 345*7c478bd9Sstevel@tonic-gate prs_buff(numbuf); 346*7c478bd9Sstevel@tonic-gate } 347*7c478bd9Sstevel@tonic-gate 348*7c478bd9Sstevel@tonic-gate void 349*7c478bd9Sstevel@tonic-gate prsp_buff(int cnt) 350*7c478bd9Sstevel@tonic-gate { 351*7c478bd9Sstevel@tonic-gate while (cnt--) { 352*7c478bd9Sstevel@tonic-gate prc_buff(SPACE); 353*7c478bd9Sstevel@tonic-gate } 354*7c478bd9Sstevel@tonic-gate } 355*7c478bd9Sstevel@tonic-gate 356*7c478bd9Sstevel@tonic-gate int 357*7c478bd9Sstevel@tonic-gate setb(int fd) 358*7c478bd9Sstevel@tonic-gate { 359*7c478bd9Sstevel@tonic-gate int ofd; 360*7c478bd9Sstevel@tonic-gate 361*7c478bd9Sstevel@tonic-gate if ((ofd = buffd) == -1) { 362*7c478bd9Sstevel@tonic-gate if (bufp+index+1 >= brkend) { 363*7c478bd9Sstevel@tonic-gate growstak(bufp+index+1); 364*7c478bd9Sstevel@tonic-gate } 365*7c478bd9Sstevel@tonic-gate if (bufp[index-1]) { 366*7c478bd9Sstevel@tonic-gate bufp[index++] = 0; 367*7c478bd9Sstevel@tonic-gate } 368*7c478bd9Sstevel@tonic-gate endstak(bufp+index); 369*7c478bd9Sstevel@tonic-gate } else { 370*7c478bd9Sstevel@tonic-gate flushb(); 371*7c478bd9Sstevel@tonic-gate } 372*7c478bd9Sstevel@tonic-gate if ((buffd = fd) == -1) { 373*7c478bd9Sstevel@tonic-gate bufp = locstak(); 374*7c478bd9Sstevel@tonic-gate } else { 375*7c478bd9Sstevel@tonic-gate bufp = buffer; 376*7c478bd9Sstevel@tonic-gate } 377*7c478bd9Sstevel@tonic-gate index = 0; 378*7c478bd9Sstevel@tonic-gate return (ofd); 379*7c478bd9Sstevel@tonic-gate } 380