Skip to content

SD library: Declare path parameter on all functions as const #3998

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

Merged
merged 1 commit into from
Oct 22, 2015
Merged
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
22 changes: 11 additions & 11 deletions libraries/SD/src/SD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace SDLib {
#define MAX_COMPONENT_LEN 12 // What is max length?
#define PATH_COMPONENT_BUFFER_LEN MAX_COMPONENT_LEN+1

bool getNextPathComponent(char *path, unsigned int *p_offset,
bool getNextPathComponent(const char *path, unsigned int *p_offset,
char *buffer) {
/*

Expand Down Expand Up @@ -117,9 +117,9 @@ bool getNextPathComponent(char *path, unsigned int *p_offset,



boolean walkPath(char *filepath, SdFile& parentDir,
boolean walkPath(const char *filepath, SdFile& parentDir,
boolean (*callback)(SdFile& parentDir,
char *filePathComponent,
const char *filePathComponent,
boolean isLastComponent,
void *object),
void *object = NULL) {
Expand Down Expand Up @@ -232,7 +232,7 @@ boolean walkPath(char *filepath, SdFile& parentDir,

*/

boolean callback_pathExists(SdFile& parentDir, char *filePathComponent,
boolean callback_pathExists(SdFile& parentDir, const char *filePathComponent,
boolean isLastComponent, void *object) {
/*

Expand All @@ -255,7 +255,7 @@ boolean callback_pathExists(SdFile& parentDir, char *filePathComponent,



boolean callback_makeDirPath(SdFile& parentDir, char *filePathComponent,
boolean callback_makeDirPath(SdFile& parentDir, const char *filePathComponent,
boolean isLastComponent, void *object) {
/*

Expand Down Expand Up @@ -310,15 +310,15 @@ boolean callback_openPath(SdFile& parentDir, char *filePathComponent,



boolean callback_remove(SdFile& parentDir, char *filePathComponent,
boolean callback_remove(SdFile& parentDir, const char *filePathComponent,
boolean isLastComponent, void *object) {
if (isLastComponent) {
return SdFile::remove(parentDir, filePathComponent);
}
return true;
}

boolean callback_rmdir(SdFile& parentDir, char *filePathComponent,
boolean callback_rmdir(SdFile& parentDir, const char *filePathComponent,
boolean isLastComponent, void *object) {
if (isLastComponent) {
SdFile f;
Expand Down Expand Up @@ -517,7 +517,7 @@ File SDClass::open(char *filepath, uint8_t mode) {
//}


boolean SDClass::exists(char *filepath) {
boolean SDClass::exists(const char *filepath) {
/*

Returns true if the supplied file path exists.
Expand All @@ -538,7 +538,7 @@ boolean SDClass::exists(char *filepath) {
//}


boolean SDClass::mkdir(char *filepath) {
boolean SDClass::mkdir(const char *filepath) {
/*

Makes a single directory or a heirarchy of directories.
Expand All @@ -549,7 +549,7 @@ boolean SDClass::mkdir(char *filepath) {
return walkPath(filepath, root, callback_makeDirPath);
}

boolean SDClass::rmdir(char *filepath) {
boolean SDClass::rmdir(const char *filepath) {
/*

Remove a single directory or a heirarchy of directories.
Expand All @@ -560,7 +560,7 @@ boolean SDClass::rmdir(char *filepath) {
return walkPath(filepath, root, callback_rmdir);
}

boolean SDClass::remove(char *filepath) {
boolean SDClass::remove(const char *filepath) {
return walkPath(filepath, root, callback_remove);
}

Expand Down
10 changes: 5 additions & 5 deletions libraries/SD/src/SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ class SDClass {
File open(const String &filename, uint8_t mode = FILE_READ) { return open( filename.c_str(), mode ); }

// Methods to determine if the requested file path exists.
boolean exists(char *filepath);
boolean exists(const char *filepath);
boolean exists(const String &filepath) { return exists(filepath.c_str()); }

// Create the requested directory heirarchy--if intermediate directories
// do not exist they will be created.
boolean mkdir(char *filepath);
boolean mkdir(const char *filepath);
boolean mkdir(const String &filepath) { return mkdir(filepath.c_str()); }

// Delete the file.
boolean remove(char *filepath);
boolean remove(const char *filepath);
boolean remove(const String &filepath) { return remove(filepath.c_str()); }

boolean rmdir(char *filepath);
boolean rmdir(const char *filepath);
boolean rmdir(const String &filepath) { return rmdir(filepath.c_str()); }

private:
Expand All @@ -101,7 +101,7 @@ class SDClass {
int fileOpenMode;

friend class File;
friend boolean callback_openPath(SdFile&, char *, boolean, void *);
friend boolean callback_openPath(SdFile&, const char *, boolean, void *);
};

extern SDClass SD;
Expand Down