OSDN Git Service

io/stdio.hpp: seek() 実装
authorMyun2 <myun2@nwhite.info>
Fri, 18 May 2012 03:48:08 +0000 (12:48 +0900)
committerMyun2 <myun2@nwhite.info>
Fri, 18 May 2012 03:48:08 +0000 (12:48 +0900)
roast/include/roast/io/stdio.hpp

index 820c4d5..e5995a4 100644 (file)
@@ -68,6 +68,17 @@ namespace roast
                        stdio(){}
                        stdio(::FILE* fp) : _Base(fp){}
                        stdio(const char* path, const char* mode="r") : _Base(open_params_type(path, mode)){}
+                       
+                       /////////////////////////////////////////////////////////////////////////////////
+                       void seek_ex(long offset, int whence){
+                               this->handler_assert("seek");
+                               
+                               if ( ::fseek(this->get_handle(), offset, whence) != 0 )
+                                       throw io_exception("stdio::seek(): ::fseek() was failed.");
+                       }
+                       void seek(long offset){ seek_ex(offset, SEEK_CUR); }
+                       void seek_abs(long offset){ seek_ex(offset, SEEK_SET); }
+                       void seek_end(long offset=0){ seek_ex(offset, SEEK_END); }
                };
                
                ///////////////////////////////////////////////