OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [cxx/] [ustl/] [current/] [include/] [ustl/] [fstream.h] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// This file is part of the uSTL library, an STL implementation.
2
//
3
// Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
4
// This file is free software, distributed under the MIT License.
5
 
6
#ifndef FSTREAM_H_056E10F70EAD416443E3B36A2D6B5FA3
7
#define FSTREAM_H_056E10F70EAD416443E3B36A2D6B5FA3
8
 
9
#include "uios.h"
10
#include "ustring.h"
11
 
12
struct stat;
13
 
14
namespace ustl {
15
 
16
/// \class fstream fstream.h ustl.h
17
/// \ingroup DeviceStreams
18
///
19
/// \brief Implements file operations.
20
///
21
/// This is not implemented as a stream, but rather as a base for one. You
22
/// should use ifstream or ofstream if you want flow operators. Otherwise
23
/// this only implements functions for binary i/o.
24
///
25
class fstream : public ios_base {
26
public:
27
                        fstream (void);
28
    explicit            fstream (const char* filename, openmode mode = in | out);
29
    explicit            fstream (int nfd, const char* filename = "");
30
                       ~fstream (void) throw();
31
    void                open (const char* filename, openmode mode, mode_t perms = 0644);
32
    void                attach (int nfd, const char* filename = "");
33
    void                detach (void);
34
    void                close (void);
35
    void                sync (void);
36
    off_t               read (void* p, off_t n);
37
    off_t               readsome (void* p, off_t n);
38
    off_t               write (const void* p, off_t n);
39
    off_t               size (void) const;
40
    off_t               seek (off_t n, seekdir whence = beg);
41
    off_t               pos (void) const;
42
    void                stat (struct stat& rs) const;
43
    int                 ioctl (const char* rname, int request, long argument = 0);
44
    inline int          ioctl (const char* rname, int request, int argument)    { return (fstream::ioctl (rname, request, long(argument))); }
45
    inline int          ioctl (const char* rname, int request, void* argument)  { return (fstream::ioctl (rname, request, intptr_t(argument))); }
46
    int                 fcntl (const char* rname, int request, long argument = 0);
47
    inline int          fcntl (const char* rname, int request, int argument)    { return (fstream::fcntl (rname, request, long(argument))); }
48
    inline int          fcntl (const char* rname, int request, void* argument)  { return (fstream::fcntl (rname, request, intptr_t(argument))); }
49
#if 0 // memory mapped files are not supported in eCos
50
    memlink             mmap (off_t n, off_t offset = 0);
51
    void                munmap (memlink& l);
52
    void                msync (memlink& l);
53
#endif // #if 0
54
    void                set_nonblock (bool v = true);
55
    inline int          fd (void) const         { return (m_fd); }
56
    inline bool         is_open (void) const    { return (fd() >= 0); }
57
    inline off_t        tellg (void) const      { return (pos()); }
58
    inline off_t        tellp (void) const      { return (pos()); }
59
    inline void         seekg (off_t n, seekdir whence = beg)   { seek (n, whence); }
60
    inline void         seekp (off_t n, seekdir whence = beg)   { seek (n, whence); }
61
    inline void         flush (void)            { sync(); }
62
    inline const string& name (void) const      { return (m_Filename); }
63
private:
64
   DLL_LOCAL static int om_to_flags (openmode m);
65
    DLL_LOCAL void      set_and_throw (iostate s, const char* op);
66
private:
67
    int                 m_fd;           ///< Currently open file descriptor.
68
    string              m_Filename;     ///< Currently open filename.
69
};
70
 
71
/// Argument macro for fstream::ioctl. Use like fs.ioctl (IOCTLID (TCGETS), &ts).
72
#define IOCTLID(r)      "ioctl("#r")", r
73
#define FCNTLID(r)      "fcntl("#r")", r
74
 
75
} // namespace ustl
76
 
77
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.