summaryrefslogtreecommitdiffstats
path: root/src/server/fileutil.c
diff options
context:
space:
mode:
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)