[WiiU] Reformat fs_utils.c

Was getting warnings around misleading indentation when there
was none, so just redid the whole file.
This commit is contained in:
Ash 2017-11-04 20:07:29 +11:00
parent 0d38612f4a
commit 5f00e2f6bb
No known key found for this signature in database
GPG Key ID: F8C85A8C836C0A7E

View File

@ -31,174 +31,174 @@
int MountFS(void *pClient, void *pCmd, char **mount_path) int MountFS(void *pClient, void *pCmd, char **mount_path)
{ {
int result = -1; int result = -1;
void *mountSrc = malloc(FS_MOUNT_SOURCE_SIZE); void *mountSrc = malloc(FS_MOUNT_SOURCE_SIZE);
if(!mountSrc) if(!mountSrc)
return -3; return -3;
char* mountPath = (char*) malloc(FS_MAX_MOUNTPATH_SIZE); char* mountPath = (char*) malloc(FS_MAX_MOUNTPATH_SIZE);
if(!mountPath) { if(!mountPath) {
free(mountSrc); free(mountSrc);
return -4; return -4;
} }
memset(mountSrc, 0, FS_MOUNT_SOURCE_SIZE); memset(mountSrc, 0, FS_MOUNT_SOURCE_SIZE);
memset(mountPath, 0, FS_MAX_MOUNTPATH_SIZE); memset(mountPath, 0, FS_MAX_MOUNTPATH_SIZE);
// Mount sdcard // Mount sdcard
if (FSGetMountSource(pClient, pCmd, FS_SOURCETYPE_EXTERNAL, mountSrc, -1) == 0) if (FSGetMountSource(pClient, pCmd, FS_SOURCETYPE_EXTERNAL, mountSrc, -1) == 0)
{ {
result = FSMount(pClient, pCmd, mountSrc, mountPath, FS_MAX_MOUNTPATH_SIZE, -1); result = FSMount(pClient, pCmd, mountSrc, mountPath, FS_MAX_MOUNTPATH_SIZE, -1);
if((result == 0) && mount_path) { if((result == 0) && mount_path) {
*mount_path = (char*)malloc(strlen(mountPath) + 1); *mount_path = (char*)malloc(strlen(mountPath) + 1);
if(*mount_path) if(*mount_path)
strcpy(*mount_path, mountPath); strcpy(*mount_path, mountPath);
} }
} }
free(mountPath); free(mountPath);
free(mountSrc); free(mountSrc);
return result; return result;
} }
int UmountFS(void *pClient, void *pCmd, const char *mountPath) int UmountFS(void *pClient, void *pCmd, const char *mountPath)
{ {
int result = -1; int result = -1;
result = FSUnmount(pClient, pCmd, mountPath, -1); result = FSUnmount(pClient, pCmd, mountPath, -1);
return result; return result;
} }
int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size) int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size)
{ {
//! always initialze input //! always initialze input
*inbuffer = NULL; *inbuffer = NULL;
if(size) if(size)
*size = 0; *size = 0;
int iFd = open(filepath, O_RDONLY); int iFd = open(filepath, O_RDONLY);
if (iFd < 0) if (iFd < 0)
return -1; return -1;
u32 filesize = lseek(iFd, 0, SEEK_END); u32 filesize = lseek(iFd, 0, SEEK_END);
lseek(iFd, 0, SEEK_SET); lseek(iFd, 0, SEEK_SET);
u8 *buffer = (u8 *) malloc(filesize); u8 *buffer = (u8 *) malloc(filesize);
if (buffer == NULL) if (buffer == NULL)
{ {
close(iFd); close(iFd);
return -2; return -2;
} }
u32 blocksize = 0x4000; u32 blocksize = 0x4000;
u32 done = 0; u32 done = 0;
int readBytes = 0; int readBytes = 0;
while(done < filesize) while(done < filesize)
{ {
if(done + blocksize > filesize) { if(done + blocksize > filesize) {
blocksize = filesize - done; blocksize = filesize - done;
} }
readBytes = read(iFd, buffer + done, blocksize); readBytes = read(iFd, buffer + done, blocksize);
if(readBytes <= 0) if(readBytes <= 0)
break; break;
done += readBytes; done += readBytes;
} }
close(iFd); close(iFd);
if (done != filesize) if (done != filesize)
{ {
free(buffer); free(buffer);
return -3; return -3;
} }
*inbuffer = buffer; *inbuffer = buffer;
//! sign is optional input //! sign is optional input
if(size) if(size)
*size = filesize; *size = filesize;
return filesize; return filesize;
} }
int CheckFile(const char * filepath) int CheckFile(const char * filepath)
{ {
if(!filepath) if(!filepath)
return 0; return 0;
struct stat filestat; struct stat filestat;
char dirnoslash[strlen(filepath)+2]; char dirnoslash[strlen(filepath)+2];
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath); snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
while(dirnoslash[strlen(dirnoslash)-1] == '/') while(dirnoslash[strlen(dirnoslash)-1] == '/')
dirnoslash[strlen(dirnoslash)-1] = '\0'; dirnoslash[strlen(dirnoslash)-1] = '\0';
char * notRoot = strrchr(dirnoslash, '/'); char * notRoot = strrchr(dirnoslash, '/');
if(!notRoot) if(!notRoot)
{ {
strcat(dirnoslash, "/"); strcat(dirnoslash, "/");
} }
if (stat(dirnoslash, &filestat) == 0) if (stat(dirnoslash, &filestat) == 0)
return 1; return 1;
return 0; return 0;
} }
int CreateSubfolder(const char * fullpath) int CreateSubfolder(const char * fullpath)
{ {
if(!fullpath) if(!fullpath)
return 0; return 0;
int result = 0; int result = 0;
char dirnoslash[strlen(fullpath)+1]; char dirnoslash[strlen(fullpath)+1];
strcpy(dirnoslash, fullpath); strcpy(dirnoslash, fullpath);
int pos = strlen(dirnoslash)-1; int pos = strlen(dirnoslash)-1;
while(dirnoslash[pos] == '/') while(dirnoslash[pos] == '/')
{ {
dirnoslash[pos] = '\0'; dirnoslash[pos] = '\0';
pos--; pos--;
} }
if(CheckFile(dirnoslash)) if(CheckFile(dirnoslash))
{ {
return 1; return 1;
} }
else else
{ {
char parentpath[strlen(dirnoslash)+2]; char parentpath[strlen(dirnoslash)+2];
strcpy(parentpath, dirnoslash); strcpy(parentpath, dirnoslash);
char * ptr = strrchr(parentpath, '/'); char * ptr = strrchr(parentpath, '/');
if(!ptr) if(!ptr)
{ {
//!Device root directory (must be with '/') //!Device root directory (must be with '/')
strcat(parentpath, "/"); strcat(parentpath, "/");
struct stat filestat; struct stat filestat;
if (stat(parentpath, &filestat) == 0) if (stat(parentpath, &filestat) == 0)
return 1; return 1;
return 0; return 0;
} }
ptr++; ptr++;
ptr[0] = '\0'; ptr[0] = '\0';
result = CreateSubfolder(parentpath); result = CreateSubfolder(parentpath);
} }
if(!result) if(!result)
return 0; return 0;
if (mkdir(dirnoslash, 0777) == -1) if (mkdir(dirnoslash, 0777) == -1)
{ {
return 0; return 0;
} }
return 1; return 1;
} }