Skip to content

Commit 3a2ae81

Browse files
committed
bin/xbps-alternatives: initialize xbps_handle directly
1 parent 67edbed commit 3a2ae81

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

bin/xbps-alternatives/main.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -273,20 +273,22 @@ main(int argc, char **argv)
273273
{ "version", no_argument, NULL, 'V' },
274274
{ NULL, 0, NULL, 0 }
275275
};
276-
struct xbps_handle xh;
277-
const char *confdir, *rootdir, *group, *pkg;
278-
int c, rv, flags = 0;
276+
struct xbps_handle xh = { 0 };
277+
const char *group, *pkg;
278+
int c, rv;
279279
bool list_mode = false, set_mode = false, repo_mode = false;
280280

281-
confdir = rootdir = group = pkg = NULL;
281+
group = pkg = NULL;
282+
283+
xh.state_cb = state_cb;
282284

283285
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
284286
switch (c) {
285287
case 'C':
286-
confdir = optarg;
288+
xbps_strlcpy(xh.confdir, optarg, sizeof(xh.confdir));
287289
break;
288290
case 'd':
289-
flags |= XBPS_FLAG_DEBUG;
291+
xh.flags |= XBPS_FLAG_DEBUG;
290292
break;
291293
case 'g':
292294
group = optarg;
@@ -295,7 +297,7 @@ main(int argc, char **argv)
295297
usage(false);
296298
/* NOTREACHED */
297299
case 'i':
298-
flags |= XBPS_FLAG_IGNORE_CONF_REPOS;
300+
xh.flags |= XBPS_FLAG_IGNORE_CONF_REPOS;
299301
break;
300302
case 'l':
301303
list_mode = true;
@@ -311,10 +313,10 @@ main(int argc, char **argv)
311313
repo_mode = true;
312314
break;
313315
case 'r':
314-
rootdir = optarg;
316+
xbps_strlcpy(xh.rootdir, optarg, sizeof(xh.rootdir));
315317
break;
316318
case 'v':
317-
flags |= XBPS_FLAG_VERBOSE;
319+
xh.flags |= XBPS_FLAG_VERBOSE;
318320
break;
319321
case 'V':
320322
printf("%s\n", XBPS_RELVER);
@@ -337,15 +339,6 @@ main(int argc, char **argv)
337339
usage(true);
338340
}
339341

340-
memset(&xh, 0, sizeof(xh));
341-
xh.state_cb = state_cb;
342-
if (rootdir)
343-
xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
344-
if (confdir)
345-
xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
346-
347-
xh.flags = flags;
348-
349342
/* initialize xbps */
350343
if ((rv = xbps_init(&xh)) != 0) {
351344
xbps_error_printf("Failed to initialize libxbps: %s\n",

0 commit comments

Comments
 (0)