(maybe_backup_file): Changed return type
[debian/tar] / src / misc.c
1 /* Miscellaneous functions, not really specific to GNU tar.
2
3    Copyright (C) 1988, 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
4    2003 Free Software Foundation, Inc.
5
6    This program is free software; you can redistribute it and/or modify it
7    under the terms of the GNU General Public License as published by the
8    Free Software Foundation; either version 2, or (at your option) any later
9    version.
10
11    This program is distributed in the hope that it will be useful, but
12    WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
14    Public License for more details.
15
16    You should have received a copy of the GNU General Public License along
17    with this program; if not, write to the Free Software Foundation, Inc.,
18    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
20 #include "system.h"
21 #include "rmt.h"
22 #include "common.h"
23 #include <quotearg.h>
24 #include <save-cwd.h>
25
26 static void call_arg_fatal (char const *, char const *)
27      __attribute__ ((noreturn));
28 \f
29 /* Handling strings.  */
30
31 /* Assign STRING to a copy of VALUE if not zero, or to zero.  If
32    STRING was nonzero, it is freed first.  */
33 void
34 assign_string (char **string, const char *value)
35 {
36   if (*string)
37     free (*string);
38   *string = value ? xstrdup (value) : 0;
39 }
40
41 /* Allocate a copy of the string quoted as in C, and returns that.  If
42    the string does not have to be quoted, it returns a null pointer.
43    The allocated copy should normally be freed with free() after the
44    caller is done with it.
45
46    This is used in one context only: generating the directory file in
47    incremental dumps.  The quoted string is not intended for human
48    consumption; it is intended only for unquote_string.  The quoting
49    is locale-independent, so that users needn't worry about locale
50    when reading directory files.  This means that we can't use
51    quotearg, as quotearg is locale-dependent and is meant for human
52    consumption.  */
53 char *
54 quote_copy_string (const char *string)
55 {
56   const char *source = string;
57   char *destination = 0;
58   char *buffer = 0;
59   int copying = 0;
60
61   while (*source)
62     {
63       int character = *source++;
64
65       switch (character)
66         {
67         case '\n': case '\\':
68           if (!copying)
69             {
70               size_t length = (source - string) - 1;
71
72               copying = 1;
73               buffer = xmalloc (length + 2 + 2 * strlen (source) + 1);
74               memcpy (buffer, string, length);
75               destination = buffer + length;
76             }
77           *destination++ = '\\';
78           *destination++ = character == '\\' ? '\\' : 'n';
79           break;
80
81         default:
82           if (copying)
83             *destination++ = character;
84           break;
85         }
86     }
87   if (copying)
88     {
89       *destination = '\0';
90       return buffer;
91     }
92   return 0;
93 }
94
95 /* Takes a quoted C string (like those produced by quote_copy_string)
96    and turns it back into the un-quoted original.  This is done in
97    place.  Returns 0 only if the string was not properly quoted, but
98    completes the unquoting anyway.
99
100    This is used for reading the saved directory file in incremental
101    dumps.  It is used for decoding old `N' records (demangling names).
102    But also, it is used for decoding file arguments, would they come
103    from the shell or a -T file, and for decoding the --exclude
104    argument.  */
105 int
106 unquote_string (char *string)
107 {
108   int result = 1;
109   char *source = string;
110   char *destination = string;
111
112   /* Escape sequences other than \\ and \n are no longer generated by
113      quote_copy_string, but accept them for backwards compatibility,
114      and also because unquote_string is used for purposes other than
115      parsing the output of quote_copy_string.  */
116
117   while (*source)
118     if (*source == '\\')
119       switch (*++source)
120         {
121         case '\\':
122           *destination++ = '\\';
123           source++;
124           break;
125
126         case 'n':
127           *destination++ = '\n';
128           source++;
129           break;
130
131         case 't':
132           *destination++ = '\t';
133           source++;
134           break;
135
136         case 'f':
137           *destination++ = '\f';
138           source++;
139           break;
140
141         case 'b':
142           *destination++ = '\b';
143           source++;
144           break;
145
146         case 'r':
147           *destination++ = '\r';
148           source++;
149           break;
150
151         case '?':
152           *destination++ = 0177;
153           source++;
154           break;
155
156         case '0':
157         case '1':
158         case '2':
159         case '3':
160         case '4':
161         case '5':
162         case '6':
163         case '7':
164           {
165             int value = *source++ - '0';
166
167             if (*source < '0' || *source > '7')
168               {
169                 *destination++ = value;
170                 break;
171               }
172             value = value * 8 + *source++ - '0';
173             if (*source < '0' || *source > '7')
174               {
175                 *destination++ = value;
176                 break;
177               }
178             value = value * 8 + *source++ - '0';
179             *destination++ = value;
180             break;
181           }
182
183         default:
184           result = 0;
185           *destination++ = '\\';
186           if (*source)
187             *destination++ = *source++;
188           break;
189         }
190     else if (source != destination)
191       *destination++ = *source++;
192     else
193       source++, destination++;
194
195   if (source != destination)
196     *destination = '\0';
197   return result;
198 }
199 \f
200 /* File handling.  */
201
202 /* Saved names in case backup needs to be undone.  */
203 static char *before_backup_name;
204 static char *after_backup_name;
205
206 /* Return 1 if PATH is obviously "." or "/".  */
207 static bool
208 must_be_dot_or_slash (char const *path)
209 {
210   path += FILESYSTEM_PREFIX_LEN (path);
211
212   if (ISSLASH (path[0]))
213     {
214       for (;;)
215         if (ISSLASH (path[1]))
216           path++;
217         else if (path[1] == '.' && ISSLASH (path[2 + (path[2] == '.')]))
218           path += 2 + (path[2] == '.');
219         else
220           return ! path[1];
221     }
222   else
223     {
224       while (path[0] == '.' && ISSLASH (path[1]))
225         {
226           path += 2;
227           while (ISSLASH (*path))
228             path++;
229         }
230
231       return ! path[0] || (path[0] == '.' && ! path[1]);
232     }
233 }
234
235 /* Some implementations of rmdir let you remove '.' or '/'.
236    Report an error with errno set to zero for obvious cases of this;
237    otherwise call rmdir.  */
238 static int
239 safer_rmdir (const char *path)
240 {
241   if (must_be_dot_or_slash (path))
242     {
243       errno = 0;
244       return -1;
245     }
246
247   return rmdir (path);
248 }
249
250 /* Remove PATH, returning 1 on success.  If PATH is a directory, then
251    if OPTION is RECURSIVE_REMOVE_OPTION is set remove PATH
252    recursively; otherwise, remove it only if it is empty.  If PATH is
253    a directory that cannot be removed (e.g., because it is nonempty)
254    and if OPTION is WANT_DIRECTORY_REMOVE_OPTION, then return -1.
255    Return 0 on error, with errno set; if PATH is obviously the working
256    directory return zero with errno set to zero.  */
257 int
258 remove_any_file (const char *path, enum remove_option option)
259 {
260   /* Try unlink first if we are not root, as this saves us a system
261      call in the common case where we're removing a non-directory.  */
262   if (! we_are_root)
263     {
264       if (unlink (path) == 0)
265         return 1;
266
267       /* POSIX 1003.1-2001 requires EPERM when attempting to unlink a
268          directory without appropriate privileges, but many Linux
269          kernels return the more-sensible EISDIR.  */
270       if (errno != EPERM && errno != EISDIR)
271         return 0;
272     }
273
274   if (safer_rmdir (path) == 0)
275     return 1;
276
277   switch (errno)
278     {
279     case ENOTDIR:
280       return we_are_root && unlink (path) == 0;
281
282     case 0:
283     case EEXIST:
284 #if defined ENOTEMPTY && ENOTEMPTY != EEXIST
285     case ENOTEMPTY:
286 #endif
287       switch (option)
288         {
289         case ORDINARY_REMOVE_OPTION:
290           break;
291
292         case WANT_DIRECTORY_REMOVE_OPTION:
293           return -1;
294
295         case RECURSIVE_REMOVE_OPTION:
296           {
297             char *directory = savedir (path);
298             char const *entry;
299             size_t entrylen;
300
301             if (! directory)
302               return 0;
303
304             for (entry = directory;
305                  (entrylen = strlen (entry)) != 0;
306                  entry += entrylen + 1)
307               {
308                 char *path_buffer = new_name (path, entry);
309                 int r = remove_any_file (path_buffer, 1);
310                 int e = errno;
311                 free (path_buffer);
312
313                 if (! r)
314                   {
315                     free (directory);
316                     errno = e;
317                     return 0;
318                   }
319               }
320
321             free (directory);
322             return safer_rmdir (path) == 0;
323           }
324         }
325       break;
326     }
327
328   return 0;
329 }
330
331 /* Check if PATH already exists and make a backup of it right now.
332    Return success (nonzero) only if the backup is either unneeded, or
333    successful.  For now, directories are considered to never need
334    backup.  If ARCHIVE is nonzero, this is the archive and so, we do
335    not have to backup block or character devices, nor remote entities.  */
336 bool
337 maybe_backup_file (const char *path, int archive)
338 {
339   struct stat file_stat;
340
341   /* Check if we really need to backup the file.  */
342
343   if (archive && _remdev (path))
344     return true;
345
346   if (stat (path, &file_stat))
347     {
348       if (errno == ENOENT)
349         return true;
350
351       stat_error (path);
352       return false;
353     }
354
355   if (S_ISDIR (file_stat.st_mode))
356     return true;
357
358   if (archive && (S_ISBLK (file_stat.st_mode) || S_ISCHR (file_stat.st_mode)))
359     return true;
360
361   assign_string (&before_backup_name, path);
362
363   /* A run situation may exist between Emacs or other GNU programs trying to
364      make a backup for the same file simultaneously.  If theoretically
365      possible, real problems are unlikely.  Doing any better would require a
366      convention, GNU-wide, for all programs doing backups.  */
367
368   assign_string (&after_backup_name, 0);
369   after_backup_name = find_backup_file_name (path, backup_type);
370   if (! after_backup_name)
371     xalloc_die ();
372
373   if (rename (before_backup_name, after_backup_name) == 0)
374     {
375       if (verbose_option)
376         fprintf (stdlis, _("Renaming %s to %s\n"),
377                  quote_n (0, before_backup_name),
378                  quote_n (1, after_backup_name));
379       return true;
380     }
381   else
382     {
383       /* The backup operation failed.  */
384       int e = errno;
385       ERROR ((0, e, _("%s: Cannot rename to %s"),
386               quotearg_colon (before_backup_name),
387               quote_n (1, after_backup_name)));
388       assign_string (&after_backup_name, 0);
389       return false;
390     }
391 }
392
393 /* Try to restore the recently backed up file to its original name.
394    This is usually only needed after a failed extraction.  */
395 void
396 undo_last_backup (void)
397 {
398   if (after_backup_name)
399     {
400       if (rename (after_backup_name, before_backup_name) != 0)
401         {
402           int e = errno;
403           ERROR ((0, e, _("%s: Cannot rename to %s"),
404                   quotearg_colon (after_backup_name),
405                   quote_n (1, before_backup_name)));
406         }
407       if (verbose_option)
408         fprintf (stdlis, _("Renaming %s back to %s\n"),
409                  quote_n (0, after_backup_name),
410                  quote_n (1, before_backup_name));
411       assign_string (&after_backup_name, 0);
412     }
413 }
414
415 /* Depending on DEREF, apply either stat or lstat to (NAME, BUF).  */
416 int
417 deref_stat (bool deref, char const *name, struct stat *buf)
418 {
419   return deref ? stat (name, buf) : lstat (name, buf);
420 }
421
422 /* A description of a working directory.  */
423 struct wd
424 {
425   char const *name;
426   int saved;
427   struct saved_cwd saved_cwd;
428 };
429
430 /* A vector of chdir targets.  wd[0] is the initial working directory.  */
431 static struct wd *wd;
432
433 /* The number of working directories in the vector.  */
434 static size_t wds;
435
436 /* The allocated size of the vector.  */
437 static size_t wd_alloc;
438
439 /* DIR is the operand of a -C option; add it to vector of chdir targets,
440    and return the index of its location.  */
441 int
442 chdir_arg (char const *dir)
443 {
444   if (wds == wd_alloc)
445     {
446       wd_alloc = 2 * (wd_alloc + 1);
447       wd = xrealloc (wd, sizeof *wd * wd_alloc);
448       if (! wds)
449         {
450           wd[wds].name = ".";
451           wd[wds].saved = 0;
452           wds++;
453         }
454     }
455
456   /* Optimize the common special case of the working directory,
457      or the working directory as a prefix.  */
458   if (dir[0])
459     {
460       while (dir[0] == '.' && ISSLASH (dir[1]))
461         for (dir += 2;  ISSLASH (*dir);  dir++)
462           continue;
463       if (! dir[dir[0] == '.'])
464         return wds - 1;
465     }
466
467   wd[wds].name = dir;
468   wd[wds].saved = 0;
469   return wds++;
470 }
471
472 /* Change to directory I.  If I is 0, change to the initial working
473    directory; otherwise, I must be a value returned by chdir_arg.  */
474 void
475 chdir_do (int i)
476 {
477   static int previous;
478
479   if (previous != i)
480     {
481       struct wd *prev = &wd[previous];
482       struct wd *curr = &wd[i];
483
484       if (! prev->saved)
485         {
486           prev->saved = 1;
487           if (save_cwd (&prev->saved_cwd) != 0)
488             FATAL_ERROR ((0, 0, _("Cannot save working directory")));
489         }
490
491       if (curr->saved)
492         {
493           if (restore_cwd (&curr->saved_cwd))
494             FATAL_ERROR ((0, 0, _("Cannot change working directory")));
495         }
496       else
497         {
498           if (i && ! ISSLASH (curr->name[0]))
499             chdir_do (i - 1);
500           if (chdir (curr->name) != 0)
501             chdir_fatal (curr->name);
502         }
503
504       previous = i;
505     }
506 }
507 \f
508 /* Decode MODE from its binary form in a stat structure, and encode it
509    into a 9-byte string STRING, terminated with a NUL.  */
510
511 void
512 decode_mode (mode_t mode, char *string)
513 {
514   *string++ = mode & S_IRUSR ? 'r' : '-';
515   *string++ = mode & S_IWUSR ? 'w' : '-';
516   *string++ = (mode & S_ISUID
517                ? (mode & S_IXUSR ? 's' : 'S')
518                : (mode & S_IXUSR ? 'x' : '-'));
519   *string++ = mode & S_IRGRP ? 'r' : '-';
520   *string++ = mode & S_IWGRP ? 'w' : '-';
521   *string++ = (mode & S_ISGID
522                ? (mode & S_IXGRP ? 's' : 'S')
523                : (mode & S_IXGRP ? 'x' : '-'));
524   *string++ = mode & S_IROTH ? 'r' : '-';
525   *string++ = mode & S_IWOTH ? 'w' : '-';
526   *string++ = (mode & S_ISVTX
527                ? (mode & S_IXOTH ? 't' : 'T')
528                : (mode & S_IXOTH ? 'x' : '-'));
529   *string = '\0';
530 }
531
532 /* Report an error associated with the system call CALL and the
533    optional name NAME.  */
534 static void
535 call_arg_error (char const *call, char const *name)
536 {
537   int e = errno;
538   ERROR ((0, e, _("%s: Cannot %s"), quotearg_colon (name), call));
539 }
540
541 /* Report a fatal error associated with the system call CALL and
542    the optional file name NAME.  */
543 static void
544 call_arg_fatal (char const *call, char const *name)
545 {
546   int e = errno;
547   FATAL_ERROR ((0, e, _("%s: Cannot %s"), quotearg_colon (name),  call));
548 }
549
550 /* Report a warning associated with the system call CALL and
551    the optional file name NAME.  */
552 static void
553 call_arg_warn (char const *call, char const *name)
554 {
555   int e = errno;
556   WARN ((0, e, _("%s: Warning: Cannot %s"), quotearg_colon (name), call));
557 }
558
559 void
560 chdir_fatal (char const *name)
561 {
562   call_arg_fatal ("chdir", name);
563 }
564
565 void
566 chmod_error_details (char const *name, mode_t mode)
567 {
568   int e = errno;
569   char buf[10];
570   decode_mode (mode, buf);
571   ERROR ((0, e, _("%s: Cannot change mode to %s"),
572           quotearg_colon (name), buf));
573 }
574
575 void
576 chown_error_details (char const *name, uid_t uid, gid_t gid)
577 {
578   int e = errno;
579   ERROR ((0, e, _("%s: Cannot change ownership to uid %lu, gid %lu"),
580           quotearg_colon (name), (unsigned long) uid, (unsigned long) gid));
581 }
582
583 void
584 close_error (char const *name)
585 {
586   call_arg_error ("close", name);
587 }
588
589 void
590 close_fatal (char const *name)
591 {
592   call_arg_fatal ("close", name);
593 }
594
595 void
596 close_warn (char const *name)
597 {
598   call_arg_warn ("close", name);
599 }
600
601 void
602 close_diag (char const *name)
603 {
604   if (ignore_failed_read_option)
605     close_warn (name);
606   else
607     close_error (name);
608 }
609
610 void
611 exec_fatal (char const *name)
612 {
613   call_arg_fatal ("exec", name);
614 }
615
616 void
617 link_error (char const *target, char const *source)
618 {
619   int e = errno;
620   ERROR ((0, e, _("%s: Cannot hard link to %s"),
621           quotearg_colon (source), quote_n (1, target)));
622 }
623
624 void
625 mkdir_error (char const *name)
626 {
627   call_arg_error ("mkdir", name);
628 }
629
630 void
631 mkfifo_error (char const *name)
632 {
633   call_arg_error ("mkfifo", name);
634 }
635
636 void
637 mknod_error (char const *name)
638 {
639   call_arg_error ("mknod", name);
640 }
641
642 void
643 open_error (char const *name)
644 {
645   call_arg_error ("open", name);
646 }
647
648 void
649 open_fatal (char const *name)
650 {
651   call_arg_fatal ("open", name);
652 }
653
654 void
655 open_warn (char const *name)
656 {
657   call_arg_warn ("open", name);
658 }
659
660 void
661 open_diag (char const *name)
662 {
663   if (ignore_failed_read_option)
664     open_warn (name);
665   else
666     open_error (name);
667 }
668
669 void
670 read_error (char const *name)
671 {
672   call_arg_error ("read", name);
673 }
674
675 void
676 read_error_details (char const *name, off_t offset, size_t size)
677 {
678   char buf[UINTMAX_STRSIZE_BOUND];
679   int e = errno;
680   ERROR ((0, e,
681           ngettext ("%s: Read error at byte %s, reading %lu byte",
682                     "%s: Read error at byte %s, reading %lu bytes",
683                     size),
684           quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
685           (unsigned long) size));
686 }
687
688 void
689 read_warn_details (char const *name, off_t offset, size_t size)
690 {
691   char buf[UINTMAX_STRSIZE_BOUND];
692   int e = errno;
693   WARN ((0, e,
694          ngettext ("%s: Warning: Read error at byte %s, reading %lu byte",
695                    "%s: Warning: Read error at byte %s, reading %lu bytes",
696                    size),
697          quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
698          (unsigned long) size));
699 }
700
701 void
702 read_diag_details (char const *name, off_t offset, size_t size)
703 {
704   if (ignore_failed_read_option)
705     read_warn_details (name, offset, size);
706   else
707     read_error_details (name, offset, size);
708 }
709
710 void
711 read_fatal (char const *name)
712 {
713   call_arg_fatal ("read", name);
714 }
715
716 void
717 read_fatal_details (char const *name, off_t offset, size_t size)
718 {
719   char buf[UINTMAX_STRSIZE_BOUND];
720   int e = errno;
721   FATAL_ERROR ((0, e,
722                 ngettext ("%s: Read error at byte %s, reading %lu byte",
723                           "%s: Read error at byte %s, reading %lu bytes",
724                           size),
725                 quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
726                 (unsigned long) size));
727 }
728
729 void
730 readlink_error (char const *name)
731 {
732   call_arg_error ("readlink", name);
733 }
734
735 void
736 readlink_warn (char const *name)
737 {
738   call_arg_warn ("readlink", name);
739 }
740
741 void
742 readlink_diag (char const *name)
743 {
744   if (ignore_failed_read_option)
745     readlink_warn (name);
746   else
747     readlink_error (name);
748 }
749
750 void
751 savedir_error (char const *name)
752 {
753   call_arg_error ("savedir", name);
754 }
755
756 void
757 savedir_warn (char const *name)
758 {
759   call_arg_warn ("savedir", name);
760 }
761
762 void
763 savedir_diag (char const *name)
764 {
765   if (ignore_failed_read_option)
766     savedir_warn (name);
767   else
768     savedir_error (name);
769 }
770
771 void
772 seek_error (char const *name)
773 {
774   call_arg_error ("seek", name);
775 }
776
777 void
778 seek_error_details (char const *name, off_t offset)
779 {
780   char buf[UINTMAX_STRSIZE_BOUND];
781   int e = errno;
782   ERROR ((0, e, _("%s: Cannot seek to %s"),
783           quotearg_colon (name),
784           STRINGIFY_BIGINT (offset, buf)));
785 }
786
787 void
788 seek_warn (char const *name)
789 {
790   call_arg_warn ("seek", name);
791 }
792
793 void
794 seek_warn_details (char const *name, off_t offset)
795 {
796   char buf[UINTMAX_STRSIZE_BOUND];
797   int e = errno;
798   WARN ((0, e, _("%s: Warning: Cannot seek to %s"),
799          quotearg_colon (name),
800          STRINGIFY_BIGINT (offset, buf)));
801 }
802
803 void
804 seek_diag_details (char const *name, off_t offset)
805 {
806   if (ignore_failed_read_option)
807     seek_warn_details (name, offset);
808   else
809     seek_error_details (name, offset);
810 }
811
812 void
813 symlink_error (char const *contents, char const *name)
814 {
815   int e = errno;
816   ERROR ((0, e, _("%s: Cannot create symlink to %s"),
817           quotearg_colon (name), quote_n (1, contents)));
818 }
819
820 void
821 stat_error (char const *name)
822 {
823   call_arg_error ("stat", name);
824 }
825
826 void
827 stat_warn (char const *name)
828 {
829   call_arg_warn ("stat", name);
830 }
831
832 void
833 stat_diag (char const *name)
834 {
835   if (ignore_failed_read_option)
836     stat_warn (name);
837   else
838     stat_error (name);
839 }
840
841 void
842 truncate_error (char const *name)
843 {
844   call_arg_error ("truncate", name);
845 }
846
847 void
848 truncate_warn (char const *name)
849 {
850   call_arg_warn ("truncate", name);
851 }
852
853 void
854 unlink_error (char const *name)
855 {
856   call_arg_error ("unlink", name);
857 }
858
859 void
860 utime_error (char const *name)
861 {
862   call_arg_error ("utime", name);
863 }
864
865 void
866 waitpid_error (char const *name)
867 {
868   call_arg_error ("waitpid", name);
869 }
870
871 void
872 write_error (char const *name)
873 {
874   call_arg_error ("write", name);
875 }
876
877 void
878 write_error_details (char const *name, ssize_t status, size_t size)
879 {
880   if (status < 0)
881     write_error (name);
882   else
883     ERROR ((0, 0,
884             ngettext ("%s: Wrote only %lu of %lu byte",
885                       "%s: Wrote only %lu of %lu bytes",
886                       record_size),
887             name, (unsigned long) status, (unsigned long) record_size));
888 }
889
890 void
891 write_fatal (char const *name)
892 {
893   call_arg_fatal ("write", name);
894 }
895
896 void
897 write_fatal_details (char const *name, ssize_t status, size_t size)
898 {
899   write_error_details (name, status, size);
900   fatal_exit ();
901 }
902
903
904 /* Fork, aborting if unsuccessful.  */
905 pid_t
906 xfork (void)
907 {
908   pid_t p = fork ();
909   if (p == (pid_t) -1)
910     call_arg_fatal ("fork", _("child process"));
911   return p;
912 }
913
914 /* Create a pipe, aborting if unsuccessful.  */
915 void
916 xpipe (int fd[2])
917 {
918   if (pipe (fd) < 0)
919     call_arg_fatal ("pipe", _("interprocess channel"));
920 }
921
922 /* Return an unambiguous printable representation, allocated in slot N,
923    for NAME, suitable for diagnostics.  */
924 char const *
925 quote_n (int n, char const *name)
926 {
927   return quotearg_n_style (n, locale_quoting_style, name);
928 }
929
930 /* Return an unambiguous printable representation of NAME, suitable
931    for diagnostics.  */
932 char const *
933 quote (char const *name)
934 {
935   return quote_n (0, name);
936 }