Skip to content

Commit

Permalink
win32: use glob(3) to count packages (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
darealshinji authored and woodruffw committed Aug 19, 2016
1 parent 3520a94 commit 0564f12
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/plat/win32/detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <unistd.h>
#include <getopt.h>
#include <libgen.h>
#include <glob.h>

/* Windows-specific includes */
#include <Windows.h>
Expand Down Expand Up @@ -189,15 +190,23 @@ void detect_uptime(void)
*/
void detect_pkgs(void)
{
FILE *pkgs_file;
int packages = 0;

pkgs_file = popen("cygcheck -cd | wc -l", "r");
fscanf(pkgs_file, "%d", &packages);
packages -= 2;
pclose(pkgs_file);

snprintf(pkgs_str, MAX_STRLEN, "%d", packages);
const char *pattern;
glob_t globbuf;

#if defined(__MSYS__)
/* MSYS2 */
/* ignores: ALPM_DB_VERSION */
pattern = "/var/lib/pacman/local/*-*";
#else
/* Cygwin */
/* ignores: installed.db setup.rc timestamp */
pattern = "/etc/setup/*.lst.*";
#endif

globbuf.gl_offs = 1;
glob(pattern, GLOB_DOOFFS, NULL, &globbuf);
snprintf(pkgs_str, MAX_STRLEN, "%d", (int) globbuf.gl_pathc);
globfree(&globbuf);

return;
}
Expand Down

0 comments on commit 0564f12

Please sign in to comment.