Print this page
1150 libcmdutils has superfluous #define
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Reviewed by: Andy Stormont <astormont@racktopsystems.com>
Reviewed by: Marcel Telka <marcel@telka.sk>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libcmdutils/common/writefile.c
          +++ new/usr/src/lib/libcmdutils/common/writefile.c
↓ open down ↓ 29 lines elided ↑ open up ↑
  30   30  /*
  31   31   * University Copyright- Copyright (c) 1982, 1986, 1988
  32   32   * The Regents of the University of California
  33   33   * All Rights Reserved
  34   34   *
  35   35   * University Acknowledgment- Portions of this document are derived from
  36   36   * software developed by the University of California, Berkeley, and its
  37   37   * contributors.
  38   38   */
  39   39  
  40      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  41      -
  42   40  #include "libcmdutils.h"
  43   41  
  44   42  
  45   43  int
  46   44  writefile(int fi, int fo, char *infile, char *outfile, char *asfile,
  47   45      char *atfile, struct stat *s1p, struct stat *s2p)
  48   46  {
  49   47          int mapsize, munmapsize;
  50   48          caddr_t cp;
  51   49          off_t filesize = s1p->st_size;
↓ open down ↓ 39 lines elided ↑ open up ↑
  91   89                      " for path buffer: "));
  92   90                  return (1);
  93   91          }
  94   92          if (atfile != NULL) {
  95   93                  (void) snprintf(targbuf, targ_size, "%s%s%s",
  96   94                      outfile, dgettext(TEXT_DOMAIN, " attribute "), atfile);
  97   95          } else {
  98   96                  (void) snprintf(targbuf, targ_size, "%s", outfile);
  99   97          }
 100   98  
 101      -        if (ISREG(*s1p) && s1p->st_size > SMALLFILESIZE) {
       99 +        if (S_ISREG(s1p->st_mode) && s1p->st_size > SMALLFILESIZE) {
 102  100                  /*
 103  101                   * Determine size of initial mapping.  This will determine the
 104  102                   * size of the address space chunk we work with.  This initial
 105  103                   * mapping size will be used to perform munmap() in the future.
 106  104                   */
 107  105                  mapsize = MAXMAPSIZE;
 108  106                  if (s1p->st_size < mapsize) mapsize = s1p->st_size;
 109  107                  munmapsize = mapsize;
 110  108  
 111  109                  /*
↓ open down ↓ 21 lines elided ↑ open up ↑
 133  131                                          nbytes = write(fo,
 134  132                                              cp + mapsize - remains, remains);
 135  133                                          if (nbytes < 0) {
 136  134                                                  if (errno == ENOSPC)
 137  135                                                          perror(targbuf);
 138  136                                                  else
 139  137                                                          perror(srcbuf);
 140  138                                                  (void) close(fi);
 141  139                                                  (void) close(fo);
 142  140                                                  (void) munmap(cp, munmapsize);
 143      -                                                if (ISREG(*s2p))
      141 +                                                if (S_ISREG(s2p->st_mode))
 144  142                                                          (void) unlink(targbuf);
 145  143                                                  return (1);
 146  144                                          }
 147  145                                          remains -= nbytes;
 148  146                                          if (remains == 0)
 149  147                                                  nbytes = mapsize;
 150  148                                  }
 151  149                          }
 152  150                          /*
 153  151                           * although the write manual page doesn't specify this
↓ open down ↓ 3 lines elided ↑ open up ↑
 157  155                           * problem
 158  156                           */
 159  157                          if (nbytes < 0) {
 160  158                                  if (errno == EACCES)
 161  159                                          perror(srcbuf);
 162  160                                  else
 163  161                                          perror(targbuf);
 164  162                                  (void) close(fi);
 165  163                                  (void) close(fo);
 166  164                                  (void) munmap(cp, munmapsize);
 167      -                                if (ISREG(*s2p))
      165 +                                if (S_ISREG(s2p->st_mode))
 168  166                                          (void) unlink(targbuf);
 169  167                                  if (srcbuf != NULL)
 170  168                                          free(srcbuf);
 171  169                                  if (targbuf != NULL)
 172  170                                          free(targbuf);
 173  171                                  return (1);
 174  172                          }
 175  173                          filesize -= nbytes;
 176  174                          if (filesize == 0)
 177  175                                  break;
 178  176                          offset += nbytes;
 179  177                          if (filesize < mapsize)
 180  178                                  mapsize = filesize;
 181  179                          if (mmap(cp, mapsize, PROT_READ, MAP_SHARED |
 182  180                              MAP_FIXED, fi, offset) == MAP_FAILED) {
 183  181                                  perror(srcbuf);
 184  182                                  (void) close(fi);
 185  183                                  (void) close(fo);
 186  184                                  (void) munmap(cp, munmapsize);
 187      -                                if (ISREG(*s2p))
      185 +                                if (S_ISREG(s2p->st_mode))
 188  186                                          (void) unlink(targbuf);
 189  187                                  if (srcbuf != NULL)
 190  188                                          free(srcbuf);
 191  189                                  if (targbuf != NULL)
 192  190                                          free(targbuf);
 193  191                                  return (1);
 194  192                          }
 195  193                  }
 196  194                  (void) munmap(cp, munmapsize);
 197  195          } else {
 198  196                  char buf[SMALLFILESIZE];
 199  197                  for (;;) {
 200  198                          n = read(fi, buf, sizeof (buf));
 201  199                          if (n == 0) {
 202  200                                  return (0);
 203  201                          } else if (n < 0) {
 204  202                                  (void) close(fi);
 205  203                                  (void) close(fo);
 206      -                                if (ISREG(*s2p))
      204 +                                if (S_ISREG(s2p->st_mode))
 207  205                                          (void) unlink(targbuf);
 208  206                                  if (srcbuf != NULL)
 209  207                                          free(srcbuf);
 210  208                                  if (targbuf != NULL)
 211  209                                          free(targbuf);
 212  210                                  return (1);
 213  211                          } else if (write(fo, buf, n) != n) {
 214  212                                  (void) close(fi);
 215  213                                  (void) close(fo);
 216      -                                if (ISREG(*s2p))
      214 +                                if (S_ISREG(s2p->st_mode))
 217  215                                          (void) unlink(targbuf);
 218  216                                  if (srcbuf != NULL)
 219  217                                          free(srcbuf);
 220  218                                  if (targbuf != NULL)
 221  219                                          free(targbuf);
 222  220                                  return (1);
 223  221                          }
 224  222                  }
 225  223          }
 226  224          if (srcbuf != NULL)
 227  225                  free(srcbuf);
 228  226          if (targbuf != NULL)
 229  227                  free(targbuf);
 230  228          return (0);
 231  229  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX