Path: blob/main/test/dirent/test_readdir_empty.c
4133 views
/*1* Copyright 2014 The Emscripten Authors. All rights reserved.2* Emscripten is available under two separate licenses, the MIT license and the3* University of Illinois/NCSA Open Source License. Both these licenses can be4* found in the LICENSE file.5*/67#include <stdio.h>8#include <dirent.h>9#include <sys/stat.h>10#include <string.h>11#include <errno.h>121314int main(int argc, char** argv) {15if (mkdir("/tmp", S_IRWXG) != 0 && errno != EEXIST) {16printf("Unable to create dir '/tmp'\n");17return 1;18}1920if (mkdir("/tmp/foo", S_IRWXG) != 0 && errno != EEXIST) {21printf("Unable to create dir '/tmp/foo'\n");22return 1;23}2425if (mkdir("/tmp/foo/", S_IRWXG) != 0 && errno != EEXIST) {26printf("Unable to create dir '/tmp/foo/'\n");27return 1;28}2930DIR *dir = opendir("/tmp");3132if (!dir) {33printf("Unable to open dir '/tmp'\n");34return 2;35}3637struct dirent *dirent;3839while ((dirent = readdir(dir)) != 0) {40printf("Found '%s'\n", dirent->d_name);4142if (strlen(dirent->d_name) == 0) {43printf("Found empty path!\n");44return 3;45}46}4748closedir(dir);4950printf("success\n");5152return 0;53}54555657