1 |
commit: 6554499b2e3e51288ed69349c648c8455cc05dc1 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri May 27 17:24:43 2011 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri May 27 17:24:43 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=6554499b |
7 |
|
8 |
chpathtool: update documentation |
9 |
|
10 |
Update the inline docu and manpage to actually reflect what's |
11 |
implemented currently. |
12 |
|
13 |
--- |
14 |
man/chpathtool.5 | 35 ++++++++++++++++++++++++++--------- |
15 |
src/chpathtool.c | 15 +++++++++------ |
16 |
2 files changed, 35 insertions(+), 15 deletions(-) |
17 |
|
18 |
diff --git a/man/chpathtool.5 b/man/chpathtool.5 |
19 |
index 97714da..ce6dbcf 100644 |
20 |
--- a/man/chpathtool.5 |
21 |
+++ b/man/chpathtool.5 |
22 |
@@ -1,4 +1,4 @@ |
23 |
-.TH "CHPATHTOOL" "5" "Dec 2007" "Portage 2.2-prefix" "Portage" |
24 |
+.TH "CHPATHTOOL" "5" "May 2011" "Portage 2.2-prefix" "Portage" |
25 |
.SH NAME |
26 |
chpathtool \- changes paths inside files |
27 |
.SH SYNOPSIS |
28 |
@@ -21,8 +21,8 @@ and writes the modified file as |
29 |
.RB "The important difference of " chpathtool " when compared to e.g. |
30 |
.BR sed "(1) |
31 |
is that for the strings it replaces, it maintains the original string |
32 |
-.RI "length of " magic " by padding the " value " string with zero |
33 |
-.RI "bytes, until the size of " magic " is reached. |
34 |
+.RI "length of " magic " by prepending as much '/'-characters as needed |
35 |
+.RI "to the " value " string to match the size of " magic " for binary files." |
36 |
.P |
37 |
.RB "For efficiency, " chpathtool " will operate recursively if |
38 |
.IR in-file " is a directory. In that case, " out-file " is assumed |
39 |
@@ -32,14 +32,31 @@ properties of the original file in the output file. Currently, |
40 |
.P |
41 |
.BR chpathtool " is meant for the Prefix branch of Portage to relocate |
42 |
packages from one prefix offset to another. This ability allows for the |
43 |
-use of binary packages, even though built for a different prefix offset. |
44 |
-.RB "When " chpathtool " has found a match inside a binary file, it replaces |
45 |
+use of binary packages, even though built for a different offset prefix. |
46 |
+.P |
47 |
+.RB "When " chpathtool " has found a match inside a binary file, |
48 |
+it simply uses the replacement string which has been prepended with as |
49 |
+many '/'-characters as necessary to match the size of the to be replaced |
50 |
+string. This strategy makes an awkward but correct path on UNIX |
51 |
+systems, and has the advantage of being as long as the original path. |
52 |
+This is in particular important for binary files that may store |
53 |
+information about the original string. An example is C-code where the |
54 |
+optimizer replaced a strlen(static_path_var) with the actual length of |
55 |
+that string. The strings cannot be just shortened also because in |
56 |
+binaries typically offsets are used to find relevant pieces of data. |
57 |
+Changing the size here would break those offsets. |
58 |
+.P |
59 |
+For text files, it avoids adding many '/'-characters because the |
60 |
+previously mentioned string length problem is typically is not going to |
61 |
+be a problem. Here, |
62 |
+.B chpathtool |
63 |
+replaces |
64 |
the string, and searches for the end of the string in the form of a |
65 |
zero-byte ('\\0'). At this byte, the neccessary padding bytes are |
66 |
-inserted, such that the binary internally doesn't change in size. This |
67 |
-is important for binaries where offsets are used to find relevant pieces |
68 |
-of data. For certain files, this zero-byte is never found, such as in |
69 |
-.RB "e.g. text files. For those files, " chpathtool " will " not " |
70 |
+inserted, such that the file internally doesn't change in size, if it |
71 |
+happens to have zero-bytes in it. It is to be expected that for text |
72 |
+files, this zero-byte is never found, and |
73 |
+.BR "chpathtool " will " not " |
74 |
write out the padding zero-bytes, and produce a warning about this |
75 |
instead. |
76 |
.P |
77 |
|
78 |
diff --git a/src/chpathtool.c b/src/chpathtool.c |
79 |
index c4e481b..7a74567 100644 |
80 |
--- a/src/chpathtool.c |
81 |
+++ b/src/chpathtool.c |
82 |
@@ -4,11 +4,14 @@ |
83 |
* chpathtool replaces a given string (magic) into another (value), |
84 |
* thereby paying attention to the original size of magic in order not |
85 |
* to change offsets in the file changed. To achieve this goal, value |
86 |
- * is not greater in size than magic, and the difference in size between |
87 |
- * the two is compensated by adding NULL-bytes at the end of a modified |
88 |
- * string. The end of a string is considered to be at the first |
89 |
- * NULL-byte encountered after magic. If no such NULL-byte is found, as |
90 |
- * in a plain text file, the padding NULL-bytes are silently dropped. |
91 |
+ * may not be greater in size than magic, and for binary files, the |
92 |
+ * difference in size between the two is compensated by prepending |
93 |
+ * '/'-characters to value uptil it matches the size of magic. For text |
94 |
+ * files magic is just replaced with value, with the additional logic |
95 |
+ * that the end of a string is considered to be at the first NULL-byte |
96 |
+ * encountered after magic. If no such NULL-byte is found, the padding |
97 |
+ * NULL-bytes are silently dropped. Since this is done on text files, |
98 |
+ * this is likely the case. |
99 |
*/ |
100 |
|
101 |
#include <stdio.h> |
102 |
@@ -141,7 +144,7 @@ static int chpath(const char *fi, const char *fo) { |
103 |
firstblock = 0; |
104 |
/* examine the bytes we read to judge if they are binary or |
105 |
* text; in case of the latter we can avoid writing ugly |
106 |
- * paths with zilions of backslashes */ |
107 |
+ * paths with zilions of slashes */ |
108 |
for (pos = 0; pos < len; pos++) { |
109 |
/* this is a very stupid assumption, but I don't know |
110 |
* anything better: if we find a byte that's out of |