source: cpp/frams/virtfile/stdiofile.h @ 147

Last change on this file since 147 was 121, checked in by sz, 11 years ago

updated file headers and makefiles

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 2002-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#ifndef _STDIOFILE_H_
6#define _STDIOFILE_H_
7
8#include "virtfile.h"
9#include <frams/util/sstring.h>
10#include <stdio.h>
11#include <common/nonstd_dir.h>
12
13class StdioFileSystem: public VirtFileSystem
14{
15public:
16VirtFILE *Vfopen(const char* path,const char*mode);
17int Vfexists(const char* path);
18VirtDIR *Vopendir(const char* path);
19};
20
21class StdioFILE: public VirtFILE
22{
23  protected:
24FILE *file;
25SString path;
26  public:
27StdioFILE(FILE *f) {file=f;}
28StdioFILE(FILE *f,const SString& p) {file=f;path=p;}
29static void setStdio();
30int Vread(void *ptr, size_t size, size_t nmemb) {return fread(ptr,size,nmemb,file);}
31int Vwrite(const void *ptr, size_t size, size_t nmemb) {return fwrite(ptr,size,nmemb,file);}
32int Veof() {return feof(file);}
33int Vputc(int c) {return fputc(c,file);}
34int Vputs(const char *s) {return fputs(s,file);}
35int Vgetc() {return fgetc(file);}
36char *Vgets(char *s, int size) {return fgets(s,size,file);}
37int Vprintf(const char *format, va_list args) { return vfprintf(file,format,args); }
38int Vseek(long offset, int whence) {return fseek(file,offset,whence);}
39int Vtell() {return ftell(file);}
40void Vrewind() {rewind(file);}
41int Vflush() {return fflush(file);}
42const char* VgetPath() {return path;}
43
44~StdioFILE() {if (file) fclose(file);}
45};
46
47class StdioDIR: public VirtDIR
48{
49DIR *dir;
50  public:
51StdioDIR(DIR* d):dir(d) {}
52~StdioDIR() {if (dir) closedir(dir);}
53dirent* Vreaddir();
54};
55
56class StdioFILEDontClose: public StdioFILE
57{
58  public:
59StdioFILEDontClose(FILE *f):StdioFILE(f) {}
60~StdioFILEDontClose() {file=0;}
61};
62
63#endif
Note: See TracBrowser for help on using the repository browser.