From ed0f307c89ce6e9c766a9405cee19f0cc60f1ce0 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Mon, 17 Apr 2023 19:25:05 -0400 Subject: ustar, main: Dynamically allocate member structs TODO: Save max strlen()s in first loop and printf() and free() in second loop. --- (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 84ff164..c3ab9f7 100644 --- a/src/main.c +++ b/src/main.c @@ -149,30 +149,31 @@ _opkg_opk_main_read_control(struct opkg_opk_ustar *ustar) static int _opkg_opk_main_list_members(struct opkg_opk_ustar *ustar) { - struct opkg_opk_ustar_member member; + struct opkg_opk_ustar_member *member; int ret; char mode[10]; char mtime[20]; while ((ret = opkg_opk_ustar_list(ustar, &member)) == OPKG_OPK_OK) { - if (member.mode & 00400) mode[0] = 'r'; else mode[0] = '-'; - if (member.mode & 00200) mode[1] = 'w'; else mode[1] = '-'; - if (member.mode & 00100) mode[2] = 'x'; else mode[2] = '-'; - if (member.mode & 04000) mode[2] = 's'; - if (member.mode & 00040) mode[3] = 'r'; else mode[3] = '-'; - if (member.mode & 00020) mode[4] = 'w'; else mode[4] = '-'; - if (member.mode & 00010) mode[5] = 'x'; else mode[5] = '-'; - if (member.mode & 02000) mode[5] = 's'; - if (member.mode & 00004) mode[6] = 'r'; else mode[6] = '-'; - if (member.mode & 00002) mode[7] = 'w'; else mode[7] = '-'; - if (member.mode & 00001) mode[8] = 'x'; else mode[8] = '-'; - if (member.mode & 01000) mode[8] = 't'; + if (member->mode & 00400) mode[0] = 'r'; else mode[0] = '-'; + if (member->mode & 00200) mode[1] = 'w'; else mode[1] = '-'; + if (member->mode & 00100) mode[2] = 'x'; else mode[2] = '-'; + if (member->mode & 04000) mode[2] = 's'; + if (member->mode & 00040) mode[3] = 'r'; else mode[3] = '-'; + if (member->mode & 00020) mode[4] = 'w'; else mode[4] = '-'; + if (member->mode & 00010) mode[5] = 'x'; else mode[5] = '-'; + if (member->mode & 02000) mode[5] = 's'; + if (member->mode & 00004) mode[6] = 'r'; else mode[6] = '-'; + if (member->mode & 00002) mode[7] = 'w'; else mode[7] = '-'; + if (member->mode & 00001) mode[8] = 'x'; else mode[8] = '-'; + if (member->mode & 01000) mode[8] = 't'; mode[9] = '\0'; strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", - localtime(&member.mtime)); + localtime(&member->mtime)); printf("%c%s %32s/%-32s %11d %s %s\n", - member.type, mode, member.uname, member.gname, - member.size, mtime, member.name); + member->type, mode, + member->uname, member->gname, + member->size, mtime, member->name); } if (ret == OPKG_OPK_ERROR) { fputs("Error: Failed to list data files\n", stderr); -- cgit v0.9.1