Permalink
Browse files

use opendir instead of stat to see if directory exists

  • Loading branch information...
1 parent da206d8 commit 04d4f1c6dfd107830aa04e323a8742f0ad63adbc @FIX94 committed Dec 29, 2016
Showing with 29 additions and 9 deletions.
  1. +1 −1 Makefile
  2. +2 −2 src/fs/fs_utils.c
  3. +1 −1 src/main.c
  4. +25 −5 src/vrt.c
View
@@ -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
View
@@ -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;
}
View
@@ -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);
View
@@ -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, ...) {
@@ -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);

0 comments on commit 04d4f1c

Please sign in to comment.