Skip to content

Commit

Permalink
update to r.888,1a9b3de01a8a
Browse files Browse the repository at this point in the history
  • Loading branch information
filux committed Sep 4, 2016
1 parent 0bc0513 commit 86bb138
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ IF(CURSES_FOUND)
ADD_DEFINITIONS(-DHAVE_NCURSESW_CURSES_H)
ELSEIF(CURSES_HAVE_NCURSESW_H)
ADD_DEFINITIONS(-DHAVE_NCURSESW_H)
ELSEIF(CURSES_HAVE_CURSES_H)
ADD_DEFINITIONS(-DHAVE_CURSES_H)
ENDIF(CURSES_HAVE_NCURSESW_NCURSES_H)

OPTION(MOJOSETUP_GUI_NCURSES_STATIC "Statically link ncurses GUI" FALSE)
Expand Down
65 changes: 49 additions & 16 deletions archive_tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ static boolean MojoArchive_tar_enumerate(MojoArchive *ar)
#define TAR_TYPE_BLOCKDEV '4'
#define TAR_TYPE_DIRECTORY '5'
#define TAR_TYPE_FIFO '6'
#define TAR_TYPE_LONGLINK 'K'
#define TAR_TYPE_LONGNAME 'L'

static boolean is_ustar(const uint8 *block)
{
Expand Down Expand Up @@ -205,12 +207,15 @@ static const MojoArchiveEntry *MojoArchive_tar_enumNext(MojoArchive *ar)
if (info->input != NULL)
fatal("BUG: tar entry still open on new enumeration");

get_next_block:

if (!ar->io->seek(ar->io, info->nextEnumPos))
return NULL;

// Find a non-zero block of data. Tarballs have two 512 blocks filled with
// null bytes at the end of the archive, but you can cat tarballs
// together, so you can't treat them as EOF indicators. Just skip them.
zeroes = true;
while (zeroes)
{
if (ar->io->read(ar->io, block, sizeof (block)) != sizeof (block))
Expand All @@ -222,26 +227,51 @@ static const MojoArchiveEntry *MojoArchive_tar_enumNext(MojoArchive *ar)

ustar = is_ustar(block);

type = block[TAR_TYPE];

if ((type == TAR_TYPE_LONGNAME) || (type == TAR_TYPE_LONGLINK))
{
int64 filenameLength = octal_convert(&block[TAR_SIZE], TAR_SIZELEN);
char* filename = (char *) xmalloc(filenameLength + 1);
if (!ar->io->read(ar->io, filename, filenameLength))
return NULL;
filename[filenameLength] = '\0';

if (type == TAR_TYPE_LONGLINK)
ar->prevEnum.linkdest = filename;
else
ar->prevEnum.filename = filename;

info->nextEnumPos += 512 + filenameLength;
if (filenameLength % 512)
info->nextEnumPos += 512 - (filenameLength % 512);

goto get_next_block;
}

if (!ar->prevEnum.filename)
{
// We count on (scratch) being zeroed out here!
// prefix of filename is at the end for legacy compat.
if (ustar)
memcpy(scratch, &block[TAR_FNAMEPRE], TAR_FNAMEPRELEN);
fnamelen = strlen((const char *) scratch);
memcpy(&scratch[fnamelen], &block[TAR_FNAME], TAR_FNAMELEN);
fnamelen += strlen((const char *) &scratch[fnamelen]);

if (fnamelen == 0)
return NULL; // corrupt file. !!! FIXME: fatal() ?

ar->prevEnum.filename = xstrdup((const char *) scratch);
}

ar->prevEnum.perms = (uint16) octal_convert(&block[TAR_MODE], TAR_MODELEN);
ar->prevEnum.filesize = octal_convert(&block[TAR_SIZE], TAR_SIZELEN);
info->curFileStart = info->nextEnumPos + 512;
info->nextEnumPos += 512 + ar->prevEnum.filesize;
if (ar->prevEnum.filesize % 512)
info->nextEnumPos += 512 - (ar->prevEnum.filesize % 512);

// We count on (scratch) being zeroed out here!
// prefix of filename is at the end for legacy compat.
if (ustar)
memcpy(scratch, &block[TAR_FNAMEPRE], TAR_FNAMEPRELEN);
fnamelen = strlen((const char *) scratch);
memcpy(&scratch[fnamelen], &block[TAR_FNAME], TAR_FNAMELEN);
fnamelen += strlen((const char *) &scratch[fnamelen]);

if (fnamelen == 0)
return NULL; // corrupt file. !!! FIXME: fatal() ?

ar->prevEnum.filename = xstrdup((const char *) scratch);

type = block[TAR_TYPE];
if (type == 0) // some archivers do the file type as 0 instead of '0'.
type = TAR_TYPE_FILE;
Expand All @@ -265,9 +295,12 @@ static const MojoArchiveEntry *MojoArchive_tar_enumNext(MojoArchive *ar)
else if (type == TAR_TYPE_SYMLINK)
{
ar->prevEnum.type = MOJOARCHIVE_ENTRY_SYMLINK;
memcpy(scratch, &block[TAR_LINKNAME], TAR_LINKNAMELEN);
scratch[TAR_LINKNAMELEN] = '\0'; // just in case.
ar->prevEnum.linkdest = xstrdup((const char *) scratch);
if(!ar->prevEnum.linkdest)
{
memcpy(scratch, &block[TAR_LINKNAME], TAR_LINKNAMELEN);
scratch[TAR_LINKNAMELEN] = '\0'; // just in case.
ar->prevEnum.linkdest = xstrdup((const char *) scratch);
}
} // else if

return &ar->prevEnum;
Expand Down
12 changes: 10 additions & 2 deletions buildver.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
#error Please define APPREV in the build system.
#endif

#if (defined __GNUC__)
#if (defined __clang__)
# define VERSTR2(x) #x
# define VERSTR(x) VERSTR2(x)
# define COMPILERVER " " VERSTR(__clang_major__) "." VERSTR(__clang_minor__) "." VERSTR(__clang_patchlevel__)
#elif (defined __GNUC__)
# define VERSTR2(x) #x
# define VERSTR(x) VERSTR2(x)
# define COMPILERVER " " VERSTR(__GNUC__) "." VERSTR(__GNUC_MINOR__) "." VERSTR(__GNUC_PATCHLEVEL__)
Expand All @@ -50,7 +54,11 @@
#endif

#ifndef COMPILER
#if (defined __GNUC__)
#if (defined __clang__) && defined(__apple_build_version__) // Apple reports version differently than LLVM Clang, note difference here.
#define COMPILER "Apple Clang"
#elif (defined __clang__)
#define COMPILER "Clang"
#elif (defined __GNUC__)
#define COMPILER "GCC"
#elif (defined _MSC_VER)
#define COMPILER "Visual Studio"
Expand Down
2 changes: 2 additions & 0 deletions gui_ncurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ CREATE_MOJOGUI_ENTRY_POINT(ncurses)
#include <ncursesw/curses.h>
#elif defined(HAVE_NCURSESW_H)
#include <ncursesw.h>
#elif defined(HAVE_CURSES_H)
#include <curses.h>
#else
#error ncurses gui enabled, but no known header file found
#endif
Expand Down

0 comments on commit 86bb138

Please sign in to comment.