[darwinbuild-changes] [490] branches/PR-6688645/darwinup/Utils.cpp
source_changes at macosforge.org
source_changes at macosforge.org
Fri Mar 20 14:17:31 PDT 2009
Revision: 490
http://trac.macosforge.org/projects/darwinbuild/changeset/490
Author: wsiegrist at apple.com
Date: 2009-03-20 14:17:31 -0700 (Fri, 20 Mar 2009)
Log Message:
-----------
We were not removing slashes at the end of p2, so do one last slashes check after the while loop. Also switch from our custom compact_slashes to a macro using memmove.
Modified Paths:
--------------
branches/PR-6688645/darwinup/Utils.cpp
Modified: branches/PR-6688645/darwinup/Utils.cpp
===================================================================
--- branches/PR-6688645/darwinup/Utils.cpp 2009-03-19 20:10:32 UTC (rev 489)
+++ branches/PR-6688645/darwinup/Utils.cpp 2009-03-20 21:17:31 UTC (rev 490)
@@ -142,14 +142,14 @@
return res;
}
+#define compact_slashes(buf, count) do { memmove(buf - count + 1, buf, strlen(buf) + 1); buf -= count; } while (0)
+
/**
* join_path joins two paths and removes any extra slashes,
* even internal ones in p1 or p2. It allocates memory
* for the string and the caller is responsible for freeing.
*/
int join_path(char **out, const char *p1, const char *p2) {
- int res = 0;
-
asprintf(out, "%s/%s", p1, p2);
if (!out) {
fprintf(stderr, "Error: join_path is out of memory!\n");
@@ -164,36 +164,15 @@
} else {
// we found the next non-slash
if (slashes > 1) {
- res = compact_slashes(cur, slashes);
- if (res == -1) {
- fprintf(stderr, "Error: could not compact slashes\n");
- return res;
- }
+ compact_slashes(cur, slashes);
}
slashes = 0;
}
cur++;
}
-
+ // see if we had extra slashes at the very end of p2
+ if (slashes > 1) {
+ compact_slashes(cur, slashes);
+ }
return 0;
}
-
-/**
- * compact_slashes takes a pointer to the next non-slash
- * after a number of slashes, and shifts characters to the
- * left in order to overwrite the extra slashes. It also
- * moves the null terminator.
- */
-int compact_slashes(char *orig, int slashes) {
- char *right = orig;
- char *left = orig - slashes + 1; // leave 1 slash
-
- while (*right != '\0') {
- *(left++) = *(right++);
- }
-
- // one last assignment to set the new null terminator
- *left = *right;
-
- return 0;
-}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20090320/9ae93c54/attachment.html>
More information about the darwinbuild-changes
mailing list