status = EINVAL;
} else {
/* fully qualified path; just make a copy */
- newPath = (char *)malloc(strlen(cpath) + 1);
- if (!newPath) {
+ newPath = strdup(cpath);
+ if (!newPath)
status = ENOMEM;
- } else {
- (void)strcpy(newPath, cpath);
- }
}
} else {
LocalizePathHead(&cpath, &relativeTo);
if (*cpath == '/') {
- newPath = (char *)malloc(strlen(cpath) + 1);
- if (!newPath) {
- status = ENOMEM;
- } else {
- strcpy(newPath, cpath);
- }
+ newPath = strdup(cpath);
} else {
- newPath = (char *)malloc(strlen(relativeTo) + 1 + strlen(cpath) + 1);
- if (!newPath) {
- status = ENOMEM;
- } else {
- sprintf(newPath, "%s/%s", relativeTo, cpath);
- }
+ asprintf(&newPath, "%s/%s", relativeTo, cpath);
}
+ if (newPath == NULL)
+ status = ENOMEM;
if (status == 0) {
FilepathNormalize(newPath);