(root)/
tar-1.35/
src/
warning.c
       1  /* Warnings for GNU tar.
       2  
       3     Copyright 2009-2023 Free Software Foundation, Inc.
       4  
       5     This file is part of GNU tar.
       6  
       7     GNU tar is free software; you can redistribute it and/or modify
       8     it under the terms of the GNU General Public License as published by
       9     the Free Software Foundation; either version 3 of the License, or
      10     (at your option) any later version.
      11  
      12     GNU tar is distributed in the hope that it will be useful,
      13     but WITHOUT ANY WARRANTY; without even the implied warranty of
      14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15     GNU General Public License for more details.
      16  
      17     You should have received a copy of the GNU General Public License
      18     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
      19  
      20  #include <system.h>
      21  #include <argmatch.h>
      22  
      23  #include "common.h"
      24  
      25  static char const *const warning_args[] = {
      26    "all",
      27    "alone-zero-block",
      28    "bad-dumpdir",
      29    "cachedir",
      30    "contiguous-cast",
      31    "file-changed",
      32    "file-ignored",
      33    "file-removed",
      34    "file-shrank",
      35    "file-unchanged",
      36    "filename-with-nuls",
      37    "ignore-archive",
      38    "ignore-newer",
      39    "new-directory",
      40    "rename-directory",
      41    "symlink-cast",
      42    "timestamp",
      43    "unknown-cast",
      44    "unknown-keyword",
      45    "xdev",
      46    "decompress-program",
      47    "existing-file",
      48    "xattr-write",
      49    "record-size",
      50    "failed-read",
      51    "missing-zero-blocks",
      52    "verbose",
      53    NULL
      54  };
      55  
      56  static int warning_types[] = {
      57    WARN_ALL,
      58    WARN_ALONE_ZERO_BLOCK,
      59    WARN_BAD_DUMPDIR,
      60    WARN_CACHEDIR,
      61    WARN_CONTIGUOUS_CAST,
      62    WARN_FILE_CHANGED,
      63    WARN_FILE_IGNORED,
      64    WARN_FILE_REMOVED,
      65    WARN_FILE_SHRANK,
      66    WARN_FILE_UNCHANGED,
      67    WARN_FILENAME_WITH_NULS,
      68    WARN_IGNORE_ARCHIVE,
      69    WARN_IGNORE_NEWER,
      70    WARN_NEW_DIRECTORY,
      71    WARN_RENAME_DIRECTORY,
      72    WARN_SYMLINK_CAST,
      73    WARN_TIMESTAMP,
      74    WARN_UNKNOWN_CAST,
      75    WARN_UNKNOWN_KEYWORD,
      76    WARN_XDEV,
      77    WARN_DECOMPRESS_PROGRAM,
      78    WARN_EXISTING_FILE,
      79    WARN_XATTR_WRITE,
      80    WARN_RECORD_SIZE,
      81    WARN_FAILED_READ,
      82    WARN_MISSING_ZERO_BLOCKS,
      83    WARN_VERBOSE_WARNINGS,
      84  };
      85  
      86  ARGMATCH_VERIFY (warning_args, warning_types);
      87  
      88  int warning_option = WARN_ALL & ~(WARN_VERBOSE_WARNINGS|WARN_MISSING_ZERO_BLOCKS);
      89  
      90  void
      91  set_warning_option (const char *arg)
      92  {
      93    int negate = 0;
      94    int option;
      95  
      96    if (strcmp (arg, "none") == 0)
      97      {
      98        warning_option = 0;
      99        return;
     100      }
     101    if (strlen (arg) > 2 && memcmp (arg, "no-", 3) == 0)
     102      {
     103        negate = 1;
     104        arg += 3;
     105      }
     106  
     107    option = XARGMATCH ("--warning", arg,
     108  		      warning_args, warning_types);
     109    if (negate)
     110      warning_option &= ~option;
     111    else
     112      warning_option |= option;
     113  }