2 * $Id: routines.h 536 2007-06-02 06:09:00Z elliotth $
4 * Copyright (c) 2002, Darren Hiebert
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License.
9 * External interface to routines.c
17 #include "general.h" /* must always come first */
22 #define xMalloc(n,Type) (Type *)eMalloc((size_t)(n) * sizeof (Type))
23 #define xCalloc(n,Type) (Type *)eCalloc((size_t)(n), sizeof (Type))
24 #define xRealloc(p,n,Type) (Type *)eRealloc((p), (n) * sizeof (Type))
29 #ifndef PATH_SEPARATOR
30 # if defined (MSDOS_STYLE_PATH)
31 # define PATH_SEPARATOR '\\'
33 # define PATH_SEPARATOR '_'
35 # define PATH_SEPARATOR '/'
39 #if defined (MSDOS_STYLE_PATH) && defined (UNIX_PATH_SEPARATOR)
40 # define OUTPUT_PATH_SEPARATOR '/'
42 # define OUTPUT_PATH_SEPARATOR PATH_SEPARATOR
48 #if defined (MSDOS_STYLE_PATH) || defined (VMS)
49 extern const char *const PathDelimiters
;
51 extern char *CurrentDirectory
;
52 typedef int errorSelection
;
53 enum eErrorTypes
{ FATAL
= 1, WARNING
= 2, PERROR
= 4 };
56 /* Name of file for which status is valid */
59 /* Does file exist? If not, members below do not contain valid data. */
62 /* is file path a symbolic link to another file? */
63 boolean isSymbolicLink
;
65 /* Is file (pointed to) a directory? */
68 /* Is file (pointed to) a normal file? */
71 /* Is file (pointed to) executable? */
74 /* Is file (pointed to) setuid? */
77 /* Size of file (pointed to) */
84 extern void freeRoutineResources (void);
85 extern void setExecutableName (const char *const path
);
86 extern const char *getExecutableName (void);
87 extern const char *getExecutablePath (void);
88 extern void error (const errorSelection selection
, const char *const format
, ...) __printf__ (2, 3);
90 /* Memory allocation functions */
91 #ifdef NEED_PROTO_MALLOC
92 extern void *malloc (size_t);
93 extern void *realloc (void *ptr
, size_t);
95 extern void *eMalloc (const size_t size
);
96 extern void *eCalloc (const size_t count
, const size_t size
);
97 extern void *eRealloc (void *const ptr
, const size_t size
);
98 extern void eFree (void *const ptr
);
100 /* String manipulation functions */
101 extern int struppercmp (const char *s1
, const char *s2
);
102 extern int strnuppercmp (const char *s1
, const char *s2
, size_t n
);
104 extern char* strstr (const char *str
, const char *substr
);
106 extern char* eStrdup (const char* str
);
107 extern void toLowerString (char* str
);
108 extern void toUpperString (char* str
);
109 extern char* newLowerString (const char* str
);
110 extern char* newUpperString (const char* str
);
112 /* File system functions */
113 extern void setCurrentDirectory (void);
114 extern fileStatus
*eStat (const char *const fileName
);
115 extern void eStatFree (fileStatus
*status
);
116 extern boolean
doesFileExist (const char *const fileName
);
117 extern boolean
isRecursiveLink (const char* const dirName
);
118 extern boolean
isSameFile (const char *const name1
, const char *const name2
);
119 #if defined(NEED_PROTO_FGETPOS)
120 extern int fgetpos (FILE *stream
, fpos_t *pos
);
121 extern int fsetpos (FILE *stream
, fpos_t *pos
);
123 extern const char *baseFilename (const char *const filePath
);
124 extern const char *fileExtension (const char *const fileName
);
125 extern boolean
isAbsolutePath (const char *const path
);
126 extern vString
*combinePathAndFile (const char *const path
, const char *const file
);
127 extern char* absoluteFilename (const char *file
);
128 extern char* absoluteDirname (char *file
);
129 extern char* relativeFilename (const char *file
, const char *dir
);
130 extern FILE *tempFile (const char *const mode
, char **const pName
);
132 #endif /* _ROUTINES_H */
134 /* vi:set tabstop=4 shiftwidth=4: */