[1.5][JPIP] added get_filesize()

This commit is contained in:
Kaori Hagihara 2011-11-16 16:13:11 +00:00
parent 544e8c9de0
commit 3459199eba
7 changed files with 36 additions and 43 deletions

View File

@ -31,9 +31,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <ctype.h>
#include "box_manager.h"
@ -174,12 +171,8 @@ box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, char TBox[
if( length==0){ // set the max length
struct stat sb;
if( fstat( fd, &sb) == -1){
fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
if( (length = get_filesize( fd) - offset) <= 0)
return NULL;
}
length = (Byte8_t)sb.st_size - offset;
}
pos = offset;

View File

@ -32,6 +32,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "byte_manager.h"
#ifdef SERVER
@ -153,3 +154,15 @@ void modify_4Bytecode( Byte4_t code, Byte_t *stream)
*(stream+2) = (Byte_t) ((Byte4_t)(code & 0x0000ff00) >> 8);
*(stream+3) = (Byte_t) (code & 0x000000ff);
}
Byte8_t get_filesize( int fd)
{
struct stat sb;
if( fstat( fd, &sb) == -1){
fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
fprintf( FCGI_stderr, "Error: error in get_filesize( %d)\n", fd);
return 0;
}
return (Byte8_t)sb.st_size;
}

View File

@ -124,4 +124,12 @@ Byte8_t big8( Byte_t *buf);
*/
void modify_4Bytecode( Byte4_t code, Byte_t *stream);
/**
* Get file size
*
* @param[in] fd file discriptor
* @return file size
*/
Byte8_t get_filesize( int fd);
#endif /* !BYTE_MANAGER_H_ */

View File

@ -31,9 +31,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include "bool.h"
@ -79,14 +76,12 @@ index_param_t * parse_jp2file( int fd)
box_param_t *cidx;
metadatalist_param_t *metadatalist;
boxlist_param_t *toplev_boxlist;
struct stat sb;
if( fstat( fd, &sb) == -1){
fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
return NULL;
}
Byte8_t filesize;
if( !(toplev_boxlist = get_boxstructure( fd, 0, sb.st_size))){
if( !(filesize = get_filesize( fd)))
return NULL;
if( !(toplev_boxlist = get_boxstructure( fd, 0, filesize))){
fprintf( FCGI_stderr, "Error: Not correctl JP2 format\n");
return NULL;
}

View File

@ -30,9 +30,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include "metadata_manager.h"
@ -67,14 +64,12 @@ metadatalist_param_t * const_metadatalist( int fd)
placeholderlist_param_t *phldlist;
placeholder_param_t *phld;
int idx;
struct stat sb;
if( fstat( fd, &sb) == -1){
fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
return NULL;
}
Byte8_t filesize;
if( !(toplev_boxlist = get_boxstructure( fd, 0, sb.st_size))){
if(!(filesize = get_filesize( fd)))
return NULL;
if( !(toplev_boxlist = get_boxstructure( fd, 0, filesize))){
fprintf( FCGI_stderr, "Error: Not correctl JP2 format\n");
return NULL;
}

View File

@ -494,15 +494,8 @@ void emit_body( message_param_t *msg, int fd)
{
Byte_t *data;
if( lseek( fd, msg->res_offset, SEEK_SET)==-1){
fprintf( FCGI_stderr, "Error: fseek in emit_body()\n");
return;
}
data = (Byte_t *)malloc( msg->length);
if( read( fd, data, msg->length) != msg->length){
free( data);
fprintf( FCGI_stderr, "Error: fread in emit_body()\n");
if( !(data = fetch_bytes( fd, msg->res_offset, msg->length))){
fprintf( FCGI_stderr, "Error: fetch_bytes in emit_body()\n");
return;
}

View File

@ -252,19 +252,15 @@ jpip_dec_param_t * init_jpipdecoder( bool jp2)
bool fread_jpip( char fname[], jpip_dec_param_t *dec)
{
int infd;
struct stat sb;
if(( infd = open( fname, O_RDONLY)) == -1){
fprintf( stderr, "file %s not exist\n", fname);
return false;
}
if( fstat( infd, &sb) == -1){
fprintf( stderr, "input file stream is broken\n");
if(!(dec->jpiplen = get_filesize(infd)))
return false;
}
dec->jpiplen = (Byte8_t)sb.st_size;
dec->jpipstream = (Byte_t *)malloc( dec->jpiplen);
if( read( infd, dec->jpipstream, dec->jpiplen) != dec->jpiplen){