home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 4
/
DATAFILE_PDCD4.iso
/
unix
/
unixtools
/
util
/
h
/
utils
< prev
Wrap
Text File
|
1992-07-21
|
4KB
|
165 lines
/* H.Utils: general utilities (header file) */
#ifndef __utils_h
#define __utils_h
/* Type definitions required for function prototypes */
#ifndef __stdio_h
/* If we've done <stdio.h> we've got everything we need already */
/* Set up size_t (as defined in standard headers) */
#ifndef __size_t
#define __size_t 1
typedef unsigned int size_t; /* from <stddef.h> */
#endif
/* Temporary #define - undone at the end */
#define FILE struct __FILE_struct
#endif
/* ARM System time format */
#ifndef __TIME_h
#define __TIME_h
typedef struct
{
unsigned char t[5]; /* Low byte first - ie. t[0] is low */
}
TIME;
#endif
/* File length/offset type */
#ifndef __off_t_h
#define __off_t_h
typedef unsigned int off_t;
#endif
/* Standard external function definitions */
/* Error message handling */
extern void fatal (int rc, const char *format, ...);
extern void message (const char *format, ...);
/* Extra string handling */
extern char *strdup (const char *str);
extern char *strndup (const char *str, int n);
extern char *strupper (char *str);
extern char *strlower (char *str);
extern char *strpcpy (char *s, const char *t);
extern char *strnpcpy (char *s, const char *t, int n);
extern int strlcmp (const char *s, const char *t);
extern int strnlcmp (const char *s, const char *t, int n);
extern int strcchr (const char *s, char c);
/* Automatically reclaimed memory allocation */
extern void *alloca (size_t size);
/* Safe memory allocation */
extern void *emalloc (size_t size);
extern void *erealloc (void *ptr, size_t size);
extern void *ecalloc (size_t count, size_t size);
/* Safe file opening */
extern FILE *efopen (const char *file, const char *mode);
extern FILE *efreopen (const char *file, const char *mode, FILE *fp);
/* File system manipulation */
extern int chdir (const char *dir);
extern int touch (const char *file);
extern char *getcwd (int preserve_pwd, char **pwd_ptr);
#define getwd() getcwd (1, 0)
/* Temporary file handling */
extern char *temp_dir;
extern char *mktemp (const char *file);
/* Simulation of pipes */
extern FILE *popen (char *command, char *mode);
extern int pclose (FILE *fd);
/* Random number generator */
void srandom (unsigned seed);
long random (void);
char *initstate (unsigned seed, char *arg_state, int n);
char *setstate (char *arg_state);
/* Program option processing */
extern int getopt (int argc, char *argv[], const char *optstring);
extern char *optarg;
extern int optind;
extern int opterr;
/* Directory scan for wildcards */
extern char *dirscan (const char *file);
/* File information */
extern int filetype (const char *file);
extern TIME filetime (const char *file);
extern off_t filelen (const char *file);
/* Results from filetype() */
#define F_NONE (-1)
#define F_DIR (-2)
#define F_UNSTAMPED (-3)
#define F_ERROR (-4)
/* Copy data to the heap. This should only be used for l-values (including
* array names).
*
* For example, with the following declarations:
*
* void *heap_ptr;
* char a[100];
* time_t t;
*
* Use:
*
* heap_ptr = VarToHeap(a); -- copies the whole array (100 bytes).
* heap_ptr = VarToHeap(t); -- copies t, even if t is a structure type.
*
*/
#define VarToHeap(var) ( memcpy( emalloc(sizeof(var)), &(var), sizeof(var)) )
/* Machine dependent data types */
typedef unsigned char byte; /* 8-bit byte */
typedef unsigned short halfword; /* 16-bit halfword */
typedef unsigned int word; /* 32-bit word */
/* Number of elements in array A */
#define DIM(a) ( sizeof(a) / sizeof(*(a)) )
/* Maximum and minimum */
#define MAX(a,b) ( (a) > (b) ? (a) : (b) )
#define MIN(a,b) ( (a) < (b) ? (a) : (b) )
/* Scope control pseudo-keywords */
#define public
#define private static
/* Flag a given variable (function argument) as used.
*
* Notes: No code is compiled (isn't optimisation wonderful).
* Side effects in "var" are not evaluated.
* Var must be an l-value.
*/
#define USE(var) (void)( 0 ? (var)=(var) : 0 )
/* Now undo the temporary definition of FILE */
#ifndef __stdio_h
#undef FILE
#endif
#endif