- /* absolute path, we don't do anything */
- if (path[0] == '/') {
- if (is_directory(path) == -1) {
- return NULL;
- }
- absolute_path = strdup(path);
- return absolute_path;
- }
-
- static char cwd[MAXPATHLEN];
- char *pwd = getcwd(cwd, sizeof(cwd));
- size_t len = strlen(pwd) + 1 + strlen(path) + 1;
- int has_trailing_backslash = (path[strlen(path)-1] == '/');
- if (!has_trailing_backslash)
- len++;
-
- absolute_path = (char*) malloc(sizeof(char) * len);
- memset(absolute_path, '\0', len);
- sprintf(absolute_path, "%s/%s", pwd, path);
-
- if(!has_trailing_backslash)
- absolute_path[len-2] = '/';
-
- if (is_directory(absolute_path) == -1) {
- strfree(absolute_path);
- return NULL;
- }
-
- return absolute_path;
+ // Append "/" and allocate new memory for the string
+ return strdup( strcat( absolute_path, "/" ) );