diff options
Diffstat (limited to 'util.h')
-rw-r--r-- | util.h | 65 |
1 files changed, 65 insertions, 0 deletions
@@ -0,0 +1,65 @@ +/* + + DiskImageTool - Tool for manipulating disk images + + Copyright (C) 2019 Ian Cowburn (ianc@noddybox.co.uk) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + ------------------------------------------------------------------------- + + Various utilities + +*/ + +#ifndef DITOOL_UTIL_H +#define DITOOL_UTIL_H + +/* Allocate memory, quitting if it fails +*/ +void *Malloc(size_t size); + +/* Reallocate memory, quitting if it fails +*/ +void *Realloc(void *p, size_t size); + +/* Get the next line from stdin, prompting with prompt. Will only return at + EOF or when a string is entered. Returns TRUE for OK, FALSE for EOF. +*/ +int GetLine(const char *prompt, char *buff, size_t buffsize); + +/* Load the file from path into memory, returning a pointer to an allocated + block for the file. *size holds the size of the file. Returns NULL on + error. +*/ +void *Load(const char *path, size_t *size); + +/* Save the passed memory to the path. Returns TRUE for OK, FALSE for failure. +*/ +int Save(const char *path, const void *buff, size_t buffsize); + +/* Compare a lump of memory with a string. Returns as per memcmp() +*/ +int CompareMem(const void *mem, const char *str); + +/* Gets a character from the user from a list of possible choices with an + optional default value. Returns zero on EOF. +*/ +char GetOption(const char *prompt, const char *allowed, char default_val); + +#endif + +/* +vim: ai sw=4 ts=8 expandtab +*/ |