summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2010-01-11 20:04:42 +0100
committerAndreas Gruenbacher <agruen@suse.de>2010-05-02 11:44:03 +0200
commit502d77b81b692ec1f3e03c2cce621df85cf110f2 (patch)
treeedfca39029c1008f6be77bb509fbaef193035117
parent5f3b6a06a14899717ecefbbf8f20975fa4875e71 (diff)
downloadpatch-502d77b81b692ec1f3e03c2cce621df85cf110f2.tar.gz
Do not modify the string arguments of makedirs and removedirs
* src/patch.c (main): Convert outname into a char const *. * src/util.ch (create_backup, move_file, removedirs): Take char const * filenames. * src/util.c (makedirs): Take a char const * filename. (makedirs, removedirs): Take char const * filenames. Create and modify a copy of the filename.
-rw-r--r--ChangeLog7
-rw-r--r--src/patch.c2
-rw-r--r--src/util.c14
-rw-r--r--src/util.h6
4 files changed, 20 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 4e96bc3..fff4368 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2009-04-29 Andreas Gruenbacher <agruen@suse.de>
+ * src/patch.c (main): Convert outname into a char const *.
+ * src/util.ch (create_backup, move_file, removedirs): Take char const *
+ filenames.
+ * src/util.c (makedirs): Take a char const * filename.
+ (makedirs, removedirs): Take char const * filenames. Create and
+ modify a copy of the filename.
+
* src/pch.c (p_copy, p_rename): New variables.
(pch_copy, pch_rename): New functions.
(intuit_diff_type): Parse the "copy from", "copy to", "rename from",
diff --git a/src/patch.c b/src/patch.c
index 07913bb..74c7767 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -180,7 +180,7 @@ main (int argc, char **argv)
int hunk = 0;
int failed = 0;
bool mismatch = false;
- char *outname = NULL;
+ char const *outname = NULL;
if (! skip_rest_of_patch && ! file_type)
{
diff --git a/src/util.c b/src/util.c
index f7819d2..7fd8302 100644
--- a/src/util.c
+++ b/src/util.c
@@ -41,7 +41,7 @@
#include <stdarg.h>
#include <full-write.h>
-static void makedirs (char *);
+static void makedirs (char const *);
typedef struct
{
@@ -194,7 +194,7 @@ create_backup_copy (char const *from, char const *to, struct stat *st,
}
void
-create_backup (char *to, struct stat *to_st, int *to_errno,
+create_backup (char const *to, struct stat *to_st, int *to_errno,
bool leave_original)
{
struct stat tmp_st;
@@ -322,7 +322,7 @@ create_backup (char *to, struct stat *to_st, int *to_errno,
void
move_file (char const *from, int *from_needs_removal,
struct stat const *fromst,
- char *to, mode_t mode, bool backup)
+ char const *to, mode_t mode, bool backup)
{
struct stat to_st;
int to_errno = -1;
@@ -1154,8 +1154,9 @@ replace_slashes (char *filename)
Ignore the last element of `filename'. */
static void
-makedirs (char *filename)
+makedirs (char const *name)
{
+ char *filename = xstrdup (name);
char *f;
char *flim = replace_slashes (filename);
@@ -1176,14 +1177,16 @@ makedirs (char *filename)
*f = '/';
}
}
+ free (filename);
}
/* Remove empty ancestor directories of FILENAME.
Ignore errors, since the path may contain ".."s, and when there
is an EEXIST failure the system may return some other error number. */
void
-removedirs (char *filename)
+removedirs (char const *name)
{
+ char *filename = xstrdup (name);
size_t i;
for (i = strlen (filename); i != 0; i--)
@@ -1201,6 +1204,7 @@ removedirs (char *filename)
say ("Removed empty directory %s\n", quotearg (filename));
filename[i] = '/';
}
+ free (filename);
}
static struct timespec initial_time;
diff --git a/src/util.h b/src/util.h
index aff9cb5..d8b851d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -55,11 +55,11 @@ void ignore_signals (void);
void init_backup_hash_table (void);
void init_time (void);
void xalloc_die (void) __attribute__ ((noreturn));
-void create_backup (char *, struct stat *, int *, bool);
-void move_file (char const *, int *, struct stat const *, char *, mode_t, bool);
+void create_backup (char const *, struct stat *, int *, bool);
+void move_file (char const *, int *, struct stat const *, char const *, mode_t, bool);
void read_fatal (void) __attribute__ ((noreturn));
void remove_prefix (char *, size_t);
-void removedirs (char *);
+void removedirs (char const *);
void set_signals (bool);
void write_fatal (void) __attribute__ ((noreturn));
bool file_already_seen (struct stat const *);