L4Re/departure

tests/dstest_host_readdir.cc

158:adeb9552b755
2021-08-03 Paul Boddie Added a test of directory reading in preparation for similar filesystem support.
     1 /*     2  * Test directory reading.     3  *     4  * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>     5  *     6  * This program is free software; you can redistribute it and/or     7  * modify it under the terms of the GNU General Public License as     8  * published by the Free Software Foundation; either version 2 of     9  * the License, or (at your option) any later version.    10  *    11  * This program is distributed in the hope that it will be useful,    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    14  * GNU General Public License for more details.    15  *    16  * You should have received a copy of the GNU General Public License    17  * along with this program; if not, write to the Free Software    18  * Foundation, Inc., 51 Franklin Street, Fifth Floor,    19  * Boston, MA  02110-1301, USA    20  */    21     22 #include <dirent.h>    23 #include <stdio.h>    24     25     26     27 int main(int argc, char *argv[])    28 {    29   if (argc < 2)    30   {    31     printf("Need directory name.\n");    32     return 1;    33   }    34     35   /* Obtain directory name. */    36     37   char *filename = argv[1];    38   DIR *dir = opendir(filename);    39     40   if (dir == NULL)    41   {    42     printf("Could not obtain directory: %s\n", filename);    43     return 1;    44   }    45     46   struct dirent *dirent;    47     48   while ((dirent = readdir(dir)) != NULL)    49     printf("> %s\n", dirent->d_name);    50     51   printf("Directory shown.\n");    52     53   return 0;    54 }    55     56 // vim: tabstop=2 expandtab shiftwidth=2