ls.c revision 86922
1/* 2 * Copyright (c) 1989, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Michael Fischbein. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37#ifndef lint 38static const char copyright[] = 39"@(#) Copyright (c) 1989, 1993, 1994\n\ 40 The Regents of the University of California. All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44#if 0 45static char sccsid[] = "@(#)ls.c 8.5 (Berkeley) 4/2/94"; 46#else 47static const char rcsid[] = 48 "$FreeBSD: head/bin/ls/ls.c 86922 2001-11-26 22:21:15Z green $"; 49#endif 50#endif /* not lint */ 51 52#include <sys/types.h> 53#include <sys/stat.h> 54#include <sys/ioctl.h> 55 56#include <dirent.h> 57#include <err.h> 58#include <errno.h> 59#include <fts.h> 60#include <limits.h> 61#include <locale.h> 62#include <stdio.h> 63#include <stdlib.h> 64#include <string.h> 65#include <unistd.h> 66#ifdef COLORLS 67#include <termcap.h> 68#include <signal.h> 69#endif 70 71#include "ls.h" 72#include "extern.h" 73#include "lomac.h" 74 75/* 76 * Upward approximation of the maximum number of characters needed to 77 * represent a value of integral type t as a string, excluding the 78 * NUL terminator, with provision for a sign. 79 */ 80#define STRBUF_SIZEOF(t) (1 + CHAR_BIT * sizeof(t) / 3 + 1) 81 82static void display __P((FTSENT *, FTSENT *)); 83static u_quad_t makenines __P((u_long)); 84static int mastercmp __P((const FTSENT **, const FTSENT **)); 85static void traverse __P((int, char **, int)); 86 87static void (*printfcn) __P((DISPLAY *)); 88static int (*sortfcn) __P((const FTSENT *, const FTSENT *)); 89 90long blocksize; /* block size units */ 91int termwidth = 80; /* default terminal width */ 92 93/* flags */ 94int f_accesstime; /* use time of last access */ 95int f_column; /* columnated format */ 96int f_flags; /* show flags associated with a file */ 97int f_inode; /* print inode */ 98int f_kblocks; /* print size in kilobytes */ 99int f_listdir; /* list actual directory, not contents */ 100int f_listdot; /* list files beginning with . */ 101int f_longform; /* long listing format */ 102int f_nonprint; /* show unprintables as ? */ 103int f_nosort; /* don't sort output */ 104int f_notabs; /* don't use tab-separated multi-col output */ 105int f_numericonly; /* don't convert uid/gid to name */ 106int f_octal; /* show unprintables as \xxx */ 107int f_octal_escape; /* like f_octal but use C escapes if possible */ 108int f_recursive; /* ls subdirectories also */ 109int f_reversesort; /* reverse whatever sort is used */ 110int f_sectime; /* print the real time for all files */ 111int f_singlecol; /* use single column output */ 112int f_size; /* list size in short listing */ 113int f_statustime; /* use time of last mode change */ 114int f_timesort; /* sort by time vice name */ 115int f_type; /* add type character for non-regular files */ 116int f_whiteout; /* show whiteout entries */ 117int f_lomac; /* show LOMAC attributes */ 118#ifdef COLORLS 119int f_color; /* add type in color for non-regular files */ 120 121char *ansi_bgcol; /* ANSI sequence to set background colour */ 122char *ansi_fgcol; /* ANSI sequence to set foreground colour */ 123char *ansi_coloff; /* ANSI sequence to reset colours */ 124#endif 125 126int rval; 127 128int 129main(argc, argv) 130 int argc; 131 char *argv[]; 132{ 133 static char dot[] = ".", *dotav[] = { dot, NULL }; 134 struct winsize win; 135 int ch, fts_options, notused; 136 char *p; 137 138#ifdef COLORLS 139 char termcapbuf[1024]; /* termcap definition buffer */ 140 char tcapbuf[512]; /* capability buffer */ 141 char *bp = tcapbuf; 142#endif 143 144 (void) setlocale(LC_ALL, ""); 145 146 /* Terminal defaults to -Cq, non-terminal defaults to -1. */ 147 if (isatty(STDOUT_FILENO)) { 148 if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == -1 || 149 !win.ws_col) { 150 if ((p = getenv("COLUMNS")) != NULL) 151 termwidth = atoi(p); 152 } 153 else 154 termwidth = win.ws_col; 155 f_column = f_nonprint = 1; 156 } else { 157 f_singlecol = 1; 158 /* retrieve environment variable, in case of explicit -C */ 159 if ((p = getenv("COLUMNS"))) 160 termwidth = atoi(p); 161 } 162 163 /* Root is -A automatically. */ 164 if (!getuid()) 165 f_listdot = 1; 166 167 fts_options = FTS_PHYSICAL; 168 while ((ch = getopt(argc, argv, "1ABCFGHLPRTWZabcdfgiklnoqrstu")) != -1) { 169 switch (ch) { 170 /* 171 * The -1, -C and -l options all override each other so shell 172 * aliasing works right. 173 */ 174 case '1': 175 f_singlecol = 1; 176 f_column = f_longform = 0; 177 break; 178 case 'B': 179 f_nonprint = 0; 180 f_octal = 1; 181 f_octal_escape = 0; 182 break; 183 case 'C': 184 f_column = 1; 185 f_longform = f_singlecol = 0; 186 break; 187 case 'l': 188 f_longform = 1; 189 f_column = f_singlecol = 0; 190 break; 191 /* The -c and -u options override each other. */ 192 case 'c': 193 f_statustime = 1; 194 f_accesstime = 0; 195 break; 196 case 'u': 197 f_accesstime = 1; 198 f_statustime = 0; 199 break; 200 case 'F': 201 f_type = 1; 202 break; 203 case 'H': 204 fts_options |= FTS_COMFOLLOW; 205 break; 206 case 'G': 207 setenv("CLICOLOR", "", 1); 208 break; 209 case 'L': 210 fts_options &= ~FTS_PHYSICAL; 211 fts_options |= FTS_LOGICAL; 212 break; 213 case 'P': 214 fts_options &= ~FTS_COMFOLLOW; 215 fts_options &= ~FTS_LOGICAL; 216 fts_options |= FTS_PHYSICAL; 217 break; 218 case 'R': 219 f_recursive = 1; 220 break; 221 case 'a': 222 fts_options |= FTS_SEEDOT; 223 /* FALLTHROUGH */ 224 case 'A': 225 f_listdot = 1; 226 break; 227 /* The -d option turns off the -R option. */ 228 case 'd': 229 f_listdir = 1; 230 f_recursive = 0; 231 break; 232 case 'f': 233 f_nosort = 1; 234 break; 235 case 'g': /* Compatibility with 4.3BSD. */ 236 break; 237 case 'i': 238 f_inode = 1; 239 break; 240 case 'k': 241 f_kblocks = 1; 242 break; 243 case 'n': 244 f_numericonly = 1; 245 break; 246 case 'o': 247 f_flags = 1; 248 break; 249 case 'q': 250 f_nonprint = 1; 251 f_octal = 0; 252 f_octal_escape = 0; 253 break; 254 case 'r': 255 f_reversesort = 1; 256 break; 257 case 's': 258 f_size = 1; 259 break; 260 case 'T': 261 f_sectime = 1; 262 break; 263 case 't': 264 f_timesort = 1; 265 break; 266 case 'W': 267 f_whiteout = 1; 268 break; 269 case 'b': 270 f_nonprint = 0; 271 f_octal = 0; 272 f_octal_escape = 1; 273 break; 274 case 'Z': 275 f_lomac = 1; 276 break; 277 default: 278 case '?': 279 usage(); 280 } 281 } 282 argc -= optind; 283 argv += optind; 284 285 /* Enabling of colours is conditional on the environment. */ 286 if (getenv("CLICOLOR") && 287 (isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE"))) 288#ifdef COLORLS 289 if (tgetent(termcapbuf, getenv("TERM")) == 1) { 290 ansi_fgcol = tgetstr("AF", &bp); 291 ansi_bgcol = tgetstr("AB", &bp); 292 293 /* To switch colours off use 'op' if 294 * available, otherwise use 'oc', or 295 * don't do colours at all. */ 296 ansi_coloff = tgetstr("op", &bp); 297 if (!ansi_coloff) 298 ansi_coloff = tgetstr("oc", &bp); 299 if (ansi_fgcol && ansi_bgcol && ansi_coloff) 300 f_color = 1; 301 } 302#else 303 (void)fprintf(stderr, "Color support not compiled in.\n"); 304#endif /*COLORLS*/ 305 306#ifdef COLORLS 307 if (f_color) { 308 /* 309 * We can't put tabs and color sequences together: 310 * column number will be incremented incorrectly 311 * for "stty oxtabs" mode. 312 */ 313 f_notabs = 1; 314 (void) signal(SIGINT, colorquit); 315 (void) signal(SIGQUIT, colorquit); 316 parsecolors(getenv("LSCOLORS")); 317 } 318#endif 319 320 /* 321 * If not -F, -i, -l, -s or -t options, don't require stat 322 * information, unless in color mode in which case we do 323 * need this to determine which colors to display. 324 */ 325 if (!f_inode && !f_longform && !f_size && !f_timesort && !f_type 326#ifdef COLORLS 327 && !f_color 328#endif 329 ) 330 fts_options |= FTS_NOSTAT; 331 332 /* 333 * If not -F, -d or -l options, follow any symbolic links listed on 334 * the command line. 335 */ 336 if (!f_longform && !f_listdir && !f_type) 337 fts_options |= FTS_COMFOLLOW; 338 339 /* 340 * If -W, show whiteout entries 341 */ 342#ifdef FTS_WHITEOUT 343 if (f_whiteout) 344 fts_options |= FTS_WHITEOUT; 345#endif 346 347 /* If -l or -s, figure out block size. */ 348 if (f_longform || f_size) { 349 if (f_kblocks) 350 blocksize = 2; 351 else { 352 (void)getbsize(¬used, &blocksize); 353 blocksize /= 512; 354 } 355 } 356 357 /* Select a sort function. */ 358 if (f_reversesort) { 359 if (!f_timesort) 360 sortfcn = revnamecmp; 361 else if (f_accesstime) 362 sortfcn = revacccmp; 363 else if (f_statustime) 364 sortfcn = revstatcmp; 365 else /* Use modification time. */ 366 sortfcn = revmodcmp; 367 } else { 368 if (!f_timesort) 369 sortfcn = namecmp; 370 else if (f_accesstime) 371 sortfcn = acccmp; 372 else if (f_statustime) 373 sortfcn = statcmp; 374 else /* Use modification time. */ 375 sortfcn = modcmp; 376 } 377 378 /* Select a print function. */ 379 if (f_singlecol) 380 printfcn = printscol; 381 else if (f_longform) 382 printfcn = printlong; 383 else 384 printfcn = printcol; 385 386 if (argc) 387 traverse(argc, argv, fts_options); 388 else 389 traverse(1, dotav, fts_options); 390 exit(rval); 391} 392 393static int output; /* If anything output. */ 394 395/* 396 * Traverse() walks the logical directory structure specified by the argv list 397 * in the order specified by the mastercmp() comparison function. During the 398 * traversal it passes linked lists of structures to display() which represent 399 * a superset (may be exact set) of the files to be displayed. 400 */ 401static void 402traverse(argc, argv, options) 403 int argc, options; 404 char *argv[]; 405{ 406 FTS *ftsp; 407 FTSENT *p, *chp; 408 int ch_options; 409 410 if ((ftsp = 411 fts_open(argv, options, f_nosort ? NULL : mastercmp)) == NULL) 412 err(1, NULL); 413 414 display(NULL, fts_children(ftsp, 0)); 415 if (f_listdir) 416 return; 417 418 /* 419 * If not recursing down this tree and don't need stat info, just get 420 * the names. 421 */ 422 ch_options = !f_recursive && options & FTS_NOSTAT ? FTS_NAMEONLY : 0; 423 424 while ((p = fts_read(ftsp)) != NULL) 425 switch (p->fts_info) { 426 case FTS_DC: 427 warnx("%s: directory causes a cycle", p->fts_name); 428 break; 429 case FTS_DNR: 430 case FTS_ERR: 431 warnx("%s: %s", p->fts_name, strerror(p->fts_errno)); 432 rval = 1; 433 break; 434 case FTS_D: 435 if (p->fts_level != FTS_ROOTLEVEL && 436 p->fts_name[0] == '.' && !f_listdot) 437 break; 438 439 /* 440 * If already output something, put out a newline as 441 * a separator. If multiple arguments, precede each 442 * directory with its name. 443 */ 444 if (output) 445 (void)printf("\n%s:\n", p->fts_path); 446 else if (argc > 1) { 447 (void)printf("%s:\n", p->fts_path); 448 output = 1; 449 } 450 451 chp = fts_children(ftsp, ch_options); 452 display(p, chp); 453 454 if (!f_recursive && chp != NULL) 455 (void)fts_set(ftsp, p, FTS_SKIP); 456 break; 457 } 458 if (errno) 459 err(1, "fts_read"); 460} 461 462/* 463 * Display() takes a linked list of FTSENT structures and passes the list 464 * along with any other necessary information to the print function. P 465 * points to the parent directory of the display list. 466 */ 467static void 468display(p, list) 469 FTSENT *p, *list; 470{ 471 struct stat *sp; 472 DISPLAY d; 473 FTSENT *cur; 474 NAMES *np; 475 u_quad_t maxsize; 476 u_long btotal, maxblock, maxinode, maxlen, maxnlink, maxlattr; 477 int bcfile, flen, glen, ulen, lattrlen, maxflags, maxgroup, maxuser; 478 char *initmax; 479 int entries, needstats; 480 char *user, *group, *flags, *lattr; 481 char buf[STRBUF_SIZEOF(u_quad_t) + 1]; 482 char ngroup[STRBUF_SIZEOF(uid_t) + 1]; 483 char nuser[STRBUF_SIZEOF(gid_t) + 1]; 484 485 /* 486 * If list is NULL there are two possibilities: that the parent 487 * directory p has no children, or that fts_children() returned an 488 * error. We ignore the error case since it will be replicated 489 * on the next call to fts_read() on the post-order visit to the 490 * directory p, and will be signaled in traverse(). 491 */ 492 if (list == NULL) 493 return; 494 495 needstats = f_inode || f_longform || f_size; 496 flen = 0; 497 btotal = 0; 498 initmax = getenv("LS_COLWIDTHS"); 499 /* Fields match -lios order. New ones should be added at the end. */ 500 if (initmax != NULL && *initmax != '\0') { 501 char *initmax2, *jinitmax; 502 int ninitmax; 503 504 /* Fill-in "::" as "0:0:0" for the sake of scanf. */ 505 jinitmax = initmax2 = malloc(strlen(initmax) * 2 + 2); 506 if (jinitmax == NULL) 507 err(1, NULL); 508 if (*initmax == ':') 509 strcpy(initmax2, "0:"), initmax2 += 2; 510 else 511 *initmax2++ = *initmax, *initmax2 = '\0'; 512 for (initmax++; *initmax != '\0'; initmax++) { 513 if (initmax[-1] == ':' && initmax[0] == ':') { 514 *initmax2++ = '0'; 515 *initmax2++ = initmax[0]; 516 initmax2[1] = '\0'; 517 } else { 518 *initmax2++ = initmax[0]; 519 initmax2[1] = '\0'; 520 } 521 } 522 if (initmax2[-1] == ':') strcpy(initmax2, "0"); 523 524 ninitmax = sscanf(jinitmax, 525 " %lu : %lu : %lu : %i : %i : %i : %qu : %lu : %lu ", 526 &maxinode, &maxblock, &maxnlink, &maxuser, 527 &maxgroup, &maxflags, &maxsize, &maxlen, &maxlattr); 528 f_notabs = 1; 529 switch (ninitmax) { 530 case 0: maxinode = 0; 531 case 1: maxblock = 0; 532 case 2: maxnlink = 0; 533 case 3: maxuser = 0; 534 case 4: maxgroup = 0; 535 case 5: maxflags = 0; 536 case 6: maxsize = 0; 537 case 7: maxlen = 0; 538 case 8: maxlattr = 0; 539#ifdef COLORLS 540 if (!f_color) 541#endif 542 f_notabs = 0; 543 } 544 maxinode = makenines(maxinode); 545 maxblock = makenines(maxblock); 546 maxnlink = makenines(maxnlink); 547 maxsize = makenines(maxsize); 548 } else if (initmax == NULL || *initmax == '\0') 549 maxlattr = maxblock = maxinode = maxlen = maxnlink = 550 maxuser = maxgroup = maxflags = maxsize = 0; 551 if (f_lomac) 552 lomac_start(); 553 bcfile = 0; 554 flags = NULL; 555 for (cur = list, entries = 0; cur; cur = cur->fts_link) { 556 if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS) { 557 warnx("%s: %s", 558 cur->fts_name, strerror(cur->fts_errno)); 559 cur->fts_number = NO_PRINT; 560 rval = 1; 561 continue; 562 } 563 564 /* 565 * P is NULL if list is the argv list, to which different rules 566 * apply. 567 */ 568 if (p == NULL) { 569 /* Directories will be displayed later. */ 570 if (cur->fts_info == FTS_D && !f_listdir) { 571 cur->fts_number = NO_PRINT; 572 continue; 573 } 574 } else { 575 /* Only display dot file if -a/-A set. */ 576 if (cur->fts_name[0] == '.' && !f_listdot) { 577 cur->fts_number = NO_PRINT; 578 continue; 579 } 580 } 581 if (cur->fts_namelen > maxlen) 582 maxlen = cur->fts_namelen; 583 if (f_octal || f_octal_escape) { 584 int t = len_octal(cur->fts_name, cur->fts_namelen); 585 if (t > maxlen) maxlen = t; 586 } 587 if (needstats) { 588 sp = cur->fts_statp; 589 if (sp->st_blocks > maxblock) 590 maxblock = sp->st_blocks; 591 if (sp->st_ino > maxinode) 592 maxinode = sp->st_ino; 593 if (sp->st_nlink > maxnlink) 594 maxnlink = sp->st_nlink; 595 if (sp->st_size > maxsize) 596 maxsize = sp->st_size; 597 598 btotal += sp->st_blocks; 599 if (f_longform) { 600 if (f_numericonly) { 601 (void)snprintf(nuser, sizeof(nuser), 602 "%u", sp->st_uid); 603 (void)snprintf(ngroup, sizeof(ngroup), 604 "%u", sp->st_gid); 605 user = nuser; 606 group = ngroup; 607 } else { 608 user = user_from_uid(sp->st_uid, 0); 609 group = group_from_gid(sp->st_gid, 0); 610 } 611 if ((ulen = strlen(user)) > maxuser) 612 maxuser = ulen; 613 if ((glen = strlen(group)) > maxgroup) 614 maxgroup = glen; 615 if (f_flags) { 616 flags = fflagstostr(sp->st_flags); 617 if (flags != NULL && *flags == '\0') { 618 free(flags); 619 flags = strdup("-"); 620 } 621 if (flags == NULL) 622 err(1, NULL); 623 if ((flen = strlen(flags)) > maxflags) 624 maxflags = flen; 625 } else 626 flen = 0; 627 if (f_lomac) { 628 lattr = get_lattr(cur); 629 lattrlen = strlen(lattr); 630 if (lattrlen > maxlattr) 631 maxlattr = lattrlen; 632 } else 633 lattrlen = 0; 634 635 if ((np = malloc(sizeof(NAMES) + lattrlen + 636 ulen + glen + flen + 4)) == NULL) 637 err(1, NULL); 638 639 np->user = &np->data[0]; 640 (void)strcpy(np->user, user); 641 np->group = &np->data[ulen + 1]; 642 (void)strcpy(np->group, group); 643 644 if (S_ISCHR(sp->st_mode) || 645 S_ISBLK(sp->st_mode)) 646 bcfile = 1; 647 648 if (f_flags) { 649 np->flags = &np->data[ulen + glen + 2]; 650 (void)strcpy(np->flags, flags); 651 free(flags); 652 } 653 if (f_lomac) { 654 np->lattr = &np->data[ulen + glen + 2 655 + (f_flags ? flen + 1 : 0)]; 656 (void)strcpy(np->lattr, lattr); 657 free(lattr); 658 } 659 cur->fts_pointer = np; 660 } 661 } 662 ++entries; 663 } 664 665 if (!entries) 666 return; 667 668 d.list = list; 669 d.entries = entries; 670 d.maxlen = maxlen; 671 if (needstats) { 672 d.bcfile = bcfile; 673 d.btotal = btotal; 674 (void)snprintf(buf, sizeof(buf), "%lu", maxblock); 675 d.s_block = strlen(buf); 676 d.s_flags = maxflags; 677 d.s_lattr = maxlattr; 678 d.s_group = maxgroup; 679 (void)snprintf(buf, sizeof(buf), "%lu", maxinode); 680 d.s_inode = strlen(buf); 681 (void)snprintf(buf, sizeof(buf), "%lu", maxnlink); 682 d.s_nlink = strlen(buf); 683 (void)snprintf(buf, sizeof(buf), "%qu", maxsize); 684 d.s_size = strlen(buf); 685 d.s_user = maxuser; 686 } 687 688 printfcn(&d); 689 output = 1; 690 691 if (f_longform) 692 for (cur = list; cur; cur = cur->fts_link) 693 free(cur->fts_pointer); 694 if (f_lomac) 695 lomac_stop(); 696} 697 698/* 699 * Ordering for mastercmp: 700 * If ordering the argv (fts_level = FTS_ROOTLEVEL) return non-directories 701 * as larger than directories. Within either group, use the sort function. 702 * All other levels use the sort function. Error entries remain unsorted. 703 */ 704static int 705mastercmp(a, b) 706 const FTSENT **a, **b; 707{ 708 int a_info, b_info; 709 710 a_info = (*a)->fts_info; 711 if (a_info == FTS_ERR) 712 return (0); 713 b_info = (*b)->fts_info; 714 if (b_info == FTS_ERR) 715 return (0); 716 717 if (a_info == FTS_NS || b_info == FTS_NS) 718 return (namecmp(*a, *b)); 719 720 if (a_info != b_info && 721 (*a)->fts_level == FTS_ROOTLEVEL && !f_listdir) { 722 if (a_info == FTS_D) 723 return (1); 724 if (b_info == FTS_D) 725 return (-1); 726 } 727 return (sortfcn(*a, *b)); 728} 729 730/* 731 * Makenines() returns (10**n)-1. This is useful for converting a width 732 * into a number that wide in decimal. 733 */ 734static u_quad_t 735makenines(n) 736 u_long n; 737{ 738 u_long i; 739 u_quad_t reg; 740 741 reg = 1; 742 /* Use a loop instead of pow(), since all values of n are small. */ 743 for (i = 0; i < n; i++) 744 reg *= 10; 745 reg--; 746 747 return reg; 748} 749