示例#1
0
int
main(int ac, const char** av)
{
  const unsigned PropHeaderSize = 5;
  const unsigned HeaderSize = 13;

  SizeT inSize = SYMBOL(end) - SYMBOL(start);

  int32_t outSize32 = read4(SYMBOL(start) + PropHeaderSize);
  SizeT outSize = outSize32;

  uint8_t* out = static_cast<uint8_t*>(malloc(outSize));
  if (out) {
    ISzAlloc allocator = { myAllocate, myFree };
    ELzmaStatus status = LZMA_STATUS_NOT_SPECIFIED;

    if (SZ_OK == LzmaDecode
        (out, &outSize, SYMBOL(start) + HeaderSize, &inSize, SYMBOL(start),
         PropHeaderSize, LZMA_FINISH_END, &status, &allocator))
    {
      const unsigned BufferSize = 1024;
      char buffer[BufferSize];
      const char* name = temporaryFileName(buffer, BufferSize);
      if (name) {
        int file = open(name, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, S_IRWXU);
        if (file != -1) {
          SizeT result = write(file, out, outSize);
          free(out);

          if (close(file) == 0 and outSize == result) {
            void* library = openLibrary(name);
            unlink(name);

            if (library) {
              void* main = librarySymbol(library, "avianMain");
              if (main) {
                int (*mainFunction)(const char*, int, const char**);
                memcpy(&mainFunction, &main, sizeof(void*));
                return mainFunction(name, ac, av);
              } else {
                fprintf(stderr, "unable to find main in %s", name);
              }
            } else {
              fprintf(stderr, "unable to load %s: %s\n", name,
                      libraryError(library));
            }
          } else {
            unlink(name);

            fprintf(stderr, "close or write failed; tried %d, got %d; %s\n",
                    static_cast<int>(outSize), static_cast<int>(result),
                    strerror(errno));
          }
        } else {
          fprintf(stderr, "unable to open %s\n", name);
        }
      } else {
        fprintf(stderr, "unable to make temporary file name\n");
      }
    } else {
      fprintf(stderr, "unable to decode LZMA data\n");
    }
  } else {
    fprintf(stderr, "unable to allocate buffer of size %d\n",
            static_cast<int>(outSize));
  }

  return -1;
}
示例#2
0
TemporarySettings::TemporarySettings(const QByteArray &content)
    : m_settings(new QSettings(temporaryFileName(content), QSettings::IniFormat))
{
}