* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#include <string.h>
+#include <stdlib.h>
+
#include "gmqcc.h"
/*
* The PAK format uses a FOURCC concept for storing the magic ident within
* the header as a uint32_t.
*/
-#define PAK_FOURCC ((uint32_t)(('P' | ('A' << 8) | ('C' << 16) | ('K' << 24))))
+#define PAK_FOURCC ((uint32_t)(((uint8_t)'P'|((uint8_t)'A'<<8)|((uint8_t)'C'<<16)|((uint8_t)'K'<<24))))
typedef struct {
uint32_t magic; /* "PACK" */
return pak;
}
-pak_file_t *pak_open(const char *file, const char *mode) {
+static pak_file_t *pak_open(const char *file, const char *mode) {
if (!file || !mode)
return NULL;
return NULL;
}
-bool pak_exists(pak_file_t *pak, const char *file, pak_directory_t **dir) {
+static bool pak_exists(pak_file_t *pak, const char *file, pak_directory_t **dir) {
size_t itr;
if (!pak || !file)
/*
* Extraction abilities. These work as you expect them to.
*/
-bool pak_extract_one(pak_file_t *pak, const char *file, const char *outdir) {
+static bool pak_extract_one(pak_file_t *pak, const char *file, const char *outdir) {
pak_directory_t *dir = NULL;
unsigned char *dat = NULL;
char *local = NULL;
return true;
}
-bool pak_extract_all(pak_file_t *pak, const char *dir) {
+static bool pak_extract_all(pak_file_t *pak, const char *dir) {
size_t itr;
if (!fs_dir_make(dir))
* Insertion functions (the opposite of extraction). Yes for generating
* PAKs.
*/
-bool pak_insert_one(pak_file_t *pak, const char *file) {
+static bool pak_insert_one(pak_file_t *pak, const char *file) {
pak_directory_t dir;
unsigned char *dat;
+ long len;
FILE *fp;
/*
* to the PAK file itself.
*/
fs_file_seek(fp, 0, SEEK_END);
- dir.len = fs_file_tell(fp);
+ if ((len = fs_file_tell(fp)) < 0) {
+ fs_file_close(fp);
+ return false;
+ }
fs_file_seek(fp, 0, SEEK_SET);
+ dir.len = len;
dir.pos = fs_file_tell(pak->handle);
/*
return true;
}
-bool pak_close(pak_file_t *pak) {
+static bool pak_close(pak_file_t *pak) {
size_t itr;
if (!pak)
* our directory entries at the end of the file.
*/
if (pak->insert) {
+ int tell = fs_file_tell(pak->handle);
+ if (tell < 0) {
+ vec_free (pak->directories);
+ fs_file_close(pak->handle);
+ mem_d (pak);
+
+ return false;
+ }
pak->header.dirlen = vec_size(pak->directories) * 64;
- pak->header.diroff = ftell(pak->handle);
+ pak->header.diroff = tell;
/* patch header */
fs_file_seek (pak->handle, 0, SEEK_SET);
/* not possible */
pak_close(pak);
vec_free(files);
- util_meminfo();
+ stat_info();
+
return EXIT_SUCCESS;
}
pak_close(pak);
vec_free(files);
- util_meminfo();
+ stat_info();
return EXIT_SUCCESS;
}