Skip to content

Commit

Permalink
use opendir instead of stat to see if directory exists
Browse files Browse the repository at this point in the history
  • Loading branch information
FIX94 committed Dec 29, 2016
1 parent da206d8 commit 04d4f1c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ MAKEFLAGS += --no-print-directory
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lgcc -lgd -lpng -lz -lfreetype -lvorbisidec -lfat -liosuhax
LIBS := -lgcc -lfat -liosuhax

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
Expand Down
4 changes: 2 additions & 2 deletions src/fs/fs_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size)
*inbuffer = buffer;

//! sign is optional input
if(size)
if(size) {
*size = filesize;

}
return filesize;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ int Menu_Main(void)
OSScreenFlipBuffersEx(0);
OSScreenFlipBuffersEx(1);

console_printf("FTPiiU v0.4 is listening on %u.%u.%u.%u:%i", (network_gethostip() >> 24) & 0xFF, (network_gethostip() >> 16) & 0xFF, (network_gethostip() >> 8) & 0xFF, (network_gethostip() >> 0) & 0xFF, PORT);
console_printf("FTPiiU v0.4u2 is listening on %u.%u.%u.%u:%i", (network_gethostip() >> 24) & 0xFF, (network_gethostip() >> 16) & 0xFF, (network_gethostip() >> 8) & 0xFF, (network_gethostip() >> 0) & 0xFF, PORT);

int serverSocket = create_server(PORT);

Expand Down
30 changes: 25 additions & 5 deletions src/vrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ char *to_real_path(char *virtual_cwd, char *virtual_path) {
return path;
}

static int checkdir(char *path) {
DIR *dir = opendir(path);
if(dir)
{
closedir(dir);
return 0;
}
return -1;
}

typedef void * (*path_func)(char *path, ...);

static void *with_virtual_path(void *virtual_cwd, void *void_f, char *virtual_path, s32 failed, ...) {
Expand Down Expand Up @@ -205,13 +215,23 @@ int vrt_stat(char *cwd, char *path, struct stat *st) {
return (int)with_virtual_path(cwd, stat, path, -1, st, NULL);
}

static int vrt_checkdir(char *cwd, char *path) {
char *real_path = to_real_path(cwd, path);
if (!real_path)
{
return -1;
}
else if (!*real_path || (strcmp(path, ".") == 0) || (strlen(cwd) == 1) || ((strlen(cwd) > 1) && (strcmp(path, "..") == 0)))
{
return 0;
}
free(real_path);
return (int)with_virtual_path(cwd, checkdir, path, -1, NULL);
}

int vrt_chdir(char *cwd, char *path) {

struct stat st;
if (vrt_stat(cwd, path, &st)) {
return -1;
} else if (!(st.st_mode & S_IFDIR)) {
errno = ENOTDIR;
if (vrt_checkdir(cwd, path)) {
return -1;
}
char *abspath = virtual_abspath(cwd, path);
Expand Down

0 comments on commit 04d4f1c

Please sign in to comment.