-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_fio.h
93 lines (75 loc) · 3.52 KB
/
my_fio.h
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// Copyright 2015 by Kevin L. Goodwin [[email protected]]; All rights reserved
//
// This file is part of K.
//
// K is free software: you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// K is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with K. If not, see <http://www.gnu.org/licenses/>.
//
//
// FileIO System-call wrappers
//
#pragma once
#include "my_types.h"
#include <cstdio>
#if defined(_WIN32)
#include <direct.h>
#include <io.h>
#endif
#include <fcntl.h>
#include <errno.h>
#define DFLT_TEXTFILE_CREATE_MODE 0666
class fio { // could use namespace vs. class but cannot declare private members of namespace
STATIC_FXN ssize_t Read ( int fh, PVoid pBuf, ssize_t bytesToRead );
STATIC_FXN ssize_t Write( int fh, PCVoid pBuf, ssize_t bytesToWrite );
public:
STATIC_FXN bool OpenFileFailed( int *pfh, PCChar pszFileName, bool fWrAccess, int create_mode=0 );
STIL bool ReadOk( int fh, PVoid pBuffer, int bytes ) { return Read( fh, pBuffer, bytes ) == bytes; }
STIL bool WriteOk( int fh, PCVoid pBuffer, int bytes ) { return Write( fh, pBuffer, bytes ) == bytes; }
#if defined(_WIN32)
STIL int Close( int fh ) { return _close( fh ); } // -1 == error, 0 == success
STIL int Fsync( int fh ) { return _commit( fh ); } // -1 == error, 0 == success
STIL __int64 Lseek( int fh, __int64 lDistanceToMove, int dwMoveMethod ) { return _lseeki64( fh, lDistanceToMove, dwMoveMethod ); }
STIL __int64 SeekEoF( int fh ) { return Lseek( fh, 0, SEEK_END ); }
#else
STIL int Close( int fh ) { return close( fh ); } // -1 == error, 0 == success
STIL int Fsync( int fh ) { return fsync( fh ); } // -1 == error, 0 == success
STIL off_t Lseek( int fh, off_t lDistanceToMove, int dwMoveMethod ) { return lseek( fh, lDistanceToMove, dwMoveMethod ); }
STIL off_t SeekEoF( int fh ) { return Lseek( fh, 0, SEEK_END ); }
#endif
STIL void SeekBoF( int fh ) { Lseek( fh, 0, SEEK_SET ); }
};
extern bool MoveFileOk( PCChar pszCurFileName, PCChar pszNewFilename );
#define CopyFileManuallyOk( pszCurFileName, pszNewFilename ) CopyFileManuallyOk_( pszCurFileName, pszNewFilename, __func__ )
extern bool CopyFileManuallyOk_( PCChar pszCurFileName, PCChar pszNewFilename, PCChar caller );
#define VERBOSE_READ 1
#if VERBOSE_READ
# define VR_( x ) x
#else
# define VR_( x )
#endif
#if 0
// read: classic look
#define kszRdNoiseOpen " Open "
#define kszRdNoiseSeek " Open Size "
#define kszRdNoiseAllc " Open Size Alloc "
#define kszRdNoiseRead " Open Size Alloc Read "
#define kszRdNoiseScan " Open Size Alloc Read Scan "
#else
// read: duty-cycle look
#define kszRdNoiseOpen " Open "
#define kszRdNoiseSeek " Size "
#define kszRdNoiseAllc " Alloc "
#define kszRdNoiseRead " Read "
#define kszRdNoiseScan " Scan "
#endif