[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH 2/2] lib/vfscore: Add scandir


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Vlad-Andrei BĂDOIU <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
  • Date: Tue, 31 Mar 2020 15:03:19 +0300
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=stud.acs.upb.ro; dmarc=pass action=none header.from=stud.acs.upb.ro; dkim=pass header.d=stud.acs.upb.ro; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OrLQWMLAc/6BDEjC5RmhUpbpUwMsZvuFnKtgmiTOeTQ=; b=l6k8TiP07s+QiJL/FmNghsAHlsLdkqy1YWv10YWHZuvgWBCFi1z2Dy1fZi8+1IUl+SDurdfV1mLMuHnvcZuZQr3xRs4BjSPLyf33Zhin0qRSvzpvzEgF2Fhz9CSnUdUa68tfA2T49tSGK2wh+OLJcmYHlG9KGCdcOg3RqpvD+PFza8LQRH9HpyzGb7hpjvUQbd7O2KF5wdhJ0g3OAjlrkWFhR77Z96SiOJ1sCwJ30HfdnWUqYeqjL1r+28NDpf8hzxoKwrLZDo8Z6Zxt6q3jPikX+9jIT+18lPkyYccmVLgGNC/HdjqUQit0wOrhdNuYSDeeyvjtsetAd69emp/xnA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hUe8qqzIMoBjZZcSXYOu6OSMwCzjzeV1DNOolvf2gh4ITvCqBzOm+uGTqXLNFn08Qwwiu4dQm87pQAYlS54GForFfF8dJrEltHohUdYRCGcIYZ/yQ90yPlT1Hi15iAV3tUvc+JkNOY0QsU9H1uLJNjuQOOvMv88JhDWoctvmqFTXxeM862ru+Ay9tQVgQrJHca6W/w+EDbYVIJx0R59O5XfItLVrN/OLSEiIu081/EEbUjnBBmc+bG+PeOK1P56ywi5OQAxkIUMCk/LTH2nw49GLAexhba0T82s4huATjPs0erKJT7u22kLQbfVkTarYx+p92+F47nm6r3mp4v83Ug==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=vlad_andrei.badoiu@xxxxxxxxxxxxxxx;
  • Cc: felipe.huici@xxxxxxxxx, Vlad-Andrei BĂDOIU <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 31 Mar 2020 12:03:44 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

We adapt the scandir implementation for musl to work
with our vfscore implementation.

Signed-off-by: Vlad-Andrei BĂDOIU <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
---
 lib/vfscore/exportsyms.uk |  1 +
 lib/vfscore/main.c        | 48 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/lib/vfscore/exportsyms.uk b/lib/vfscore/exportsyms.uk
index e863a544..223bb72b 100644
--- a/lib/vfscore/exportsyms.uk
+++ b/lib/vfscore/exportsyms.uk
@@ -131,3 +131,4 @@ futimens
 utimes
 lutimes
 posix_fadvise
+scandir
diff --git a/lib/vfscore/main.c b/lib/vfscore/main.c
index 8c80ea61..846e2efd 100644
--- a/lib/vfscore/main.c
+++ b/lib/vfscore/main.c
@@ -36,6 +36,7 @@
 #include <sys/stat.h>
 #include <limits.h>
 #include <string.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <vfscore/prex.h>
@@ -708,6 +709,53 @@ int closedir(DIR *dir)
        return 0;
 }
 
+int scandir(const char *path, struct dirent ***res,
+       int (*sel)(const struct dirent *),
+       int (*cmp)(const struct dirent **, const struct dirent **))
+{
+       DIR *d = opendir(path);
+       struct dirent *de, **names=0, **tmp;
+       size_t cnt=0, len=0;
+       int old_errno = errno;
+
+       if (!d)
+               return -1;
+
+       while ((errno=0), (de = readdir(d))) {
+               if (sel && !sel(de))
+                       continue;
+               if (cnt >= len) {
+                       len = 2*len+1;
+                       if (len > SIZE_MAX/sizeof(*names))
+                               break;
+                       tmp = realloc(names, len * sizeof(*names));
+                       if (!tmp)
+                               break;
+                       names = tmp;
+               }
+               names[cnt] = malloc(de->d_reclen);
+               if (!names[cnt])
+                       break;
+               memcpy(names[cnt++], de, de->d_reclen);
+       }
+
+       closedir(d);
+
+       if (errno) {
+               if (names)
+                       while (cnt-->0)
+                               free(names[cnt]);
+               free(names);
+               return -1;
+       }
+       errno = old_errno;
+
+       if (cmp)
+               qsort(names, cnt, sizeof *names, (int (*)(const void *, const 
void *))cmp);
+       *res = names;
+       return cnt;
+}
+
 struct dirent *readdir(DIR *dir)
 {
        static __thread struct dirent entry, *result;
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.