aboutsummaryrefslogtreecommitdiffstats
path: root/pseudo_util.c
diff options
context:
space:
mode:
authorPeter Seebach <peter.seebach@windriver.com>2010-03-16 23:52:10 -0500
committerPeter Seebach <peter.seebach@windriver.com>2010-03-16 23:54:50 -0500
commit086e65c90420b3d38f30c3cd81a0f8573f6f69cf (patch)
tree0947e95d819a6d9756349ba8795cf5eeb8039e08 /pseudo_util.c
parent33d9386e8d818860ce603356eee074d2a2849085 (diff)
downloadpseudo-086e65c90420b3d38f30c3cd81a0f8573f6f69cf.tar.gz
pseudo-086e65c90420b3d38f30c3cd81a0f8573f6f69cf.tar.bz2
pseudo-086e65c90420b3d38f30c3cd81a0f8573f6f69cf.zip
Update: Fix some missing error checking (thanks to Laszlo Ersek for
spotting these.) Check for failed calls to pseudo_prefix_path in a couple of places, handle failed open of pid file, and make pseudo_prefix_path robust in the case of a zero-length PSEUDO_PREFIX. Also, don't try to overwrite the contents of an environment variable anymore. (The amazing part? None of these have ever caused a failure.)
Diffstat (limited to 'pseudo_util.c')
-rw-r--r--pseudo_util.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/pseudo_util.c b/pseudo_util.c
index 2e21824..0a2c683 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -415,7 +415,7 @@ pseudo_setupenv(char *opts) {
* setting the prefix all set it in the environment.
*/
char *
-pseudo_prefix_path(char *s) {
+pseudo_prefix_path(char *file) {
static char *prefix = NULL;
static size_t prefix_len;
char *path;
@@ -427,17 +427,28 @@ pseudo_prefix_path(char *s) {
exit(1);
}
prefix_len = strlen(prefix);
- while ((prefix[prefix_len - 1] == '/') && (prefix_len > 0)) {
- prefix[--prefix_len] = '\0';
- }
}
- if (!s) {
+ if (!file) {
return strdup(prefix);
} else {
- size_t len = prefix_len + strlen(s) + 2;
+ size_t len = prefix_len + strlen(file) + 2;
path = malloc(len);
if (path) {
- snprintf(path, len, "%s/%s", prefix, s);
+ char *endptr;
+ int rc;
+
+ rc = snprintf(path, len, "%s", prefix);
+ /* this certainly SHOULD be impossible */
+ if (rc >= len)
+ rc = len - 1;
+ endptr = path + rc;
+ /* strip extra slashes.
+ * This probably has no real effect, but I don't like
+ * seeing "//" in paths.
+ */
+ while ((endptr > path) && (endptr[-1] == '/'))
+ --endptr;
+ snprintf(endptr, len - (endptr - path), "/%s", file);
}
return path;
}