source: abuse/tags/pd/macabuse/inc/fakelib.hpp

Last change on this file was 49, checked in by Sam Hocevar, 12 years ago
  • Imported original public domain release, for future reference.
File size: 1.0 KB
Line 
1#ifndef __FAKELIB_HPP_
2#define __FAKELIB_HPP_
3
4#define jmalloc(x,y) malloc(x)
5#define jrealloc(x,y,z) realloc(x,y)
6#define jfree(x) free(x)
7#define uchar  unsigned char
8#define schar  signed char
9#define sshort signed short
10
11#ifdef __sgi
12#include <sys/bsd_types.h>
13#else
14#define ulong  unsigned long
15#define ushort unsigned short
16#endif
17
18class bFILE
19{
20  public :
21  FILE *fp;
22  bFILE(FILE *FP) { fp=FP; }
23  bFILE(char *fn, char *mode) { fp=fopen(fn,mode); }
24  long file_size() { long cur=ftell(fp),ret; fseek(fp,0,2); ret=ftell(fp);
25                     fseek(fp,cur,0); return ret; }
26  int read(void *buf, int count) { return fread(buf,count,1,fp); }
27  int write(void *buf, int count) { return fwrite(buf,count,1,fp); }
28  int write_byte(uchar x) { return fputc(x,fp); }
29  int open_failure() { return fp==NULL; }
30  ~bFILE() { if (fp) fclose(fp); }
31} ;
32
33#define jFILE bFILE
34
35bFILE *open_file(char *name, char *perm) { return new bFILE(fopen(name,perm)); }
36#define dprintf printf
37void dgets(char *s, int x)
38{ fgets(s,x,stdin);
39  if (strlen(s)>0) s[strlen(s)-1]=0;
40}
41
42#endif
Note: See TracBrowser for help on using the repository browser.