File: autodir.h

package info (click to toggle)
rsyncrypto 1.12-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 1,312 kB
  • ctags: 576
  • sloc: sh: 3,958; cpp: 3,253; makefile: 70
file content (56 lines) | stat: -rw-r--r-- 990 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#if defined(_WIN32)
#include "win32/autodir.h"
#elif !defined(AUTODIR_H)
#define AUTODIR_H

// automap will auto-release mmaped areas
class autodir {
    DIR *dir;

    // Disable default copy constructor
    autodir( const autodir & );
    autodir &operator=( const autodir & );
public:
    explicit autodir( const char *dirname ) : dir(opendir(dirname))
    {
#if defined(EXCEPT_CLASS)
        if( dir==NULL )
            throw rscerror("opendir failed", errno, dirname);
#endif
    }
    ~autodir()
    {
        clear();
    }
    DIR *get() const
    {
        return dir;
    }

    void clear()
    {
        if( dir!=NULL ) {
            closedir( dir );
            dir=NULL;
        }
    }

    struct dirent *read()
    {
        return ::readdir(dir);
    }
    void rewind()
    {
        ::rewinddir(dir);
    }
    void seek( off_t offset )
    {
        seekdir( dir, offset );
    }
    off_t telldir()
    {
        return ::telldir( dir );
    }
};

#endif // AUTODIR_H