4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
24 #include <sys/types.h>
36 struct stringset paths;
39 struct appfwk *appfwk_create()
41 struct appfwk *appfwk = malloc(sizeof * appfwk);
46 appfwk->paths.count = 0;
47 appfwk->paths.strings = NULL;
52 void appfwk_addref(struct appfwk *appfwk)
58 void appfwk_unref(struct appfwk *appfwk)
61 if (!--appfwk->refcount) {
62 while (appfwk->paths.count)
63 free(appfwk->paths.strings[--appfwk->paths.count]);
68 int appfwk_add_root(struct appfwk *appfwk, const char *path)
73 r = realpath(path, NULL);
77 /* avoiding duplications */
78 n = appfwk->paths.count;
79 roots = appfwk->paths.strings;
80 for (i = 0 ; i < n ; i++)
81 if (!strcmp(r, roots[i])) {
87 roots = realloc(roots, (n + 1) * sizeof(roots[0]));
94 appfwk->paths.strings = roots;
95 appfwk->paths.count = n;
106 int (*callback)(struct wgt *wgt, void *data);
110 struct appfwk_enumerate_applications_context {
118 inline int testd(int dirfd, struct dirent *e)
120 return e->d_name[0] != '.' || (e->d_name[1] && (e->d_name[1] != '.' || e->d_name[2]));
124 static int aea3(int dirfd, struct aea *aea)
126 printf("aea3 %s *** %s *** %s\n", aea->path, aea->appver, aea->ver);
130 static int aea2(int dirfd, struct aea *aea)
134 struct dirent entry, *e;
136 dir = fdopendir(dirfd);
140 aea->version = entry.d_name;
142 rc = readdir_r(dir, &entry, &e);
144 if (testd(dirfd, &entry)) {
145 fd = openat(dirfd, entry.d_name, O_DIRECTORY|O_RDONLY);
147 strcpy(aea->ver, entry.d_name);
152 rc = readdir_r(dir, &entry, &e);
158 static int aea1(int dirfd, struct aea *aea)
162 struct dirent entry, *e;
164 dir = fdopendir(dirfd);
168 aea->appid = entry.d_name;
170 rc = readdir_r(dir, &entry, &e);
172 if (testd(dirfd, &entry)) {
173 fd = openat(dirfd, entry.d_name, O_DIRECTORY|O_RDONLY);
175 aea->ver = stpcpy(aea->appver, entry.d_name);
181 rc = readdir_r(dir, &entry, &e);
187 int appfwk_enumerate_applications(struct appfwk *appfwk, int (*callback)(struct wgt *wgt, void *data), void *data)
189 int rc, iroot, nroots;
192 char buffer[PATH_MAX];
195 aea.callback = callback;
199 nroots = appfwk->paths.count;
200 roots = appfwk->paths.strings;
201 for (iroot = 0 ; iroot < nroots ; iroot++) {
202 aea.root = roots[iroot];
203 fd = openat(AT_FDCWD, aea.root, O_DIRECTORY|O_RDONLY);
205 aea.appver = stpcpy(buffer, aea.root);
222 rfd = openat(rfd, pathname, O_PATH|O_DIRECTORY);