• Main Page
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

ucommon/fsys.h

Go to the documentation of this file.
00001 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
00002 //
00003 // This file is part of GNU uCommon C++.
00004 //
00005 // GNU uCommon C++ is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published 
00007 // by the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // GNU uCommon C++ is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with GNU uCommon C++.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 #ifndef _UCOMMON_FILE_H_
00028 #define _UCOMMON_FILE_H_
00029 
00030 #ifndef _UCOMMON_CONFIG_H_
00031 #include <ucommon/platform.h>
00032 #endif
00033 
00034 #ifndef _UCOMMON_THREAD_H_
00035 #include <ucommon/thread.h>
00036 #endif
00037 
00038 #ifndef _MSWINDOWS_
00039 #include <sys/stat.h>
00040 #endif
00041 
00042 #include <errno.h>
00043 #include <stdio.h>
00044 
00045 NAMESPACE_UCOMMON
00046 
00050 typedef void *dir_t;
00051 
00055 typedef void *mem_t;
00056 
00065 class __EXPORT fsys
00066 {
00067 protected:
00068     fd_t    fd;
00069 #ifdef  _MSWINDOWS_
00070     WIN32_FIND_DATA *ptr;
00071     HINSTANCE   mem;
00072 #else
00073     void    *ptr;
00074 #endif
00075     int     error;
00076 
00077 public:
00078 #ifdef  _MSWINDOWS_
00079     static int remapError(void);
00080 #else
00081     inline static int remapError(void)
00082         {return errno;};
00083 #endif
00084 
00088     typedef enum {
00089         ACCESS_RDONLY,
00090         ACCESS_WRONLY,
00091         ACCESS_REWRITE,
00092         ACCESS_RDWR = ACCESS_REWRITE,
00093         ACCESS_APPEND,
00094         ACCESS_SHARED,
00095         ACCESS_DIRECTORY,
00096         ACCESS_STREAM,
00097         ACCESS_RANDOM
00098     } access_t;
00099 
00103     typedef long offset_t;
00104 
00108     static const offset_t end;
00109 
00113     fsys();
00114 
00119     fsys(const fsys& descriptor);
00120 
00126     fsys(const char *path, access_t access);
00127 
00134     fsys(const char *path, access_t access, unsigned permission);
00135 
00139     ~fsys();
00140 
00145     inline fd_t operator*() const
00146         {return fd;};
00147 
00152     inline operator fd_t() const
00153         {return fd;};
00154 
00159     inline operator bool() const
00160         {return fd != INVALID_HANDLE_VALUE || ptr != NULL;};
00161 
00166     inline bool operator!() const
00167         {return fd == INVALID_HANDLE_VALUE && ptr == NULL;};
00168 
00173     void operator=(const fsys& descriptor);
00174 
00179     void operator=(fd_t descriptor);
00180 
00186     inline int getError(void) const
00187         {return error;};
00188 
00193     inline fd_t getHandle(void) const
00194         {return fd;};
00195 
00201     int seek(offset_t offset);
00202 
00208     int drop(offset_t size = 0);    
00209 
00216     ssize_t read(void *buffer, size_t count);
00217 
00224     ssize_t write(const void *buffer, size_t count);
00225 
00231     int stat(struct stat *buffer);
00232 
00239     int trunc(offset_t offset);
00240 
00245     int sync(void);
00246 
00252     static int changeDir(const char *path);
00253 
00260     static int getPrefix(char *path, size_t size);
00261 
00268     static int stat(const char *path, struct stat *buffer);
00269     
00275     static int remove(const char *path);
00276 
00283     static int rename(const char *oldpath, const char *newpath);
00284 
00291     static int change(const char *path, unsigned mode);
00292     
00299     static int access(const char *path, unsigned mode);
00300 
00306     static bool isfile(const char *path);
00307 
00313     static bool isdir(const char *path);
00314 
00315 
00323     inline static ssize_t read(fsys& descriptor, void *buffer, size_t count)
00324         {return descriptor.read(buffer, count);};
00325 
00333     inline static ssize_t write(fsys& descriptor, const void *buffer, size_t count)
00334         {return descriptor.write(buffer, count);};
00335 
00342     inline static int seek(fsys& descriptor, offset_t offset)
00343         {return descriptor.seek(offset);};
00344 
00351     inline static int drop(fsys& descriptor, offset_t size)
00352         {return descriptor.drop(size);};
00353 
00359     void open(const char *path, access_t access);
00360 
00365     inline void assign(fd_t descriptor)
00366         {close(); fd = descriptor;};
00367 
00373     inline static void assign(fsys& object, fd_t descriptor)
00374         {object.close(); object.fd = descriptor;};
00375 
00382     void create(const char *path, access_t access, unsigned mode);
00383 
00390     static int createDir(const char *path, unsigned mode); 
00391 
00397     static int removeDir(const char *path);
00398 
00403     inline static void close(fsys& descriptor)
00404         {descriptor.close();};
00405 
00409     void close(void);
00410 
00417     inline static void open(fsys& object, const char *path, access_t access)
00418         {object.open(path, access);};
00419 
00427     inline static void create(fsys& object, const char *path, access_t access, unsigned mode)
00428         {object.create(path, access, mode);};
00429 
00435     static int load(const char *path);
00436 
00442     static void load(fsys& module, const char *path);
00443 
00448     static void unload(fsys& module);
00449     
00456     static void *find(fsys& module, const char *symbol);
00457 
00465     static size_t printf(FILE *file, const char *format, ...) __PRINTF(2, 3);
00466     
00474     static size_t writes(FILE *file, const char *string);
00475 
00485     static size_t readln(FILE *file, char *address, size_t size);
00486 };
00487     
00491 typedef fsys fsys_t;
00492 
00493 END_NAMESPACE
00494 
00495 #endif
00496 

Generated on Sun Sep 4 2011 for UCommon by  doxygen 1.7.1