summaryrefslogtreecommitdiffstats
path: root/src/server/fileutil.c
diff options
context:
space:
mode:
authorSimon Rettberg2014-12-31 23:39:21 +0100
committerSimon Rettberg2014-12-31 23:39:21 +0100
commit6788efa3459b9581b1e4197e37f504d8fb2e8e87 (patch)
treef177c92792884dd98c82b8d8828b092b2119a36c /src/server/fileutil.c
parent[SERVER] Minor tweaks and improvements (diff)
downloaddnbd3-6788efa3459b9581b1e4197e37f504d8fb2e8e87.tar.gz
dnbd3-6788efa3459b9581b1e4197e37f504d8fb2e8e87.tar.xz
dnbd3-6788efa3459b9581b1e4197e37f504d8fb2e8e87.zip
[SERVER] Use stdbool.h for booleans; minor refactoring of variable and function names
Diffstat (limited to 'src/server/fileutil.c')
-rw-r--r--src/server/fileutil.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/server/fileutil.c b/src/server/fileutil.c
index 5adc90a..d16c4d8 100644
--- a/src/server/fileutil.c
+++ b/src/server/fileutil.c
@@ -9,53 +9,53 @@
#include <assert.h>
#include <string.h>
-int file_isReadable(char *file)
+bool file_isReadable(char *file)
{
int fd = open( file, O_RDONLY );
- if ( fd < 0 ) return FALSE;
+ if ( fd < 0 ) return false;
close( fd );
- return TRUE;
+ return true;
}
-int file_isWritable(char *file)
+bool file_isWritable(char *file)
{
int fd = open( file, O_WRONLY );
if ( fd >= 0 ) {
close( fd );
- return TRUE;
+ return true;
}
fd = open( file, O_WRONLY | O_CREAT, 0600 );
- if ( fd < 0 ) return FALSE;
+ if ( fd < 0 ) return false;
close( fd );
unlink( file );
- return TRUE;
+ return true;
}
-int mkdir_p(const char* path)
+bool mkdir_p(const char* path)
{
assert( path != NULL );
- if ( *path == '\0' ) return TRUE;
+ if ( *path == '\0' ) return true;
char buffer[strlen( path ) + 1];
strcpy( buffer, path );
char *current = buffer;
char *slash;
while ( (slash = strchr( current, '/' )) != NULL ) {
*slash = '\0';
- if ( *buffer != '\0' && mkdir( buffer, 0750 ) != 0 && errno != EEXIST ) return FALSE;
+ if ( *buffer != '\0' && mkdir( buffer, 0755 ) != 0 && errno != EEXIST ) return false;
*slash = '/';
current = slash + 1;
}
- if ( mkdir( buffer, 0750 ) != 0 && errno != EEXIST ) return FALSE;
- return TRUE;
+ if ( mkdir( buffer, 0755 ) != 0 && errno != EEXIST ) return false;
+ return true;
}
-int file_alloc(int fd, uint64_t offset, uint64_t size)
+bool file_alloc(int fd, uint64_t offset, uint64_t size)
{
- if ( fallocate( fd, 0, offset, size ) == 0 ) return TRUE; // fast way
- if ( posix_fallocate( fd, offset, size ) == 0 ) return TRUE; // slow way
- if ( lseek( fd, offset + size - 1, SEEK_SET ) != offset ) return FALSE; // dumb way
- if ( write( fd, "", 1 ) != 1 ) return FALSE;
- return TRUE;
+ if ( fallocate( fd, 0, offset, size ) == 0 ) return true; // fast way
+ if ( posix_fallocate( fd, offset, size ) == 0 ) return true; // slow way
+ if ( lseek( fd, offset + size - 1, SEEK_SET ) != offset ) return false; // dumb way
+ if ( write( fd, "", 1 ) != 1 ) return false;
+ return true;
}
int64_t file_freeDiskSpace(const char * const path)