home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / utilslib / utils_old / h / Utils < prev   
Encoding:
Text File  |  1994-02-22  |  4.2 KB  |  166 lines

  1. /* H.Utils: general utilities (header file) */
  2.  
  3. #ifndef __utils_h
  4. #define __utils_h
  5.  
  6. /* Type definitions required for function prototypes */
  7.  
  8. #ifndef __stdio_h
  9. /* If we've done <stdio.h> we've got everything we need already */
  10.  
  11. /* Set up size_t (as defined in standard headers) */
  12.  
  13. #ifndef __size_t
  14. #define __size_t 1
  15. typedef unsigned int size_t;   /* from <stddef.h> */
  16. #endif
  17.  
  18. /* Temporary #define - undone at the end */
  19.  
  20. #define FILE struct __FILE_struct
  21.  
  22. #endif
  23.  
  24. /* ARM System time format */
  25.  
  26. #ifndef __TIME_h
  27. #define __TIME_h
  28. typedef struct
  29. {
  30.     unsigned char t[5];    /* Low byte first - ie. t[0] is low */
  31. }
  32. TIME;
  33. #endif
  34.  
  35. /* Standard external function definitions */
  36.  
  37. /* Error message handling */
  38. extern void fatal (int rc, const char *format, ...);
  39.                           /* Tends to clash with stuff in other sources :-( */
  40. extern void message (const char *format, ...);
  41.  
  42. /* Extra string handling */
  43. extern char *strdup (const char *str);
  44. extern char *strndup (const char *str, int n);
  45. extern char *strupper (char *str);
  46. extern char *strlower (char *str);
  47. extern char *strpcpy (char *s, const char *t);
  48. extern char *strnpcpy (char *s, const char *t, int n);
  49. extern int strlcmp (const char *s, const char *t);
  50. extern int strnlcmp (const char *s, const char *t, int n);
  51. extern int strcchr (const char *s, char c);
  52.  
  53. /* Automatically reclaimed memory allocation */
  54. extern void *alloca (size_t size);
  55.  
  56. /* Safe memory allocation */
  57. extern void *emalloc (size_t size);
  58. extern void *erealloc (void *ptr, size_t size);
  59. extern void *ecalloc (size_t count, size_t size);
  60.  
  61. /* Safe file opening */
  62. extern FILE *efopen (const char *file, const char *mode);
  63. extern FILE *efreopen (const char *file, const char *mode, FILE *fp);
  64.  
  65. /* File pointer information */
  66. extern int isatty (FILE *fp); /* think this should be an int fd ... -- GT */
  67.  
  68. /* File system manipulation */
  69. extern int chdir (const char *dir);
  70. extern int touch (const char *file);
  71. extern char *getcwd (int preserve_pwd, char **pwd_ptr);
  72. #define getwd() getcwd (1, 0)
  73.  
  74. /* Temporary file handling */
  75. extern char *temp_dir;
  76. extern char *mktemp (const char *file);
  77.  
  78. /* Simulation of pipes */
  79. extern FILE *popen (char *command, char *mode);
  80. extern int pclose (FILE *fd);
  81.  
  82. /* Random number generator */
  83. void srandom (unsigned seed);
  84. long random (void);
  85. char *initstate (unsigned seed, char *arg_state, int n);
  86. char *setstate (char *arg_state);
  87.  
  88. /* Program option processing */
  89. extern int  getopt (int argc, char *argv[], const char *optstring);
  90. extern char *optarg;
  91. extern int  optind;
  92. extern int  opterr;
  93.  
  94. /* Directory scan for wildcards */
  95. extern char *dirscan (const char *file);
  96.  
  97. /* File information */
  98. extern int filetype (const char *file);
  99. extern TIME filetime (const char *file);
  100. extern unsigned filelen (const char *file);
  101.  
  102. /* Results from filetype() */
  103. #define F_NONE        (-1)
  104. #define F_DIR        (-2)
  105. #define F_UNSTAMPED    (-3)
  106. #define F_ERROR        (-4)
  107.  
  108. /* Debugging utilities */
  109. extern void *ProgLimit (void);
  110. extern char *caller (void);
  111.  
  112. /* Copy data to the heap. This should only be used for l-values (including
  113.  * array names).
  114.  *
  115.  * For example, with the following declarations:
  116.  *
  117.  * void *heap_ptr;
  118.  * char a[100];
  119.  * time_t t;
  120.  *
  121.  * Use:
  122.  *
  123.  * heap_ptr = VarToHeap(a);         -- copies the whole array (100 bytes).
  124.  * heap_ptr = VarToHeap(t);         -- copies t, even if t is a structure type.
  125.  *
  126.  */
  127.  
  128. #define VarToHeap(var)  ( memcpy( emalloc(sizeof(var)), &(var), sizeof(var)) )
  129.  
  130. /* Machine dependent data types */
  131.  
  132. typedef unsigned char  byte;            /*  8-bit byte     */
  133. typedef unsigned short halfword;        /* 16-bit halfword */
  134. typedef unsigned int   word;            /* 32-bit word     */
  135.  
  136. /* Number of elements in array A */
  137.  
  138. #define DIM(a)  ( sizeof(a) / sizeof(*(a)) )
  139.  
  140. /* Maximum and minimum */
  141.  
  142. #define MAX(a,b)        ( (a) > (b) ? (a) : (b) )
  143. #define MIN(a,b)        ( (a) < (b) ? (a) : (b) )
  144.  
  145. /* Scope control pseudo-keywords */
  146.  
  147. #define public
  148. #define private static
  149.  
  150. /* Flag a given variable (function argument) as used.
  151.  *
  152.  * Notes: No code is compiled (isn't optimisation wonderful).
  153.  *        Side effects in "var" are not evaluated.
  154.  *        Var must be an l-value.
  155.  */
  156.  
  157. #define USE(var)        (void)( 0 ? (var)=(var) : 0 )
  158.  
  159. /* Now undo the temporary definition of FILE */
  160.  
  161. #ifndef __stdio_h
  162. #undef FILE
  163. #endif
  164.  
  165. #endif
  166.