-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutils.h
96 lines (65 loc) · 2.89 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/****************************************************************************
utils.h
various utilities
(memory management, file manipulation, etc... )
Lord of the Rings game engine
Copyright (C) 2003 Michal Benes
Lord of the Rings game engine is free software;
you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this code; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
#ifndef _UTILS_H
#define _UTILS_H
#include <stdio.h>
#include <libxml/parser.h>
#ifndef min
# define min(a,b) ((a) > (b) ? (b) : (a))
#endif
#ifndef max
# define max(a,b) ((a) > (b) ? (a) : (b))
#endif
/* allocates memory, exits on error */
extern void *lotr_malloc(int size);
/* opens a file, exits on error */
extern FILE *lotr_fopen(const char *path, const char *mode);
/* check if file exists */
extern int lotr_file_exists(const char *path);
/* return full path to $HOME/.lotr/<name> */
extern char *lotr_homedir_filename(const char *name);
/* adds suffix to a filename */
extern char *lotr_add_suffix(const char *name, const char *suffix);
/* returns file length, -1 if file==NULL */
extern long lotr_filelen(FILE *file);
/* random number */
extern int lotr_rnd(int n);
/* add integer property node to a given xml node */
extern void lotr_save_prop_int(xmlNodePtr node, char *name, int value);
/* add field property node to a given xml node */
extern void lotr_save_prop_field(xmlNodePtr node, char *name, Uint8 *value,
int len);
/* read integer property from node */
extern int lotr_load_prop_int(xmlNodePtr node, char *name);
/* read integer property from node, return default if no such node */
extern int lotr_load_prop_int_default(xmlNodePtr node, char *name,
int default_value);
/* read field property node from a given xml node */
extern int lotr_load_prop_field(xmlNodePtr node, char *name, Uint8 *value,
int maxlen);
/* gets node with a given name */
extern xmlNodePtr lotr_get_subnode(xmlNodePtr node, const xmlChar *name,
int force);
/* return data directory */
extern char *lotr_data_directory(void);
#if defined(AMIGA_OS4) || defined(_MSC_VER)
# define random() rand()
#endif
#endif /* _UTILS_H */