home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / ohlutil / cp_aux.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-24  |  3.4 KB  |  136 lines

  1. /*  cp-aux.c  -- file copying (auxiliary routines)
  2.     Copyright (C) 1989, 1990 Free Software Foundation.
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 1, or (at your option)
  7.     any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     Written by Torbjorn Granlund, Sweden (tege@sics.se).
  19. */
  20.  
  21. /*
  22.  * MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  23.  *
  24.  * To this port, the same copying conditions apply as to the
  25.  * original release.
  26.  *
  27.  * IMPORTANT:
  28.  * This file is not identical to the original GNU release!
  29.  * You should have received this code as patch to the official
  30.  * GNU release.
  31.  *
  32.  * MORE IMPORTANT:
  33.  * This port comes with ABSOLUTELY NO WARRANTY.
  34.  *
  35.  * $Header: e:/gnu/fileutil/RCS/cp-aux.c'v 1.3.0.2 90/06/29 00:46:35 tho Stable $
  36.  */
  37.  
  38. #include <stdio.h>
  39.  
  40. #include "cp.h"
  41.  
  42. extern char *program_name;
  43.  
  44. void
  45. usage (reason)
  46.      char *reason;
  47. {
  48.   if (reason != NULL)
  49.     fprintf (stderr, "%s: %s\n", program_name, reason);
  50.  
  51.   fprintf (stderr, "\
  52. Usage: %s [-bdfioprvR] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
  53.        [+backup] [+no-dereference] [+force] [+interactive] [+one-file-system]\n\
  54.        [+preserve] [+recursive] [+verbose] [+suffix backup-suffix]\n\
  55.        [+version-control {numbered,existing,simple}] source dest\n\
  56. \n", program_name);
  57.   fprintf (stderr, "\
  58.        %s [-bdfioprvR] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
  59.        [+backup] [+no-dereference] [+force] [+interactive] [+one-file-system]\n\
  60.        [+preserve] [+recursive] [+verbose] [+suffix backup-suffix]\n\
  61.        [+version-control {numbered,existing,simple}] source... directory\n",
  62.        program_name);
  63.  
  64.   exit (2);
  65. }
  66.  
  67. char *
  68. xmalloc (size)
  69.      unsigned size;
  70. {
  71.   char *x = malloc (size);
  72.   if (x == 0)
  73.     error (1, 0, "virtual memory exhausted");
  74.   return x;
  75. }
  76.  
  77. char *
  78. xrealloc (ptr, size)
  79.      char *ptr;
  80.      unsigned size;
  81. {
  82.   char *x = realloc (ptr, size);
  83.   if (x == 0)
  84.     error (1, 0, "virtual memory exhausted");
  85.   return x;
  86. }
  87.  
  88. char *
  89. str_cpy (s1, s2)
  90.      char *s1;
  91.      char *s2;
  92. {
  93.   while ((*s1++ = *s2++) != '\0')
  94.     ;
  95.   return s1 - 1;
  96. }
  97.  
  98. int
  99. yesno ()
  100. {
  101.   int c, t;
  102.  
  103.   fflush (stderr);
  104.   c = t = getchar ();
  105.   while (t != EOF && t != '\n')
  106.     t = getchar ();
  107.   return c == 'y' || c == 'Y';
  108. }
  109.  
  110. int
  111. is_ancestor (sb, ancestors)
  112.      struct stat *sb;
  113.      struct dir_list *ancestors;
  114. {
  115.   while (ancestors != 0)
  116.     {
  117.       if (ancestors->ino == sb->st_ino && ancestors->dev == sb->st_dev)
  118.     return 1;
  119.       ancestors = ancestors->parent;
  120.     }
  121.   return 0;
  122. }
  123.  
  124. /* Remove trailing slashes from PATH; they cause some system calls to fail. */
  125.  
  126. void
  127. strip_trailing_slashes (path)
  128.      char *path;
  129. {
  130.   int last;
  131.  
  132.   last = strlen (path) - 1;
  133.   while (last > 0 && path[last] == '/')
  134.     path[last--] = '\0';
  135. }
  136.