diff options
author | 2018-10-31 14:48:17 +0100 | |
---|---|---|
committer | 2018-10-31 14:48:17 +0100 | |
commit | e9c136b0eece9369622baaca9656307a919b3547 (patch) | |
tree | 8cfcd8e119b0fc546d75a6d18dbe53f705e4a63c /common/util.c | |
parent | Update ISSUE_TEMPLATE.md (diff) | |
parent | Revert "Add resolve_path() to utils" (diff) | |
download | sway-e9c136b0eece9369622baaca9656307a919b3547.tar.gz sway-e9c136b0eece9369622baaca9656307a919b3547.tar.zst sway-e9c136b0eece9369622baaca9656307a919b3547.zip |
Merge pull request #3027 from madblobfish/remove-resolve_path
Remove resolve_path() from utils
Diffstat (limited to 'common/util.c')
-rw-r--r-- | common/util.c | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/common/util.c b/common/util.c index 467aa4b5..78d46a2a 100644 --- a/common/util.c +++ b/common/util.c | |||
@@ -138,40 +138,3 @@ bool parse_boolean(const char *boolean, bool current) { | |||
138 | // All other values are false to match i3 | 138 | // All other values are false to match i3 |
139 | return false; | 139 | return false; |
140 | } | 140 | } |
141 | |||
142 | char* resolve_path(const char* path) { | ||
143 | struct stat sb; | ||
144 | ssize_t r; | ||
145 | int i; | ||
146 | char *current = NULL; | ||
147 | char *resolved = NULL; | ||
148 | |||
149 | if(!(current = strdup(path))) { | ||
150 | return NULL; | ||
151 | } | ||
152 | for (i = 0; i < 16; ++i) { | ||
153 | if (lstat(current, &sb) == -1) { | ||
154 | goto failed; | ||
155 | } | ||
156 | if((sb.st_mode & S_IFMT) != S_IFLNK) { | ||
157 | return current; | ||
158 | } | ||
159 | if (!(resolved = malloc(sb.st_size + 1))) { | ||
160 | goto failed; | ||
161 | } | ||
162 | r = readlink(current, resolved, sb.st_size); | ||
163 | if (r == -1 || r > sb.st_size) { | ||
164 | goto failed; | ||
165 | } | ||
166 | resolved[r] = '\0'; | ||
167 | free(current); | ||
168 | current = strdup(resolved); | ||
169 | free(resolved); | ||
170 | resolved = NULL; | ||
171 | } | ||
172 | |||
173 | failed: | ||
174 | free(resolved); | ||
175 | free(current); | ||
176 | return NULL; | ||
177 | } | ||