Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constify file system functions arguments #525

Open
wants to merge 1 commit into
base: v1.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions hal/filesystem/linux/file_provider_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct sDirectoryHandle {
};

FileHandle
FileSystem_openFile(char* fileName, bool readWrite)
FileSystem_openFile(const char* fileName, bool readWrite)
{
FileHandle newHandle = NULL;

Expand All @@ -57,7 +57,7 @@ FileSystem_readFile(FileHandle handle, uint8_t* buffer, int maxSize)
}

int
FileSystem_writeFile(FileHandle handle, uint8_t* buffer, int size)
FileSystem_writeFile(FileHandle handle, const uint8_t* buffer, int size)
{
return fwrite(buffer, 1, size, (FILE*) handle);
}
Expand All @@ -69,7 +69,7 @@ FileSystem_closeFile(FileHandle handle)
}

bool
FileSystem_deleteFile(char* filename)
FileSystem_deleteFile(const char* filename)
{
if (remove(filename) == 0)
return true;
Expand All @@ -78,7 +78,7 @@ FileSystem_deleteFile(char* filename)
}

bool
FileSystem_renameFile(char* oldFilename, char* newFilename)
FileSystem_renameFile(const char* oldFilename, const char* newFilename)
{
if (rename(oldFilename, newFilename) == 0)
return true;
Expand All @@ -88,7 +88,7 @@ FileSystem_renameFile(char* oldFilename, char* newFilename)


bool
FileSystem_getFileInfo(char* filename, uint32_t* fileSize, uint64_t* lastModificationTimestamp)
FileSystem_getFileInfo(const char* filename, uint32_t* fileSize, uint64_t* lastModificationTimestamp)
{
struct stat fileStats;

Expand All @@ -106,7 +106,7 @@ FileSystem_getFileInfo(char* filename, uint32_t* fileSize, uint64_t* lastModific
}

DirectoryHandle
FileSystem_openDirectory(char* directoryName)
FileSystem_openDirectory(const char* directoryName)
{
DIR* dirHandle = opendir(directoryName);

Expand All @@ -120,7 +120,7 @@ FileSystem_openDirectory(char* directoryName)
return handle;
}

char*
const char*
FileSystem_readDirectory(DirectoryHandle directory, bool* isDirectory)
{
struct dirent* dir;
Expand Down
14 changes: 7 additions & 7 deletions hal/filesystem/win32/file_provider_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct sDirectoryHandle {


FileHandle
FileSystem_openFile(char* fileName, bool readWrite)
FileSystem_openFile(const char* fileName, bool readWrite)
{
FileHandle newHandle = NULL;

Expand All @@ -66,7 +66,7 @@ FileSystem_readFile(FileHandle handle, uint8_t* buffer, int maxSize)
}

int
FileSystem_writeFile(FileHandle handle, uint8_t* buffer, int size)
FileSystem_writeFile(FileHandle handle, const uint8_t* buffer, int size)
{
return fwrite(buffer, 1, size, (FILE*) handle);
}
Expand All @@ -78,7 +78,7 @@ FileSystem_closeFile(FileHandle handle)
}

bool
FileSystem_getFileInfo(char* filename, uint32_t* fileSize, uint64_t* lastModificationTimestamp)
FileSystem_getFileInfo(const char* filename, uint32_t* fileSize, uint64_t* lastModificationTimestamp)
{
WIN32_FILE_ATTRIBUTE_DATA fad;

Expand All @@ -104,7 +104,7 @@ FileSystem_getFileInfo(char* filename, uint32_t* fileSize, uint64_t* lastModific
}

DirectoryHandle
FileSystem_openDirectory(char* directoryName)
FileSystem_openDirectory(const char* directoryName)
{
DirectoryHandle dirHandle = (DirectoryHandle) GLOBAL_CALLOC(1, sizeof(struct sDirectoryHandle));

Expand Down Expand Up @@ -168,7 +168,7 @@ getNextDirectoryEntry(DirectoryHandle directory, bool* isDirectory)


bool
FileSystem_deleteFile(char* filename)
FileSystem_deleteFile(const char* filename)
{
if (remove(filename) == 0)
return true;
Expand All @@ -177,7 +177,7 @@ FileSystem_deleteFile(char* filename)
}

bool
FileSystem_renameFile(char* oldFilename, char* newFilename)
FileSystem_renameFile(const char* oldFilename, const char* newFilename)
{
if (rename(oldFilename, newFilename) == 0)
return true;
Expand All @@ -186,7 +186,7 @@ FileSystem_renameFile(char* oldFilename, char* newFilename)
}


char*
const char*
FileSystem_readDirectory(DirectoryHandle directory, bool* isDirectory)
{
char* fileName = getNextDirectoryEntry(directory, isDirectory);
Expand Down
14 changes: 7 additions & 7 deletions hal/inc/hal_filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef struct sDirectoryHandle* DirectoryHandle;
* NULL if opening fails
*/
PAL_API FileHandle
FileSystem_openFile(char* pathName, bool readWrite);
FileSystem_openFile(const char* pathName, bool readWrite);

/**
* \brief read from an open file
Expand Down Expand Up @@ -73,7 +73,7 @@ FileSystem_readFile(FileHandle handle, uint8_t* buffer, int maxSize);
* \return the number of bytes actually written
*/
PAL_API int
FileSystem_writeFile(FileHandle handle, uint8_t* buffer, int size);
FileSystem_writeFile(FileHandle handle, const uint8_t* buffer, int size);

/**
* \brief close an open file
Expand All @@ -97,7 +97,7 @@ FileSystem_closeFile(FileHandle handle);
* \return true if file exists, false if not
*/
PAL_API bool
FileSystem_getFileInfo(char* filename, uint32_t* fileSize, uint64_t* lastModificationTimestamp);
FileSystem_getFileInfo(const char* filename, uint32_t* fileSize, uint64_t* lastModificationTimestamp);

/**
* \brief delete a file
Expand All @@ -107,7 +107,7 @@ FileSystem_getFileInfo(char* filename, uint32_t* fileSize, uint64_t* lastModific
* \return true on success, false on error
*/
PAL_API bool
FileSystem_deleteFile(char* filename);
FileSystem_deleteFile(const char* filename);

/**
* \brief rename a file
Expand All @@ -118,7 +118,7 @@ FileSystem_deleteFile(char* filename);
* \return true on success, false on error
*/
PAL_API bool
FileSystem_renameFile(char* oldFilename, char* newFilename);
FileSystem_renameFile(const char* oldFilename, const char* newFilename);

/**
* \brief open the directoy with the specified name
Expand All @@ -128,7 +128,7 @@ FileSystem_renameFile(char* oldFilename, char* newFilename);
* \return a handle for the opened directory to be used in subsequent calls to identify the directory
*/
PAL_API DirectoryHandle
FileSystem_openDirectory(char* directoryName);
FileSystem_openDirectory(const char* directoryName);

/**
* \brief read the next directory entry
Expand All @@ -142,7 +142,7 @@ FileSystem_openDirectory(char* directoryName);
*
* \return the name of the directory entry
*/
PAL_API char*
PAL_API const char*
FileSystem_readDirectory(DirectoryHandle directory, bool* isDirectory);


Expand Down
2 changes: 1 addition & 1 deletion src/mms/iso_mms/server/mms_file_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ addFileEntriesToResponse(const char* basepath, uint8_t* buffer, int bufPos, int
if (directory != NULL) {

bool isDirectory;
char* fileName = FileSystem_readDirectory(directory, &isDirectory);
const char* fileName = FileSystem_readDirectory(directory, &isDirectory);

while (fileName != NULL) {
directoryName[directoryNameLength] = 0;
Expand Down