[trunk] Start working on LFS support in JPIP code section

This commit is contained in:
Mathieu Malaterre 2012-03-26 09:48:53 +00:00
parent f3217ac170
commit 1cf1d6146c
4 changed files with 22 additions and 21 deletions

View File

@ -49,28 +49,28 @@
#endif /*SERVER*/ #endif /*SERVER*/
Byte_t * fetch_bytes( int fd, long offset, int size) Byte_t * fetch_bytes( int fd, OPJ_OFF_T offset, OPJ_SIZE_T size)
{ {
Byte_t *data; Byte_t *data;
if( lseek( fd, offset, SEEK_SET)==-1){ if( lseek( fd, offset, SEEK_SET)==-1){
fprintf( FCGI_stdout, "Reason: Target broken (fseek error)\r\n"); fprintf( FCGI_stdout, "Reason: Target broken (fseek error)\r\n");
fprintf( FCGI_stderr, "Error: error in fetch_bytes( %d, %ld, %d)\n", fd, offset, size); fprintf( FCGI_stderr, "Error: error in fetch_bytes( %d, %ld, %lu)\n", fd, offset, size);
return NULL; return NULL;
} }
data = (Byte_t *)malloc( size); data = (Byte_t *)malloc( size);
if( read( fd, data, size) != size){ if( (OPJ_SIZE_T)read( fd, data, size) != size){
free( data); free( data);
fprintf( FCGI_stdout, "Reason: Target broken (read error)\r\n"); fprintf( FCGI_stdout, "Reason: Target broken (read error)\r\n");
fprintf( FCGI_stderr, "Error: error in fetch_bytes( %d, %ld, %d)\n", fd, offset, size); fprintf( FCGI_stderr, "Error: error in fetch_bytes( %d, %ld, %lu)\n", fd, offset, size);
return NULL; return NULL;
} }
return data; return data;
} }
Byte_t fetch_1byte( int fd, long offset) Byte_t fetch_1byte( int fd, OPJ_OFF_T offset)
{ {
Byte_t code; Byte_t code;
@ -88,7 +88,7 @@ Byte_t fetch_1byte( int fd, long offset)
return code; return code;
} }
Byte2_t fetch_2bytebigendian( int fd, long offset) Byte2_t fetch_2bytebigendian( int fd, OPJ_OFF_T offset)
{ {
Byte_t *data; Byte_t *data;
Byte2_t code; Byte2_t code;
@ -103,7 +103,7 @@ Byte2_t fetch_2bytebigendian( int fd, long offset)
return code; return code;
} }
Byte4_t fetch_4bytebigendian( int fd, long offset) Byte4_t fetch_4bytebigendian( int fd, OPJ_OFF_T offset)
{ {
Byte_t *data; Byte_t *data;
Byte4_t code; Byte4_t code;
@ -118,7 +118,7 @@ Byte4_t fetch_4bytebigendian( int fd, long offset)
return code; return code;
} }
Byte8_t fetch_8bytebigendian( int fd, long offset) Byte8_t fetch_8bytebigendian( int fd, OPJ_OFF_T offset)
{ {
Byte_t *data; Byte_t *data;
Byte8_t code; Byte8_t code;
@ -136,7 +136,7 @@ Byte8_t fetch_8bytebigendian( int fd, long offset)
Byte2_t big2( Byte_t *buf) Byte2_t big2( Byte_t *buf)
{ {
return (((Byte2_t) buf[0]) << 8) + ((Byte2_t) buf[1]); return (Byte2_t)((((Byte2_t) buf[0]) << 8) + ((Byte2_t) buf[1]));
} }
Byte4_t big4( Byte_t *buf) Byte4_t big4( Byte_t *buf)
@ -159,7 +159,7 @@ void modify_4Bytecode( Byte4_t code, Byte_t *stream)
*(stream+3) = (Byte_t) (code & 0x000000ff); *(stream+3) = (Byte_t) (code & 0x000000ff);
} }
Byte8_t get_filesize( int fd) OPJ_OFF_T get_filesize( int fd)
{ {
struct stat sb; struct stat sb;
@ -168,5 +168,5 @@ Byte8_t get_filesize( int fd)
fprintf( FCGI_stderr, "Error: error in get_filesize( %d)\n", fd); fprintf( FCGI_stderr, "Error: error in get_filesize( %d)\n", fd);
return 0; return 0;
} }
return (Byte8_t)sb.st_size; return sb.st_size;
} }

View File

@ -31,6 +31,7 @@
#ifndef BYTE_MANAGER_H_ #ifndef BYTE_MANAGER_H_
#define BYTE_MANAGER_H_ #define BYTE_MANAGER_H_
#include <stddef.h>
#include "opj_stdint.h" #include "opj_stdint.h"
typedef uint8_t Byte_t; typedef uint8_t Byte_t;
typedef uint16_t Byte2_t; typedef uint16_t Byte2_t;
@ -45,7 +46,7 @@ typedef uint64_t Byte8_t;
* @param[in] size Byte length * @param[in] size Byte length
* @return pointer to the fetched data * @return pointer to the fetched data
*/ */
Byte_t * fetch_bytes( int fd, long offset, int size); Byte_t * fetch_bytes( int fd, OPJ_OFF_T offset, OPJ_SIZE_T size);
/** /**
@ -55,7 +56,7 @@ Byte_t * fetch_bytes( int fd, long offset, int size);
* @param[in] offset start Byte position * @param[in] offset start Byte position
* @return fetched codes * @return fetched codes
*/ */
Byte_t fetch_1byte( int fd, long offset); Byte_t fetch_1byte( int fd, OPJ_OFF_T offset);
/** /**
* fetch a 2-byte big endian Byte codes in file stream * fetch a 2-byte big endian Byte codes in file stream
@ -64,7 +65,7 @@ Byte_t fetch_1byte( int fd, long offset);
* @param[in] offset start Byte position * @param[in] offset start Byte position
* @return fetched codes * @return fetched codes
*/ */
Byte2_t fetch_2bytebigendian( int fd, long offset); Byte2_t fetch_2bytebigendian( int fd, OPJ_OFF_T offset);
/** /**
* fetch a 4-byte big endian Byte codes in file stream * fetch a 4-byte big endian Byte codes in file stream
@ -73,7 +74,7 @@ Byte2_t fetch_2bytebigendian( int fd, long offset);
* @param[in] offset start Byte position * @param[in] offset start Byte position
* @return fetched codes * @return fetched codes
*/ */
Byte4_t fetch_4bytebigendian( int fd, long offset); Byte4_t fetch_4bytebigendian( int fd, OPJ_OFF_T offset);
/** /**
* fetch a 8-byte big endian Byte codes in file stream * fetch a 8-byte big endian Byte codes in file stream
@ -82,7 +83,7 @@ Byte4_t fetch_4bytebigendian( int fd, long offset);
* @param[in] offset start Byte position * @param[in] offset start Byte position
* @return fetched codes * @return fetched codes
*/ */
Byte8_t fetch_8bytebigendian( int fd, long offset); Byte8_t fetch_8bytebigendian( int fd, OPJ_OFF_T offset);
/** /**
@ -123,6 +124,6 @@ void modify_4Bytecode( Byte4_t code, Byte_t *stream);
* @param[in] fd file discriptor * @param[in] fd file discriptor
* @return file size * @return file size
*/ */
Byte8_t get_filesize( int fd); OPJ_OFF_T get_filesize( int fd);
#endif /* !BYTE_MANAGER_H_ */ #endif /* !BYTE_MANAGER_H_ */

View File

@ -80,7 +80,6 @@ typedef char OPJ_CHAR;
typedef float OPJ_FLOAT32; typedef float OPJ_FLOAT32;
typedef double OPJ_FLOAT64; typedef double OPJ_FLOAT64;
typedef unsigned char OPJ_BYTE; typedef unsigned char OPJ_BYTE;
typedef size_t OPJ_SIZE_T;
#include "opj_stdint.h" #include "opj_stdint.h"
@ -93,9 +92,6 @@ typedef uint32_t OPJ_UINT32;
typedef int64_t OPJ_INT64; typedef int64_t OPJ_INT64;
typedef uint64_t OPJ_UINT64; typedef uint64_t OPJ_UINT64;
/* 64-bit file offset type */
typedef OPJ_INT64 OPJ_OFF_T;
/* Avoid compile-time warning because parameter is not used */ /* Avoid compile-time warning because parameter is not used */
#define OPJ_ARG_NOT_USED(x) (void)(x) #define OPJ_ARG_NOT_USED(x) (void)(x)

View File

@ -43,5 +43,9 @@ typedef unsigned __int64 uint64_t;
#error unsupported platform #error unsupported platform
#endif #endif
#endif #endif
typedef size_t OPJ_SIZE_T;
/* 64-bit file offset type */
typedef int64_t OPJ_OFF_T;
#endif /* OPJ_STDINT_H */ #endif /* OPJ_STDINT_H */