62#define WizardMaxBlobExtent (8*8192)
63# if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
64# define MAP_ANONYMOUS MAP_ANON
66#if !defined(MAP_FAILED)
67#define MAP_FAILED ((void *) -1)
89#if defined(WIZARDSTOOLKIT_ZLIB_DELEGATE)
94#if defined(WIZARDSTOOLKIT_BZLIB_DELEGATE)
193 assert(blob_info != (
BlobInfo *) NULL);
202 blob_info->
data=(
unsigned char *) blob;
231 if ((blob_info->
status == 0) && (errno != 0))
244 assert(blob_info != (
BlobInfo *) NULL);
254 switch (blob_info->
type)
262 if ((status != 0) && (ferror(blob_info->
file_info.
file) != 0))
268#if defined(WIZARDSTOOLKIT_ZLIB_DELEGATE)
270 (void) gzerror(blob_info->
file_info.gzfile,&status);
278#if defined(WIZARDSTOOLKIT_BZLIB_DELEGATE)
280 (void) BZ2_bzerror(blob_info->
file_info.bzfile,&status);
299 switch (blob_info->
type)
316#if defined(WIZARDSTOOLKIT_HAVE_POPEN)
325#if defined(WIZARDSTOOLKIT_ZLIB_DELEGATE)
326 status=gzclose(blob_info->
file_info.gzfile);
334#if defined(WIZARDSTOOLKIT_BZLIB_DELEGATE)
335 BZ2_bzclose(blob_info->
file_info.bzfile);
374 assert(blob_info != (
BlobInfo *) NULL);
427 assert(blob_info != (
BlobInfo *) NULL);
433 blob_info->
data=(
unsigned char *) NULL;
443 data=blob_info->
data;
444 blob_info->
data=(
unsigned char *) NULL;
473 assert(blob_info != (
BlobInfo *) NULL);
478 switch (blob_info->
type)
497#if defined(WIZARDSTOOLKIT_BZLIB_DELEGATE)
502 (void) BZ2_bzerror(blob_info->
file_info.bzfile,&status);
510 return((
int) blob_info->
eof);
567 assert(filename != (
const char *) NULL);
572 if (strcmp(filename,
"-") != 0)
577 "unable to open file `%s': %s",filename,strerror(errno));
582 if ((file == fileno(stdin)) || (offset < 0) ||
596 if ((fstat(file,&file_info) == 0) && (file_info.st_size > 0))
599 for (i=0; blob != (
unsigned char *) NULL; i+=count)
601 count=read(file,blob+i,quantum);
608 if (~((
size_t) i) < (quantum+1))
615 if ((
size_t) (i+count) >= extent)
618 if (close(file) == -1)
620 "unable to close file `%s': %s",filename,strerror(errno));
621 if (blob == (
unsigned char *) NULL)
624 "memory allocation failed: `%s'",filename);
627 *length=
Min(i+count,extent);
631 *length=
Min((
size_t) offset,extent);
632 blob=(
unsigned char *) NULL;
636 if (blob == (
unsigned char *) NULL)
638 if (close(file) == -1)
641 "unable to close file `%s': %s",filename,strerror(errno));
642 return((
unsigned char *) NULL);
645 "memory allocation failed `%s'",strerror(errno));
649 if (map != (
void *) NULL)
651 (void) memcpy(blob,map,*length);
654 "unable to unmap blob `%s': %s",filename,strerror(errno));
664 if (lseek(file,0,SEEK_SET) < 0)
666 "unable to seek blob `%s': %s",filename,strerror(errno));
667 for (i=0; i < *length; i+=count)
669 count=read(file,blob+i,
Min(*length-i,(
size_t) SSIZE_MAX));
679 if (close(file) == -1)
681 "unable to close file `%s': %s",filename,strerror(errno));
684 "unable to read file `%s'",filename);
688 if (close(file) == -1)
690 "unable to close file `%s': %s",filename,strerror(errno));
691 blob[*length]=(
unsigned char)
'\0';
719 assert(blob_info != (
BlobInfo *) NULL);
750 assert(blob_info != (
BlobInfo *) NULL);
751 (void) memset(blob_info,0,
sizeof(*blob_info));
789 if (path == (
const char *) NULL)
794 (void) memset(attributes,0,
sizeof(
struct stat));
805 assert(blob_info != (
BlobInfo *) NULL);
810 switch (blob_info->
type)
815 extent=blob_info->
size;
825 extent=blob_info->
size;
827 if (file_descriptor == -1)
829 if (fstat(file_descriptor,&blob_info->
properties) == 0)
835 extent=blob_info->
size;
841#if defined(WIZARDSTOOLKIT_ZLIB_DELEGATE)
884 assert(blob_info != (
BlobInfo *) NULL);
923#if defined(WIZARDSTOOLKIT_HAVE_MMAP_FILEIO)
936#if defined(MAP_ANONYMOUS)
937 flags|=MAP_ANONYMOUS;
939 return((
unsigned char *) NULL);
947 protection=PROT_READ;
953 protection=PROT_WRITE;
959 protection=PROT_READ | PROT_WRITE;
964#if !defined(WIZARDSTOOLKIT_HAVE_HUGEPAGES) || !defined(MAP_HUGETLB)
965 map=(
unsigned char *) mmap((
char *) NULL,length,protection,flags,file,
968 map=(
unsigned char *) mmap((
char *) NULL,length,protection,flags |
969 MAP_HUGETLB,file,(off_t) offset);
971 map=(
unsigned char *) mmap((
char *) NULL,length,protection,flags,file,
975 return((
unsigned char *) NULL);
978 return((
unsigned char *) NULL);
1026 assert(filename != (
const char *) NULL);
1030 if (blob_info == (
BlobInfo *) NULL)
1033 "memory allocation failed: `%s'",filename);
1039 default: type=
"r";
break;
1052#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
1053 if (strchr(type,
'b') != (
char *) NULL)
1071 "unable to open file `%s': %s",filename,strerror(errno));
1075#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
1076 if (strchr(type,
'b') != (
char *) NULL)
1083#if defined(WIZARDSTOOLKIT_HAVE_POPEN)
1084 if (*filename ==
'|')
1094 (void) signal(SIGPIPE,SIG_IGN);
1102 "unable to open file `%s': %s",filename,strerror(errno));
1113#if defined(S_ISFIFO)
1120 "unable to open file `%s': %s",filename,strerror(errno));
1144#if defined(WIZARDSTOOLKIT_HAVE_SETVBUF)
1145 (void) setvbuf(blob_info->
file_info.
file,(
char *) NULL,(int) _IOFBF,
1148 (void) memset(magick,0,
sizeof(magick));
1149 count=(ssize_t) fread(magick,1,
sizeof(magick),
1151 (void) fseek(blob_info->
file_info.
file,-((off_t) count),SEEK_CUR);
1152#if defined(WIZARDSTOOLKIT_POSIX_SUPPORT)
1156 " read %.20g magic header bytes",(double) count);
1157#if defined(WIZARDSTOOLKIT_ZLIB_DELEGATE)
1158 if ((compress !=
WizardFalse) && ((int) magick[0] == 0x1F) &&
1159 ((int) magick[1] == 0x8B) && ((int) magick[2] == 0x08))
1164 blob_info->
file_info.gzfile=gzopen(filename,
"rb");
1165 if (blob_info->
file_info.gzfile != (gzFile) NULL)
1169#if defined(WIZARDSTOOLKIT_BZLIB_DELEGATE)
1171 (strncmp((
char *) magick,
"BZh",3) == 0))
1176 blob_info->
file_info.bzfile=BZ2_bzopen(filename,
"r");
1177 if (blob_info->
file_info.bzfile != (BZFILE *) NULL)
1181 length=(size_t) blob_info->
properties.st_size;
1191 if (blob == (
void *) NULL)
1212#if defined(WIZARDSTOOLKIT_ZLIB_DELEGATE)
1217 blob_info->
file_info.gzfile=gzopen(filename,
"wb");
1218 if (blob_info->
file_info.gzfile != (gzFile) NULL)
1223#if defined(WIZARDSTOOLKIT_BZLIB_DELEGATE)
1226 blob_info->
file_info.bzfile=BZ2_bzopen(filename,
"w");
1227 if (blob_info->
file_info.bzfile != (BZFILE *) NULL)
1237#if defined(WIZARDSTOOLKIT_HAVE_SETVBUF)
1238 (void) setvbuf(blob_info->
file_info.
file,(
char *) NULL,(int) _IOFBF,
1250 "unable to open file `%s': %s",filename,strerror(errno));
1298 assert(blob_info != (
BlobInfo *) NULL);
1300 assert(blob_info != (
BlobInfo *) NULL);
1304 assert(data != (
void *) NULL);
1306 q=(
unsigned char *) data;
1307 switch (blob_info->
type)
1319 count=(ssize_t) fread(q,1,length,blob_info->
file_info.
file);
1327 *q++=(
unsigned char) c;
1335 *q++=(
unsigned char) c;
1343 *q++=(
unsigned char) c;
1351 *q++=(
unsigned char) c;
1361#if defined(WIZARDSTOOLKIT_ZLIB_DELEGATE)
1366 count=(ssize_t) gzread(blob_info->
file_info.gzfile,q,(
unsigned int)
1375 *q++=(
unsigned char) c;
1383 *q++=(
unsigned char) c;
1391 *q++=(
unsigned char) c;
1399 *q++=(
unsigned char) c;
1410#if defined(WIZARDSTOOLKIT_BZLIB_DELEGATE)
1411 count=(ssize_t) BZ2_bzread(blob_info->
file_info.bzfile,q,(
int) length);
1427 blob_info->
offset+=count;
1428 if (count != (ssize_t) length)
1430 (void) memcpy(q,p,(
size_t) count);
1461 const size_t length,
void *data,ssize_t *count)
1463 assert(count != (ssize_t *) NULL);
1464 assert(blob_info != (
BlobInfo *) NULL);
1467 *count=
ReadBlob(blob_info,length,data);
1478 blob_info->
offset+=(*count);
1479 if (*count != (ssize_t) length)
1495 assert(blob_info != (
BlobInfo *) NULL);
1497 p=(
const unsigned char *)
ReadBlobStream(blob_info,1,buffer,&count);
1542 assert(blob_info != (
BlobInfo *) NULL);
1545 assert(data != (
void *) NULL);
1547 return(
ReadBlob(blob_info,length,data));
1549 for (i=0; i < (ssize_t) length; i+=count)
1552 (
unsigned char *) data+i);
1593 assert(blob_info != (
BlobInfo *) NULL);
1595 switch (blob_info->
type)
1623 count=(ssize_t) fwrite((
const unsigned char *)
"",1,1,
1663 count=(ssize_t) fwrite((
const unsigned char *)
"",1,1,
1671 blob_info->
extent=(size_t) extent;
1672 blob_info->
length=(size_t) extent;
1676 blob_info->
extent=(size_t) extent;
1680 if (blob_info->
data == (
unsigned char *) NULL)
1719 assert(blob_info != (
BlobInfo *) NULL);
1723 switch (blob_info->
type)
1736#if defined(WIZARDSTOOLKIT_ZLIB_DELEGATE)
1737 status=gzflush(blob_info->
file_info.gzfile,Z_SYNC_FLUSH);
1743#if defined(WIZARDSTOOLKIT_BZLIB_DELEGATE)
1744 status=BZ2_bzflush(blob_info->
file_info.bzfile);
1781 assert(blob_info != (
BlobInfo *) NULL);
1786 switch (blob_info->
type)
1800#if defined(WIZARDSTOOLKIT_ZLIB_DELEGATE)
1809 offset=blob_info->
offset;
1843#if defined(WIZARDSTOOLKIT_HAVE_MMAP_FILEIO)
1847 status=munmap(map,length);
1894 assert(blob_info != (
BlobInfo *) NULL);
1896 assert(data != (
const void *) NULL);
1900 p=(
const unsigned char *) data;
1901 switch (blob_info->
type)
1913 count=(ssize_t) fwrite((
const char *) data,1,length,
1952#if defined(WIZARDSTOOLKIT_ZLIB_DELEGATE)
1957 count=(ssize_t) gzwrite(blob_info->
file_info.gzfile,(
void *) data,
1958 (
unsigned int) length);
1963 c=gzputc(blob_info->
file_info.gzfile,(
int) *p++);
1970 c=gzputc(blob_info->
file_info.gzfile,(
int) *p++);
1977 c=gzputc(blob_info->
file_info.gzfile,(
int) *p++);
1984 c=gzputc(blob_info->
file_info.gzfile,(
int) *p++);
1997#if defined(WIZARDSTOOLKIT_BZLIB_DELEGATE)
1998 count=(ssize_t) BZ2_bzwrite(blob_info->
file_info.bzfile,(
void *) data,
2018 if (blob_info->
data == (
unsigned char *) NULL)
2025 (void) memcpy(q,p,length);
2026 blob_info->
offset+=length;
2029 count=(ssize_t) length;
2070 assert(blob_info != (
BlobInfo *) NULL);
2072 return(
WriteBlob(blob_info,length,data));
2074 assert(data != (
void *) NULL);
2076 if (extent >= blob_info->
extent)
2084 (void) memcpy(q,data,length);
2085 blob_info->
offset+=length;
2088 return((ssize_t) length);
2092 const unsigned char value)
2094 assert(blob_info != (
BlobInfo *) NULL);
2138 assert(blob_info != (
BlobInfo *) NULL);
2140 assert(data != (
const unsigned char *) NULL);
2142 return(
WriteBlob(blob_info,length,data));
2144 for (i=0; i < (ssize_t) length; i+=count)
2147 (
const unsigned char *) data+i);
2188 assert(blob_info != (
BlobInfo *) NULL);
2190 assert(
string != (
const char *) NULL);
2191 count=
WriteBlobStream(blob_info,strlen(
string),(
const unsigned char *)
WizardExport WizardBooleanType CloseBlob(BlobInfo *blob_info)
WizardExport WizardSizeType GetBlobSize(BlobInfo *blob_info)
WizardExport int EOFBlob(BlobInfo *blob_info)
WizardExport ssize_t ReadBlob(BlobInfo *blob_info, const size_t length, void *data)
WizardExport ssize_t WriteBlobChunk(BlobInfo *blob_info, const size_t length, const void *data)
WizardExport WizardBooleanType UnmapBlob(void *map, const size_t length)
static unsigned char * DetachBlob(BlobInfo *)
static const void * ReadBlobStream(BlobInfo *blob_info, const size_t length, void *data, ssize_t *count)
WizardExport BlobInfo * DestroyBlob(BlobInfo *blob_info)
WizardExport WizardOffsetType TellBlob(const BlobInfo *blob_info)
WizardExport BlobInfo * OpenBlob(const char *filename, const BlobMode mode, const WizardBooleanType compress, ExceptionInfo *exception)
WizardExport WizardBooleanType SetBlobExtent(BlobInfo *blob_info, const WizardSizeType extent)
WizardExport int SyncBlob(BlobInfo *blob_info)
WizardExport ssize_t WriteBlobString(BlobInfo *blob_info, const char *string)
static void ThrowBlobException(BlobInfo *blob_info)
WizardExport int ReadBlobByte(BlobInfo *blob_info)
WizardExport void * FileToBlob(const char *filename, const size_t extent, size_t *length, ExceptionInfo *exception)
WizardExport ssize_t WriteBlobByte(BlobInfo *blob_info, const unsigned char value)
WizardExport ssize_t ReadBlobChunk(BlobInfo *blob_info, const size_t length, void *data)
static ssize_t WriteBlobStream(BlobInfo *blob_info, const size_t length, const void *data)
WizardExport const struct stat * GetBlobProperties(const BlobInfo *blob_info)
#define WizardMaxBlobExtent
static WizardBooleanType GetPathAttributes(const char *path, void *attributes)
static void AttachBlob(BlobInfo *blob_info, const void *blob, const size_t length)
WizardExport void * MapBlob(int file, const MapMode mode, const WizardOffsetType offset, const size_t length)
WizardExport ssize_t WriteBlob(BlobInfo *blob_info, const size_t length, const void *data)
WizardExport void GetBlobInfo(BlobInfo *blob_info)
WizardExport const char * GetBlobFilename(const BlobInfo *blob_info)
#define WizardMaxBufferExtent
#define MaxCipherBlocksize
WizardExport WizardBooleanType ThrowWizardException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *format,...)
WizardBooleanType LogWizardEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
WizardExport WizardBooleanType IsEventLogging(void)
#define GetWizardModule()
WizardExport void * AcquireWizardMemory(const size_t size)
WizardExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
WizardExport void * RelinquishWizardMemory(void *memory)
WizardExport void * ResizeQuantumMemory(void *memory, const size_t count, const size_t quantum)
WizardExport WizardBooleanType AcquireWizardResource(const ResourceType type, const WizardSizeType size)
WizardExport void RelinquishWizardResource(const ResourceType type, const WizardSizeType size)
WizardExport void RelinquishSemaphoreInfo(SemaphoreInfo **semaphore_info)
WizardExport SemaphoreInfo * AcquireSemaphoreInfo(void)
WizardExport void LockSemaphoreInfo(SemaphoreInfo *semaphore_info)
WizardExport void UnlockSemaphoreInfo(SemaphoreInfo *semaphore_info)
static long StringToLong(const char *value)
WizardExport int LocaleNCompare(const char *p, const char *q, const size_t length)
WizardExport int LocaleCompare(const char *p, const char *q)
WizardExport size_t CopyWizardString(char *destination, const char *source, const size_t length)
char filename[WizardPathExtent]
WizardBooleanType temporary
SemaphoreInfo * semaphore
static int open_utf8(const char *path, int flags, mode_t mode)
static FILE * fopen_utf8(const char *path, const char *mode)
static int stat_utf8(const char *path, struct stat *attributes)
static FILE * popen_utf8(const char *command, const char *type)
WizardExport void GetPathComponent(const char *path, PathType type, char *component)