From 65dc706027546886461dc4ea170c6d7bd88fbf8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 10 Jul 2002 21:48:27 +0000 Subject: [PATCH] Converted module.c to use sys_read_dir() instead of sys_read(). But it really should use opendir(), and readdir(). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@60 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/module.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/kernel/core/module.c b/src/kernel/core/module.c index ed3caa172b..f58d358a70 100644 --- a/src/kernel/core/module.c +++ b/src/kernel/core/module.c @@ -425,34 +425,35 @@ static int recurse_check_file(const char *filepath, const char *srcfile) */ static int recurse_directory(const char *path, const char *match) { + /* ToDo: should just use opendir(), readdir(), ... */ struct stat stat; - int res = 0, file; - char *name; + int res = 0, dir; + int bufferSize = sizeof(struct dirent) + SYS_MAX_NAME_LEN + 1; + struct dirent *dirent; - if ((file = sys_open(path, STREAM_TYPE_DIR, 0)) < 0) { + if ((dir = sys_open(path, STREAM_TYPE_DIR, 0)) < 0) return -1; - } - - name = (char*)kmalloc(SYS_MAX_NAME_LEN); - if (!name) + + dirent = kmalloc(bufferSize); + if (!dirent) return -1; - + /* loop until we have a match or we run out of entries */ while (res <= 0) { char *newpath; size_t slen = 0; SHOW_FLOW(3, "scanning %s\n", path); - name[0] = '\0'; - if ((res = sys_read(file, name, 0, SYS_MAX_NAME_LEN)) <= 0) { + if ((res = sys_read_dir(dir, dirent, bufferSize, 1)) <= 0) break; - } - slen = strlen(path) + strlen(name) + 2; + dirent->d_name[dirent->d_reclen] = '\0'; + + slen = strlen(path) + strlen(dirent->d_name) + 2; newpath = (char*)kmalloc(slen); strlcpy(newpath, path, slen); strlcat(newpath, "/", slen); - strlcat(newpath, name, slen); + strlcat(newpath, dirent->d_name, slen); if ((res = sys_rstat(newpath, &stat)) != B_NO_ERROR) { kfree(newpath); @@ -481,9 +482,9 @@ static int recurse_directory(const char *path, const char *match) kfree(newpath); } - kfree(name); - sys_close(file); - + kfree(dirent); + sys_close(dir); + return res; }