Skip to content

Commit

Permalink
Adding rewinddir example
Browse files Browse the repository at this point in the history
fix example
  • Loading branch information
fjtrujy committed Nov 29, 2023
1 parent 213c45b commit 811c83e
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ee/libcglue/samples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.

SUBDIRS = mem_test nanosleep regress
SUBDIRS = mem_test nanosleep regress rewinddir

include $(PS2SDKSRC)/Defs.make
include $(PS2SDKSRC)/Rules.make
12 changes: 12 additions & 0 deletions ee/libcglue/samples/rewinddir/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.

SAMPLE_DIR = libcglue/readdir

include $(PS2SDKSRC)/Defs.make
include $(PS2SDKSRC)/samples/Rules.samples
40 changes: 40 additions & 0 deletions ee/libcglue/samples/rewinddir/Makefile.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.

SCREEN_DEBUG = 1
VERBOSE = 0

EE_BIN = rewinddir_test.elf
EE_OBJS = main.o

ifeq ($(SCREEN_DEBUG), 1)
EE_LIBS += -ldebug
EE_CFLAGS += -DSCREEN_DEBUG
endif

ifeq ($(VERBOSE), 1)
EE_CFLAGS += -DVERBOSE
endif

all: $(EE_BIN) input

input:
mkdir -p testfiles/
echo "hello world" > testfiles/dummy

clean:
rm -rf $(EE_BIN) $(EE_OBJS)

run: $(EE_BIN)
ps2client execee host:$(EE_BIN)

reset:
ps2client reset

include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
79 changes: 79 additions & 0 deletions ee/libcglue/samples/rewinddir/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright 2001-2005, ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.
#
# Malloc tester
*/

#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <kernel.h>

#if defined(SCREEN_DEBUG)
#include <debug.h>
#endif

#if defined(SCREEN_DEBUG)
#define custom_printf(args...) \
printf(args); \
scr_printf(args);
#else
#define custom_printf(args...) printf(args);
#endif

int main(int argc, char *argv[])
{
// Buffer to store the current working directory
char cwd[1024];

#if defined(SCREEN_DEBUG)
init_scr();
sleep(3);
#endif
custom_printf("\n\nStarting rewinddir TESTS...\n");

// Get the current working directory
if (getcwd(cwd, sizeof(cwd)) == NULL) {
custom_printf("Error getting current working directory");
return 1;
}

// Open the current directory
DIR *directory = opendir(cwd);

// Check if the directory can be opened
if (directory == NULL) {
custom_printf("Error opening directory");
return 1;
}

// Read directory entries
struct dirent *entry;
while ((entry = readdir(directory)) != NULL) {
// Check if the entry is a directory using d_type
custom_printf("%s -> %s\n", entry->d_name, entry->d_type == DT_DIR ? "Directory" : "File");
}

custom_printf("\n\nExecuting rewinddir function...\n");
rewinddir(directory);

while ((entry = readdir(directory)) != NULL) {
// Check if the entry is a directory using d_type
custom_printf("%s -> %s\n", entry->d_name, entry->d_type == DT_DIR ? "Directory" : "File");
}

custom_printf("\n\nTest finished!\n");

// Close the directory
closedir(directory);

SleepThread();

return 0;
}
1 change: 1 addition & 0 deletions samples/Makefile_sample
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ SUBDIRS += kernel/nanoHelloWorld
SUBDIRS += libcglue/regress
SUBDIRS += libcglue/mem_test
SUBDIRS += libcglue/nanosleep
SUBDIRS += libcglue/rewinddir
SUBDIRS += libgs/doublebuffer
SUBDIRS += libgs/draw
#SUBDIRS += mpeg #TODO: not modified for updated newlib
Expand Down

0 comments on commit 811c83e

Please sign in to comment.