Formatting and cleanup

This commit is contained in:
Maschell
2021-09-25 14:26:18 +02:00
parent 13ed348f43
commit aa90e2478b
38 changed files with 367 additions and 395 deletions

View File

@@ -1,13 +1,12 @@
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <cstdarg>
#include <cstdio>
#include <strings.h>
#include <fs/CFile.hpp>
CFile::CFile() {
iFd = -1;
mem_file = NULL;
mem_file = nullptr;
filesize = 0;
pos = 0;
}
@@ -78,7 +77,7 @@ void CFile::close() {
::close(iFd);
iFd = -1;
mem_file = NULL;
mem_file = nullptr;
filesize = 0;
pos = 0;
}
@@ -99,7 +98,7 @@ int32_t CFile::read(uint8_t *ptr, size_t size) {
if (readsize <= 0)
return readsize;
if (mem_file != NULL) {
if (mem_file != nullptr) {
memcpy(ptr, mem_file + pos, readsize);
pos += readsize;
return readsize;
@@ -147,7 +146,7 @@ int32_t CFile::seek(long int offset, int32_t origin) {
if (iFd >= 0)
ret = ::lseek(iFd, pos, SEEK_SET);
if (mem_file != NULL) {
if (mem_file != nullptr) {
if (pos > filesize) {
pos = filesize;
}

View File

@@ -1,9 +1,8 @@
#ifndef CFILE_HPP_
#define CFILE_HPP_
#pragma once
#include <stdio.h>
#include <cstdio>
#include <string>
#include <string.h>
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
#include <wut_types.h>
@@ -29,7 +28,7 @@ public:
int32_t open(const uint8_t *memory, int32_t memsize);
BOOL isOpen() const {
[[nodiscard]] BOOL isOpen() const {
if (iFd >= 0)
return true;
@@ -49,11 +48,11 @@ public:
int32_t seek(long int offset, int32_t origin);
uint64_t tell() {
[[nodiscard]] uint64_t tell() const {
return pos;
};
uint64_t size() {
[[nodiscard]] uint64_t size() const {
return filesize;
};
@@ -63,9 +62,7 @@ public:
protected:
int32_t iFd;
const uint8_t *mem_file;
uint64_t filesize;
uint64_t pos;
const uint8_t *mem_file{};
uint64_t filesize{};
uint64_t pos{};
};
#endif

View File

@@ -81,11 +81,11 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
if (folderpath.size() < 3)
return false;
struct dirent *dirent = NULL;
DIR *dir = NULL;
struct dirent *dirent = nullptr;
DIR *dir = nullptr;
dir = opendir(folderpath.c_str());
if (dir == NULL)
if (dir == nullptr)
return false;
while ((dirent = readdir(dir)) != 0) {
@@ -153,7 +153,7 @@ void DirList::ClearList() {
for (uint32_t i = 0; i < FileInfo.size(); ++i) {
if (FileInfo[i].FilePath) {
free(FileInfo[i].FilePath);
FileInfo[i].FilePath = NULL;
FileInfo[i].FilePath = nullptr;
}
}

View File

@@ -44,13 +44,13 @@ public:
//!\param path Path from where to load the filelist of all files
//!\param filter A fileext that needs to be filtered
//!\param flags search/filter flags from the enum
DirList(const std::string &path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
DirList(const std::string &path, const char *filter = nullptr, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
//!Destructor
virtual ~DirList();
//! Load all the files from a directory
BOOL LoadPath(const std::string &path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
BOOL LoadPath(const std::string &path, const char *filter = nullptr, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
//! Get a filename of the list
//!\param list index

View File

@@ -9,7 +9,7 @@
int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
//! always initialze input
*inbuffer = NULL;
*inbuffer = nullptr;
if (size)
*size = 0;
@@ -21,7 +21,7 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
lseek(iFd, 0, SEEK_SET);
uint8_t *buffer = (uint8_t *) malloc(filesize);
if (buffer == NULL) {
if (buffer == nullptr) {
close(iFd);
return -2;
}
@@ -44,7 +44,7 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
if (done != filesize) {
free(buffer);
buffer = NULL;
buffer = nullptr;
return -3;
}