Home | History | Annotate | Download | only in lib
      1 /*
      2  * Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
      3  *
      4  * This program is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU General Public License as
      6  * published by the Free Software Foundation; either version 2 of
      7  * the License, or (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it would be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  * GNU General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU General Public License
     15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
     16  *
     17  * Author: Alexey Kodanev <alexey.kodanev (at) oracle.com>
     18  *
     19  */
     20 
     21 #include <string.h>
     22 #include <sys/types.h>
     23 #include <dirent.h>
     24 
     25 #include "test.h"
     26 #include "safe_macros.h"
     27 
     28 int tst_dir_is_empty_(void (cleanup_fn)(void), const char *name, int verbose)
     29 {
     30 	struct dirent *entry;
     31 	DIR *dir = SAFE_OPENDIR(cleanup_fn, name);
     32 	int ret = 1;
     33 
     34 	while ((entry = SAFE_READDIR(cleanup_fn, dir)) != NULL) {
     35 		const char *file = entry->d_name;
     36 
     37 		if (!strcmp(file, "..") || !strcmp(file, "."))
     38 			continue;
     39 
     40 		if (verbose)
     41 			tst_resm(TINFO, "found a file: %s", file);
     42 		ret = 0;
     43 		break;
     44 	}
     45 
     46 	SAFE_CLOSEDIR(cleanup_fn, dir);
     47 
     48 	return ret;
     49 }
     50