diff options
author | Diegoisawesome <diego@domoreaweso.me> | 2016-11-01 10:56:23 -0500 |
---|---|---|
committer | Diegoisawesome <diego@domoreaweso.me> | 2016-11-01 10:56:23 -0500 |
commit | f09f9cef752c37e3cc0686573c1fdb29da842772 (patch) | |
tree | 22bee285750a6739643859eb6afd52be4ded87e1 /tools/gbagfx/util.c | |
parent | 442002dada4183c96b5ec09fcde8486aa5ba29b1 (diff) | |
parent | 4db33778ad3faa64d994f46358a28c22c393f7c6 (diff) |
Merge remote-tracking branch 'refs/remotes/pret/master'
Diffstat (limited to 'tools/gbagfx/util.c')
-rw-r--r-- | tools/gbagfx/util.c | 98 |
1 files changed, 0 insertions, 98 deletions
diff --git a/tools/gbagfx/util.c b/tools/gbagfx/util.c deleted file mode 100644 index 5af380184..000000000 --- a/tools/gbagfx/util.c +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) 2015 YamaArashi - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdbool.h> -#include <errno.h> -#include <limits.h> -#include "global.h" -#include "util.h" - -bool ParseNumber(char *s, char **end, int radix, int *intValue) -{ - char *localEnd; - - if (end == NULL) - end = &localEnd; - - errno = 0; - - const long longValue = strtol(s, end, radix); - - if (*end == s) - return false; // not a number - - if ((longValue == LONG_MIN || longValue == LONG_MAX) && errno == ERANGE) - return false; - - if (longValue > INT_MAX) - return false; - - if (longValue < INT_MIN) - return false; - - *intValue = (int)longValue; - - return true; -} - -char *GetFileExtension(char *path) -{ - char *extension = path; - - while (*extension != 0) - extension++; - - while (extension > path && *extension != '.') - extension--; - - if (extension == path) - return NULL; - - extension++; - - if (*extension == 0) - return NULL; - - return extension; -} - -unsigned char *ReadWholeFile(char *path, int *size) -{ - FILE *fp = fopen(path, "rb"); - - if (fp == NULL) - FATAL_ERROR("Failed to open \"%s\" for reading.\n", path); - - fseek(fp, 0, SEEK_END); - - *size = ftell(fp); - - unsigned char *buffer = malloc(*size); - - if (buffer == NULL) - FATAL_ERROR("Failed to allocate memory for reading \"%s\".\n", path); - - rewind(fp); - - if (fread(buffer, *size, 1, fp) != 1) - FATAL_ERROR("Failed to read \"%s\".\n", path); - - fclose(fp); - - return buffer; -} - -void WriteWholeFile(char *path, void *buffer, int bufferSize) -{ - FILE *fp = fopen(path, "wb"); - - if (fp == NULL) - FATAL_ERROR("Failed to open \"%s\" for writing.\n", path); - - if (fwrite(buffer, bufferSize, 1, fp) != 1) - FATAL_ERROR("Failed to write to \"%s\".\n", path); - - fclose(fp); -} |