~ubuntu-branches/ubuntu/lucid/patch/lucid

« back to all changes in this revision

Viewing changes to backupfile.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Fedrowitz
  • Date: 2004-07-18 12:56:02 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040718125602-s2ukzvags50l967n
Tags: 2.5.9-2
* Standards-Version 3.6.1 (no changes required).
* Applied upstream patch to fix CR stripping. (Closes: #196297)
* Applied a patch from SUSE to prevent previously created backup files
  from being overwritten. (Closes: #248950)
* Ran aclocal and autoconf to make the above patch work.
* Touch aclocal.m4 and configure during build to prevent the usual
  time-skew problems.
* Removed emacs vars from changelog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* backupfile.c -- make Emacs style backup file names
2
 
   Copyright (C) 1990-1997, 1998, 1999 Free Software Foundation, Inc.
 
2
   Copyright (C) 1990,91,92,93,94,95,96,97,98,99,2000, 2001, 2002 Free Software
 
3
   Foundation, Inc.
3
4
 
4
5
   This program is free software; you can redistribute it and/or modify
5
6
   it under the terms of the GNU General Public License as published by
23
24
# include <config.h>
24
25
#endif
25
26
 
26
 
#include <argmatch.h>
27
 
#include <backupfile.h>
28
 
 
29
27
#include <stdio.h>
30
28
#include <sys/types.h>
31
29
#if HAVE_STRING_H
58
56
# define CLOSEDIR(d) closedir (d)
59
57
#endif
60
58
 
61
 
#if STDC_HEADERS
 
59
#if HAVE_STDLIB_H
62
60
# include <stdlib.h>
63
 
#else
64
 
char *malloc ();
65
61
#endif
66
62
 
67
63
#ifndef HAVE_DECL_GETENV
 
64
"this configure-time declaration test was not run"
 
65
#endif
 
66
#if !HAVE_DECL_GETENV
68
67
char *getenv ();
69
68
#endif
70
69
 
71
 
char *base_name PARAMS ((char const *));
 
70
#ifndef HAVE_DECL_MALLOC
 
71
"this configure-time declaration test was not run"
 
72
#endif
 
73
#if !HAVE_DECL_MALLOC
 
74
char *malloc ();
 
75
#endif
72
76
 
73
77
#if HAVE_DIRENT_H || HAVE_NDIR_H || HAVE_SYS_DIR_H || HAVE_SYS_NDIR_H
74
78
# define HAVE_DIR 1
91
95
   - Its arg may be any int or unsigned int; it need not be an unsigned char.
92
96
   - It's guaranteed to evaluate its argument exactly once.
93
97
   - It's typically faster.
94
 
   Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
95
 
   only '0' through '9' are digits.  Prefer ISDIGIT to isdigit unless
96
 
   it's important to use the locale's definition of `digit' even when the
97
 
   host does not conform to Posix.  */
 
98
   POSIX says that only '0' through '9' are digits.  Prefer ISDIGIT to
 
99
   ISDIGIT_LOCALE unless it's important to use the locale's definition
 
100
   of `digit' even when the host does not conform to POSIX.  */
98
101
#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
99
102
 
100
103
#if D_INO_IN_DIRENT
103
106
# define REAL_DIR_ENTRY(dp) 1
104
107
#endif
105
108
 
 
109
#include "argmatch.h"
 
110
#include "backupfile.h"
 
111
#include "dirname.h"
 
112
 
106
113
/* The extension added to file names to produce a simple (as opposed
107
114
   to numbered) backup file name. */
108
115
const char *simple_backup_suffix = "~";
129
136
  if (HAVE_DIR && backup_suffix_size_max < numbered_suffix_size_max)
130
137
    backup_suffix_size_max = numbered_suffix_size_max;
131
138
 
132
 
  s = malloc (file_len + backup_suffix_size_max + numbered_suffix_size_max);
 
139
  s = malloc (file_len + 1
 
140
              + backup_suffix_size_max + numbered_suffix_size_max);
133
141
  if (s)
134
142
    {
135
 
      strcpy (s, file);
136
 
 
137
143
#if HAVE_DIR
138
144
      if (backup_type != simple)
139
145
        {
140
146
          int highest_backup;
141
 
          size_t dir_len = base_name (s) - s;
 
147
          size_t dirlen = dir_len (file);
142
148
 
143
 
          strcpy (s + dir_len, ".");
144
 
          highest_backup = max_backup_version (file + dir_len, s);
 
149
          memcpy (s, file, dirlen);
 
150
          if (dirlen == FILESYSTEM_PREFIX_LEN (file))
 
151
            s[dirlen++] = '.';
 
152
          s[dirlen] = '\0';
 
153
          highest_backup = max_backup_version (base_name (file), s);
145
154
          if (! (backup_type == numbered_existing && highest_backup == 0))
146
155
            {
147
156
              char *numbered_suffix = s + (file_len + backup_suffix_size_max);
148
157
              sprintf (numbered_suffix, ".~%d~", highest_backup + 1);
149
158
              suffix = numbered_suffix;
150
159
            }
151
 
          strcpy (s, file);
152
160
        }
153
161
#endif /* HAVE_DIR */
154
162
 
 
163
      strcpy (s, file);
155
164
      addext (s, suffix, '~');
156
165
    }
157
166
  return s;
178
187
    return 0;
179
188
 
180
189
  highest_version = 0;
181
 
  file_name_length = strlen (file);
 
190
  file_name_length = base_len (file);
182
191
 
183
192
  while ((dp = readdir (dirp)) != 0)
184
193
    {