Replace spaces with tabs in resolve_path

This commit is contained in:
Mykyta Holubakha 2017-05-11 19:38:32 +03:00
parent 93cf21fb9a
commit f470fa58a3

View file

@ -124,38 +124,38 @@ uint32_t parse_color(const char *color) {
} }
char* resolve_path(const char* path) { char* resolve_path(const char* path) {
struct stat sb; struct stat sb;
ssize_t r; ssize_t r;
int i; int i;
char *current = NULL; char *current = NULL;
char *resolved = NULL; char *resolved = NULL;
if(!(current = strdup(path))) { if(!(current = strdup(path))) {
return NULL; return NULL;
} }
for (i = 0; i < 16; ++i) { for (i = 0; i < 16; ++i) {
if (lstat(current, &sb) == -1) { if (lstat(current, &sb) == -1) {
goto failed; goto failed;
} }
if((sb.st_mode & S_IFMT) != S_IFLNK) { if((sb.st_mode & S_IFMT) != S_IFLNK) {
return current; return current;
} }
if (!(resolved = malloc(sb.st_size + 1))) { if (!(resolved = malloc(sb.st_size + 1))) {
goto failed; goto failed;
} }
r = readlink(current, resolved, sb.st_size); r = readlink(current, resolved, sb.st_size);
if (r == -1 || r > sb.st_size) { if (r == -1 || r > sb.st_size) {
goto failed; goto failed;
} }
resolved[r] = '\0'; resolved[r] = '\0';
free(current); free(current);
current = strdup(resolved); current = strdup(resolved);
free(resolved); free(resolved);
resolved = NULL; resolved = NULL;
} }
failed: failed:
free(resolved); free(resolved);
free(current); free(current);
return NULL; return NULL;
} }