Print this page
5613 odd ls -U behaviour if output is not a terminal


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012, Joyent, Inc. All rights reserved.

  25  */
  26 
  27 /*
  28  * Copyright 2009 Jason King.  All rights reserved.
  29  * Use is subject to license terms.
  30  */
  31 
  32 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  33 /*        All Rights Reserved   */
  34 
  35 /*      Copyright (c) 1987, 1988 Microsoft Corporation  */
  36 /*        All Rights Reserved   */
  37 
  38 /*
  39  * List files or directories
  40  */
  41 
  42 #include <sys/param.h>
  43 #include <sys/types.h>
  44 #include <sys/mkdev.h>


1243                 new_line();
1244         }
1245 }
1246 
1247 /*
1248  * print one output entry;
1249  * if uid/gid is not found in the appropriate
1250  * file(passwd/group), then print uid/gid instead of
1251  * user/group name;
1252  */
1253 static void
1254 pentry(struct lbuf *ap)
1255 {
1256         struct lbuf *p;
1257         numbuf_t hbuf;
1258         char *dmark = "";       /* Used if -p or -F option active */
1259         char *cp;
1260         char *str;
1261 
1262         if (noflist) {
1263                 (void) printf("%s\n", ap->ln.lname);

1264                 return;
1265         }
1266 
1267         p = ap;
1268         column();
1269         if (iflg) {
1270                 if (mflg && !lflg)
1271                         curcol += printf("%llu ", (long long)p->lnum);
1272                 else
1273                         curcol += printf("%10llu ", (long long)p->lnum);
1274         }
1275         if (sflg) {
1276                 curcol += printf((mflg && !lflg) ? "%lld " :
1277                     (p->lblocks < 10000) ? "%4lld " : "%lld ",
1278                     (p->ltype != 'b' && p->ltype != 'c') ?
1279                     p->lblocks : 0LL);
1280         }
1281         if (lflg) {
1282                 (void) putchar(p->ltype);
1283                 curcol++;


1794                         perror("ls");
1795                         nomocore = 1;
1796                         return (NULL);
1797                 }
1798         }
1799 
1800         /*
1801          * nfiles is reset to nargs for each directory
1802          * that is given as an argument maxn is checked
1803          * to prevent the assignment of an lbuf to a flist entry
1804          * that already has one assigned.
1805          */
1806         if (nfiles >= maxn) {
1807                 rep = nxtlbf++;
1808                 flist[nfiles++] = rep;
1809                 maxn = nfiles;
1810         } else {
1811                 rep = flist[nfiles++];
1812         }
1813 



1814         /*
1815          * When noflist is set, none of the extra information about the dirent
1816          * will be printed, so omit initialization of this lbuf as well as the
1817          * stat(2) call.
1818          */
1819         if (!argfl && noflist)
1820                 return (rep);
1821 
1822         /* Initialize */
1823 
1824         rep->lflags = (mode_t)0;
1825         rep->flinkto = NULL;
1826         rep->cycle = 0;
1827         rep->lat.tv_sec = time(NULL);
1828         rep->lat.tv_nsec = 0;
1829         rep->lct.tv_sec = time(NULL);
1830         rep->lct.tv_nsec = 0;
1831         rep->lmt.tv_sec = time(NULL);
1832         rep->lmt.tv_nsec = 0;
1833         rep->aclp = NULL;
1834         rep->exttr = NULL;
1835         rep->extm = NULL;
1836         rep->color = NULL;
1837         rep->link_color = NULL;
1838 
1839         if (argfl || statreq) {
1840                 int doacl;
1841 
1842                 if (lflg)
1843                         doacl = 1;
1844                 else
1845                         doacl = 0;
1846 
1847                 if ((*statf)(file, &statb) < 0) {
1848                         if (argfl || errno != ENOENT ||
1849                             (Lflg && lstat(file, &statb) == 0)) {
1850                                 /*
1851                                  * Avoid race between readdir and lstat.
1852                                  * Print error message in case of dangling link.
1853                                  */
1854                                 perror(file);
1855                                 err = 2;
1856                         }
1857                         nfiles--;




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
  25  * Copyright 2015 Gary Mills
  26  */
  27 
  28 /*
  29  * Copyright 2009 Jason King.  All rights reserved.
  30  * Use is subject to license terms.
  31  */
  32 
  33 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  34 /*        All Rights Reserved   */
  35 
  36 /*      Copyright (c) 1987, 1988 Microsoft Corporation  */
  37 /*        All Rights Reserved   */
  38 
  39 /*
  40  * List files or directories
  41  */
  42 
  43 #include <sys/param.h>
  44 #include <sys/types.h>
  45 #include <sys/mkdev.h>


1244                 new_line();
1245         }
1246 }
1247 
1248 /*
1249  * print one output entry;
1250  * if uid/gid is not found in the appropriate
1251  * file(passwd/group), then print uid/gid instead of
1252  * user/group name;
1253  */
1254 static void
1255 pentry(struct lbuf *ap)
1256 {
1257         struct lbuf *p;
1258         numbuf_t hbuf;
1259         char *dmark = "";       /* Used if -p or -F option active */
1260         char *cp;
1261         char *str;
1262 
1263         if (noflist) {
1264                 (void) printf("%s\n", (ap->lflags & ISARG) ? ap->ln.namep :
1265                     ap->ln.lname);
1266                 return;
1267         }
1268 
1269         p = ap;
1270         column();
1271         if (iflg) {
1272                 if (mflg && !lflg)
1273                         curcol += printf("%llu ", (long long)p->lnum);
1274                 else
1275                         curcol += printf("%10llu ", (long long)p->lnum);
1276         }
1277         if (sflg) {
1278                 curcol += printf((mflg && !lflg) ? "%lld " :
1279                     (p->lblocks < 10000) ? "%4lld " : "%lld ",
1280                     (p->ltype != 'b' && p->ltype != 'c') ?
1281                     p->lblocks : 0LL);
1282         }
1283         if (lflg) {
1284                 (void) putchar(p->ltype);
1285                 curcol++;


1796                         perror("ls");
1797                         nomocore = 1;
1798                         return (NULL);
1799                 }
1800         }
1801 
1802         /*
1803          * nfiles is reset to nargs for each directory
1804          * that is given as an argument maxn is checked
1805          * to prevent the assignment of an lbuf to a flist entry
1806          * that already has one assigned.
1807          */
1808         if (nfiles >= maxn) {
1809                 rep = nxtlbf++;
1810                 flist[nfiles++] = rep;
1811                 maxn = nfiles;
1812         } else {
1813                 rep = flist[nfiles++];
1814         }
1815 
1816         /* Clear the lbuf */
1817         (void) memset((void *) rep, 0, sizeof (struct lbuf));
1818 
1819         /*
1820          * When noflist is set, none of the extra information about the dirent
1821          * will be printed, so omit remaining initialization of this lbuf
1822          * as well as the  stat(2) call.
1823          */
1824         if (!argfl && noflist)
1825                 return (rep);
1826 
1827         /* Initialize non-zero members */
1828 



1829         rep->lat.tv_sec = time(NULL);

1830         rep->lct.tv_sec = time(NULL);

1831         rep->lmt.tv_sec = time(NULL);






1832 
1833         if (argfl || statreq) {
1834                 int doacl;
1835 
1836                 if (lflg)
1837                         doacl = 1;
1838                 else
1839                         doacl = 0;
1840 
1841                 if ((*statf)(file, &statb) < 0) {
1842                         if (argfl || errno != ENOENT ||
1843                             (Lflg && lstat(file, &statb) == 0)) {
1844                                 /*
1845                                  * Avoid race between readdir and lstat.
1846                                  * Print error message in case of dangling link.
1847                                  */
1848                                 perror(file);
1849                                 err = 2;
1850                         }
1851                         nfiles--;