]> diplodocus.org Git - nmh/blob - sbr/m_backup.c
Fix invalid pointer arithmetic.
[nmh] / sbr / m_backup.c
1 /* m_backup.c -- construct a backup file
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
6 */
7
8 #include <h/mh.h>
9 #include "m_mktemp.h"
10
11
12 char *
13 m_backup (const char *file)
14 {
15 const char *cp;
16 static char buffer[BUFSIZ];
17
18 if ((cp = r1bindex((char *) file, '/')) == file)
19 snprintf(buffer, sizeof(buffer), "%s%s",
20 BACKUP_PREFIX, cp);
21 else
22 snprintf(buffer, sizeof(buffer), "%.*s%s%s", (int)(cp - file), file,
23 BACKUP_PREFIX, cp);
24
25 (void) m_unlink(buffer);
26 return buffer;
27 }