Graphite  Version 3
An experimental 3D geometry processing program
stdio_compat.h
Go to the documentation of this file.
1 /*
2  * GXML/Graphite: Geometry and Graphics Programming Library + Utilities
3  * Copyright (C) 2000 Bruno Levy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * If you modify this software, you should include a notice giving the
20  * name of the person performing the modification, the date of modification,
21  * and the reason for such modification.
22  *
23  * Contact: Bruno Levy
24  *
25  * levy@loria.fr
26  *
27  * ISA Project
28  * LORIA, INRIA Lorraine,
29  * Campus Scientifique, BP 239
30  * 54506 VANDOEUVRE LES NANCY CEDEX
31  * FRANCE
32  *
33  * Note that the GNU General Public License does not permit incorporating
34  * the Software into proprietary programs.
35  */
36 
37 #ifndef H_OGF_BASIC_IO_STDIO_COMPAT_H
38 #define H_OGF_BASIC_IO_STDIO_COMPAT_H
39 
41 
42 #include <iostream>
43 #include <stdio.h>
44 
51 namespace OGF {
52 
53 //____________________________________________________________________________
54 
64  inline size_t fread(
65  void* ptr_in, size_t size, size_t nbelt, std::istream* in
66  ) {
67  char* ptr = (char *)ptr_in ;
68  size_t j ;
69  for(j=0; j<nbelt; j++) {
70  for(size_t i=0; i<size; i++) {
71  if(in->eof()) {
72  return j ;
73  }
74  in->get(*ptr) ;
75  ptr++ ;
76  }
77  }
78  return j ;
79  }
80 
86  inline int fgetc(std::istream* in) {
87  char result ;
88  in->get(result) ;
89  return int(result) ;
90  }
91 
92 
102  inline int fseek(
103  std::istream* in, long offset, int whence
104  ) {
105  if(whence == SEEK_CUR) {
106  offset += in->tellg() ;
107  }
108  ogf_assert(whence != SEEK_END) ;
109  in->seekg(offset) ;
110  return 0 ;
111  }
112 
118  inline size_t ftell(std::istream* in) {
119  return size_t(in->tellg()) ;
120  }
121 
128  inline void fclose(std::istream* in) {
129  ogf_argused(in);
130  }
131 
132 
133 //____________________________________________________________________________
134 
135 }
136 
137 #endif
Global Graphite namespace.
Definition: common.h:76
int fgetc(std::istream *in)
reads a character from a stream.
Definition: stdio_compat.h:86
size_t ftell(std::istream *in)
gets the current position in a stream.
Definition: stdio_compat.h:118
size_t fread(void *ptr_in, size_t size, size_t nbelt, std::istream *in)
Reads elements from a stream.
Definition: stdio_compat.h:64
int fseek(std::istream *in, long offset, int whence)
moves the current position within a stream
Definition: stdio_compat.h:102
void fclose(std::istream *in)
closes a stream.
Definition: stdio_compat.h:128
Definitions common to all include files in the basic library.