| 1 |
/*************************************************************************/ |
| 2 |
/* */ |
| 3 |
/* Cepstral, LLC */ |
| 4 |
/* Copyright (c) 2001 */ |
| 5 |
/* All Rights Reserved. */ |
| 6 |
/* */ |
| 7 |
/* Permission is hereby granted, free of charge, to use and distribute */ |
| 8 |
/* this software and its documentation without restriction, including */ |
| 9 |
/* without limitation the rights to use, copy, modify, merge, publish, */ |
| 10 |
/* distribute, sublicense, and/or sell copies of this work, and to */ |
| 11 |
/* permit persons to whom this work is furnished to do so, subject to */ |
| 12 |
/* the following conditions: */ |
| 13 |
/* 1. The code must retain the above copyright notice, this list of */ |
| 14 |
/* conditions and the following disclaimer. */ |
| 15 |
/* 2. Any modifications must be clearly marked as such. */ |
| 16 |
/* 3. Original authors' names are not deleted. */ |
| 17 |
/* 4. The authors' names are not used to endorse or promote products */ |
| 18 |
/* derived from this software without specific prior written */ |
| 19 |
/* permission. */ |
| 20 |
/* */ |
| 21 |
/* CEPSTRAL, LLC AND THE CONTRIBUTORS TO THIS WORK DISCLAIM ALL */ |
| 22 |
/* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED */ |
| 23 |
/* WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL */ |
| 24 |
/* CEPSTRAL, LLC NOR THE CONTRIBUTORS BE LIABLE FOR ANY SPECIAL, */ |
| 25 |
/* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER */ |
| 26 |
/* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION */ |
| 27 |
/* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR */ |
| 28 |
/* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 29 |
/* */ |
| 30 |
/*************************************************************************/ |
| 31 |
/* Author: David Huggins-Daines ([email protected]) */ |
| 32 |
/* Date: October 2001 */ |
| 33 |
/*************************************************************************/ |
| 34 |
/* */ |
| 35 |
/* cst_mmap_none.c: stubs for systems with no memory-mapped I/O support. */ |
| 36 |
/* */ |
| 37 |
/*************************************************************************/ |
| 38 |
|
| 39 |
#include "cst_file.h" |
| 40 |
#include "cst_error.h" |
| 41 |
#include "cst_alloc.h" |
| 42 |
|
| 43 |
cst_filemap *cst_mmap_file(const char *path) |
| 44 |
{ |
| 45 |
cst_dbgmsg("cst_mmap_file: unsupported on this platform"); |
| 46 |
cst_error(); |
| 47 |
|
| 48 |
return NULL; |
| 49 |
} |
| 50 |
|
| 51 |
int cst_munmap_file(cst_filemap *fmap) |
| 52 |
{ |
| 53 |
cst_dbgmsg("cst_munmap_file: unsupported on this platform"); |
| 54 |
cst_error(); |
| 55 |
|
| 56 |
return -1; |
| 57 |
} |
| 58 |
|
| 59 |
cst_filemap *cst_read_whole_file(const char *path) |
| 60 |
{ |
| 61 |
cst_filemap *fmap; |
| 62 |
cst_file fh; |
| 63 |
|
| 64 |
if ((fh = cst_fopen(path, CST_OPEN_READ)) < 0) { |
| 65 |
cst_errmsg("cst_read_whole_file: Failed to open file\n"); |
| 66 |
return NULL; |
| 67 |
} |
| 68 |
|
| 69 |
fmap = cst_alloc(cst_filemap, 1); |
| 70 |
fmap->fh = fh; |
| 71 |
fmap->mapsize = cst_filesize(fmap->fh); |
| 72 |
fmap->mem = cst_alloc(char, fmap->mapsize); |
| 73 |
if (cst_fread(fmap->fh, fmap->mem, 1, fmap->mapsize) < fmap->mapsize) |
| 74 |
{ |
| 75 |
cst_errmsg("cst_read_whole_file: read() failed\n"); |
| 76 |
cst_fclose(fmap->fh); |
| 77 |
cst_free(fmap->mem); |
| 78 |
cst_free(fmap); |
| 79 |
return NULL; |
| 80 |
} |
| 81 |
|
| 82 |
return fmap; |
| 83 |
} |
| 84 |
|
| 85 |
int cst_free_whole_file(cst_filemap *fmap) |
| 86 |
{ |
| 87 |
if (cst_fclose(fmap->fh) < 0) { |
| 88 |
cst_errmsg("cst_free_whole_file: close() failed\n"); |
| 89 |
return -1; |
| 90 |
} |
| 91 |
cst_free(fmap->mem); |
| 92 |
cst_free(fmap); |
| 93 |
return 0; |
| 94 |
} |
| 95 |
|
| 96 |
cst_filemap *cst_read_part_file(const char *path) |
| 97 |
{ |
| 98 |
cst_filemap *fmap; |
| 99 |
cst_file fh; |
| 100 |
|
| 101 |
if ((fh = cst_fopen(path, CST_OPEN_READ)) == NULL) { |
| 102 |
cst_errmsg("cst_read_part_file: Failed to open file\n"); |
| 103 |
return NULL; |
| 104 |
} |
| 105 |
|
| 106 |
fmap = cst_alloc(cst_filemap, 1); |
| 107 |
fmap->fh = fh; |
| 108 |
fmap->mapsize = cst_filesize(fmap->fh); |
| 109 |
|
| 110 |
return fmap; |
| 111 |
} |
| 112 |
|
| 113 |
int cst_free_part_file(cst_filemap *fmap) |
| 114 |
{ |
| 115 |
if (cst_fclose(fmap->fh) < 0) { |
| 116 |
cst_errmsg("cst_munmap_file: cst_fclose() failed\n"); |
| 117 |
return -1; |
| 118 |
} |
| 119 |
cst_free(fmap); |
| 120 |
return 0; |
| 121 |
} |