📄 tmunpackarch.c
字号:
/*
* +-------------------------------------------------------------------+
* | Copyright (c) 1995,2000 TriMedia Technologies Inc. |
* | |
* | This software is furnished under a license and may only be used |
* | and copied in accordance with the terms and conditions of such a |
* | license and with the inclusion of this copyright notice. This |
* | software or any other copies of this software may not be provided |
* | or otherwise made available to any other person. The ownership |
* | and title of this software is not transferred. |
* | |
* | The information in this software is subject to change without |
* | any prior notice and should not be construed as a commitment by |
* | TriMedia Technologies. |
* | |
* | This code and information is provided "as is" without any |
* | warranty of any kind, either expressed or implied, including but |
* | not limited to the implied warranties of merchantability and/or |
* | fitness for any particular purpose. |
* +-------------------------------------------------------------------+
*/
/*------------------------------ Includes ------------------------------------*/
#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
#include <dirent.h>
#include "unistd.h"
#include "errno.h"
#include "tmpackedarch.h"
#ifdef _VERBOSE_
#include <stdio.h>
#endif
#include "tmlib/tmFlash.h"
#ifdef _COMPRESSION_
#include "tmlib/zlib.h"
#endif
#ifndef _VERBOSE_
int printf(const char* format, ...){
return 0;
}
#endif
/******************************************************************************/
void WriteArchieve(void)
{
Int count = 0;
Int32 fo;
UInt32 lv_write;
#ifdef _COMPRESSION_
int zlib_ret;
uint u_size = 0;
void *un_comp_mem;
#endif
/* while elements to write to file system */
while (count < FDLIST_ARRAY_LENGTH)
{
/* if this entry is a file */
if (FDList[count].File_Dir == File){
errno = 0;
/* create file */
fo = open(FDList[count].Pathname,O_CREAT|O_WRONLY|O_BINARY);
if(fo == -1)
printf("Error opening %s %d\n",FDList[count].Pathname,errno);
#ifdef _COMPRESSION_
/* allocate memory for uncompressed blocks */
un_comp_mem = (void *)malloc(FDList[count].FileLength);
if(un_comp_mem == NULL){
printf("Error allocating memory for uncompressed memory\n");
}
u_size = FDList[count].FileLength;
/* uncompress data */
zlib_ret = uncompress(un_comp_mem, &u_size,FDList[count].Data, FDList[count].CompLen );
if(zlib_ret != Z_OK || u_size != FDList[count].FileLength){
printf("Error decompressing %s %d %d\n", FDList[count].Pathname,zlib_ret,u_size);
printf("Usize %d Csize %d\n", FDList[count].FileLength,FDList[count].CompLen);
}
/*write data to file */
lv_write = write(fo,un_comp_mem,u_size);
if(lv_write != u_size)
printf("Error writing %s %d %d\n", FDList[count].Pathname,lv_write,u_size);
free(un_comp_mem);
#else
/* write to file */
lv_write = write(fo,FDList[count].Data,FDList[count].FileLength);
if(lv_write != FDList[count].FileLength)
printf("Error writing %s %d %d %d\n",
FDList[count].Pathname,lv_write,FDList[count].FileLength,errno);
#endif
/* close file */
close(fo);
printf(" F %s\n",FDList[count].Pathname);
}
/* else this entry is a directory */
else{
/* make directory*/
mkdir(FDList[count].Pathname,0x1FF);
printf(" D %s\n",FDList[count].Pathname);
}
count++;
}
}
/*------------------------------- Event handler ------------------------------*/
static Int nrof_write_errors;
static void event_handler(FlashEvent);
static EventHandler old_event_handler= event_handler;
static void event_handler(FlashEvent event)
{
if (event == FlashWriteError) {
nrof_write_errors++;
} else
if (event == FlashFull) {
fprintf(stderr,"Flash full\n");
exit(-1);
} else
if (event == FlashDangerousWriteError) {
fprintf(stderr,"Dangerous write error\n");
exit(-1);
}
}
/******************************************************************************/
Int main()
{
printf("----------- Starting tmSEA Application -----------\n");
old_event_handler= Flash_install_event_handler( event_handler );
WriteArchieve();
printf("------------- Application Terminated ------------\n");
exit (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -