[1.5][JPIP] added get_filesize()
This commit is contained in:
parent
544e8c9de0
commit
3459199eba
|
@ -31,9 +31,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "box_manager.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
|
if( length==0){ // set the max length
|
||||||
struct stat sb;
|
if( (length = get_filesize( fd) - offset) <= 0)
|
||||||
if( fstat( fd, &sb) == -1){
|
|
||||||
fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
length = (Byte8_t)sb.st_size - offset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = offset;
|
pos = offset;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include "byte_manager.h"
|
#include "byte_manager.h"
|
||||||
|
|
||||||
#ifdef SERVER
|
#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+2) = (Byte_t) ((Byte4_t)(code & 0x0000ff00) >> 8);
|
||||||
*(stream+3) = (Byte_t) (code & 0x000000ff);
|
*(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;
|
||||||
|
}
|
||||||
|
|
|
@ -124,4 +124,12 @@ Byte8_t big8( Byte_t *buf);
|
||||||
*/
|
*/
|
||||||
void modify_4Bytecode( Byte4_t code, Byte_t *stream);
|
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_ */
|
#endif /* !BYTE_MANAGER_H_ */
|
||||||
|
|
|
@ -31,9 +31,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "bool.h"
|
#include "bool.h"
|
||||||
|
@ -79,14 +76,12 @@ index_param_t * parse_jp2file( int fd)
|
||||||
box_param_t *cidx;
|
box_param_t *cidx;
|
||||||
metadatalist_param_t *metadatalist;
|
metadatalist_param_t *metadatalist;
|
||||||
boxlist_param_t *toplev_boxlist;
|
boxlist_param_t *toplev_boxlist;
|
||||||
struct stat sb;
|
Byte8_t filesize;
|
||||||
|
|
||||||
if( fstat( fd, &sb) == -1){
|
|
||||||
fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
fprintf( FCGI_stderr, "Error: Not correctl JP2 format\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,6 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "metadata_manager.h"
|
#include "metadata_manager.h"
|
||||||
|
|
||||||
|
@ -67,14 +64,12 @@ metadatalist_param_t * const_metadatalist( int fd)
|
||||||
placeholderlist_param_t *phldlist;
|
placeholderlist_param_t *phldlist;
|
||||||
placeholder_param_t *phld;
|
placeholder_param_t *phld;
|
||||||
int idx;
|
int idx;
|
||||||
struct stat sb;
|
Byte8_t filesize;
|
||||||
|
|
||||||
if( fstat( fd, &sb) == -1){
|
|
||||||
fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
fprintf( FCGI_stderr, "Error: Not correctl JP2 format\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -494,15 +494,8 @@ void emit_body( message_param_t *msg, int fd)
|
||||||
{
|
{
|
||||||
Byte_t *data;
|
Byte_t *data;
|
||||||
|
|
||||||
if( lseek( fd, msg->res_offset, SEEK_SET)==-1){
|
if( !(data = fetch_bytes( fd, msg->res_offset, msg->length))){
|
||||||
fprintf( FCGI_stderr, "Error: fseek in emit_body()\n");
|
fprintf( FCGI_stderr, "Error: fetch_bytes 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");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -252,19 +252,15 @@ jpip_dec_param_t * init_jpipdecoder( bool jp2)
|
||||||
bool fread_jpip( char fname[], jpip_dec_param_t *dec)
|
bool fread_jpip( char fname[], jpip_dec_param_t *dec)
|
||||||
{
|
{
|
||||||
int infd;
|
int infd;
|
||||||
struct stat sb;
|
|
||||||
|
|
||||||
if(( infd = open( fname, O_RDONLY)) == -1){
|
if(( infd = open( fname, O_RDONLY)) == -1){
|
||||||
fprintf( stderr, "file %s not exist\n", fname);
|
fprintf( stderr, "file %s not exist\n", fname);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( fstat( infd, &sb) == -1){
|
if(!(dec->jpiplen = get_filesize(infd)))
|
||||||
fprintf( stderr, "input file stream is broken\n");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
dec->jpiplen = (Byte8_t)sb.st_size;
|
|
||||||
|
|
||||||
dec->jpipstream = (Byte_t *)malloc( dec->jpiplen);
|
dec->jpipstream = (Byte_t *)malloc( dec->jpiplen);
|
||||||
|
|
||||||
if( read( infd, dec->jpipstream, dec->jpiplen) != dec->jpiplen){
|
if( read( infd, dec->jpipstream, dec->jpiplen) != dec->jpiplen){
|
||||||
|
|
Loading…
Reference in New Issue