These functions cannot fail, so return void.
[oweals/opkg-lede.git] / libopkg / opkg_cmd.c
index 2d1fc703d8375e7611aa79e06b99fff7e6719d7e..807777e56870f0ef7542bc56983d737f51ec5b8d 100644 (file)
@@ -195,7 +195,7 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
      failures = 0;
 
 
-     tmp = strdup ("/tmp/opkg.XXXXXX");
+     tmp = xstrdup("/tmp/opkg.XXXXXX");
 
      if (mkdtemp (tmp) == NULL) {
         perror ("mkdtemp");
@@ -303,18 +303,11 @@ typedef struct opkg_intercept *opkg_intercept_t;
 static opkg_intercept_t opkg_prep_intercepts(opkg_conf_t *conf)
 {
     opkg_intercept_t ctx;
-    char *oldpath;
     char *newpath;
     int gen;
 
-    ctx = calloc (1, sizeof (*ctx));
-    oldpath = getenv ("PATH");
-    if (oldpath) {
-        ctx->oldpath = strdup (oldpath);
-    } else {
-        ctx->oldpath = 0;
-    }
-
+    ctx = xcalloc(1, sizeof (*ctx));
+    ctx->oldpath = xstrdup(getenv("PATH"));
 
     sprintf_alloc (&newpath, "%s/opkg/intercept:%s", DATADIR, ctx->oldpath);
     setenv ("PATH", newpath, 1);
@@ -345,8 +338,6 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx)
     if (ctx->oldpath) {
         setenv ("PATH", ctx->oldpath, 1);
         free (ctx->oldpath);
-    } else {
-        unsetenv("PATH"); 
     }
 
     dir = opendir (ctx->statedir);
@@ -763,7 +754,6 @@ static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int in
      pkg_vec_t *available;
      pkg_t *pkg;
      char *pkg_name = NULL;
-     char *pkg_info; 
 
      if (argc > 0) {
          pkg_name = argv[0];
@@ -781,19 +771,16 @@ static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int in
               continue;
          }
 
-         pkg_info = pkg_formatted_info(pkg);
-          if (pkg_info == NULL)
-                 break;
-
-          printf("%s\n", pkg_info);
-          free(pkg_info);
+         pkg_formatted_info(stdout, pkg);
 
          if (conf->verbosity > 1) {
               conffile_list_elt_t *iter;
               for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
                    conffile_t *cf = (conffile_t *)iter->data;
                    int modified = conffile_has_been_modified(conf, cf);
-                   opkg_message(conf, OPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
+                   if (cf->value)
+                       opkg_message(conf, OPKG_NOTICE,
+                               "conffile=%s md5sum=%s modified=%d\n",
                                 cf->name, cf->value, modified);
               }
          }
@@ -890,7 +877,7 @@ static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv)
         available = pkg_vec_alloc();
         pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
         for (i=0; i < argc; i++) {
-           pkg_name = calloc(1, strlen(argv[i])+2);
+           pkg_name = xcalloc(1, strlen(argv[i])+2);
            strcpy(pkg_name,argv[i]);
            for (a=0; a < available->len; a++) {
                pkg = available->pkgs[a];