diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2015-05-07 11:02:15 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2015-05-07 11:02:15 +0200 |
commit | 8ac849f21ed34c447d7744cdaf76c3e10d8045cc (patch) | |
tree | 4509c95915ab853dcc19b3149ad669ddb8eb7006 /tests | |
parent | 84261462f3a8fef4bbb1727e7219a720989a4de4 (diff) | |
download | pgfuse-8ac849f21ed34c447d7744cdaf76c3e10d8045cc.tar.gz pgfuse-8ac849f21ed34c447d7744cdaf76c3e10d8045cc.tar.bz2 |
testing O_APPEND and O_TRUNC behaviour when opening files
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testopen.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/tests/testopen.c b/tests/testopen.c index c67a755..1be8bca 100644 --- a/tests/testopen.c +++ b/tests/testopen.c @@ -74,7 +74,46 @@ int main( void ) return 1; } - /* Third one should success and truncate the file */ + /* Third one should success and append to the file */ + fd = open( "./mnt/testopen", O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR ); + + /* check if the file has size 4096 */ + res = stat( "./mnt/testopen", &s ); + if( res < 0 ) { + perror( "Error stating testopen" ); + return 1; + } + if( s.st_size == 4096 ) { + // OK + } else { + fprintf( stderr, "Size of file should be 4096, but is %jd\n", s.st_size ); + return 1; + } + + /* write some more data, this data should be appended */ + wres = write( fd, buf, 4096 ); + if( wres != 4096 ) { + perror( "Error writing" ); + (void)close( fd ); + return 1; + } + + (void)close( fd ); + + /* check if the file has size 2 * 4096 now */ + res = stat( "./mnt/testopen", &s ); + if( res < 0 ) { + perror( "Error stating testopen" ); + return 1; + } + if( s.st_size == 8192 ) { + // OK + } else { + fprintf( stderr, "Size of file should be 8192, but is %jd\n", s.st_size ); + return 1; + } + + /* Fourth one should success and truncate the file */ fd = open( "./mnt/testopen", O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR ); (void)close( fd ); |