source: abuse/trunk/src/include/fakelib.hpp @ 39

Last change on this file since 39 was 17, checked in by Sam Hocevar, 18 years ago
  • absolute shitloads of 64 bit fixes.
File size: 935 bytes
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
8#ifdef __sgi
9#include <sys/bsd_types.h>
10#else
11#include <stdint.h>
12#endif
13
14class bFILE
15{
16  public :
17  FILE *fp;
18  bFILE(FILE *FP) { fp=FP; }
19  bFILE(char *fn, char *mode) { fp=fopen(fn,mode); }
20  long file_size() { long cur=ftell(fp),ret; fseek(fp,0,2); ret=ftell(fp);
21                     fseek(fp,cur,0); return ret; }
22  int read(void *buf, int count) { return fread(buf,count,1,fp); }
23  int write(void *buf, int count) { return fwrite(buf,count,1,fp); }
24  int write_byte(uchar x) { return fputc(x,fp); }
25  int open_failure() { return fp==NULL; }
26  ~bFILE() { if (fp) fclose(fp); }
27} ;
28
29#define jFILE bFILE
30
31bFILE *open_file(char *name, char *perm) { return new bFILE(fopen(name,perm)); }
32#define dprintf printf
33void dgets(char *s, int x)
34{ fgets(s,x,stdin);
35  if (strlen(s)>0) s[strlen(s)-1]=0;
36}
37
38#endif
Note: See TracBrowser for help on using the repository browser.