aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar madblobfish <madblobfish@users.noreply.github.com>2018-10-27 17:48:11 +0200
committerLibravatar madblobfish <madblobfish@users.noreply.github.com>2018-10-31 13:04:08 +0100
commit1f23ec2d050976d6f2dafd545302e9be3f821c81 (patch)
tree25c6eb676df0e90303dd659f03364d77c4febe15
parentMerge pull request #3033 from RyanDwyer/remove-movement-direction (diff)
downloadsway-1f23ec2d050976d6f2dafd545302e9be3f821c81.tar.gz
sway-1f23ec2d050976d6f2dafd545302e9be3f821c81.tar.zst
sway-1f23ec2d050976d6f2dafd545302e9be3f821c81.zip
Revert "Add resolve_path() to utils"
-rw-r--r--common/util.c37
-rw-r--r--include/util.h9
2 files changed, 0 insertions, 46 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
142char* 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
173failed:
174 free(resolved);
175 free(current);
176 return NULL;
177}
diff --git a/include/util.h b/include/util.h
index c39c92b1..56ca2eb8 100644
--- a/include/util.h
+++ b/include/util.h
@@ -59,13 +59,4 @@ uint32_t parse_color(const char *color);
59 */ 59 */
60bool parse_boolean(const char *boolean, bool current); 60bool parse_boolean(const char *boolean, bool current);
61 61
62/**
63 * Given a path string, recurseively resolves any symlinks to their targets
64 * (which may be a file, directory) and returns the result.
65 * argument is returned. Caller must free the returned buffer.
66 * If an error occures, if the path does not exist or if the path corresponds
67 * to a dangling symlink, NULL is returned.
68 */
69char* resolve_path(const char* path);
70
71#endif 62#endif