#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#define BUF_SIZE 1024
void test_dir(char *dir)
{
DIR *dirp;
struct dirent *dp;
struct stat statbuf;
char path[BUF_SIZE];
int n;
if ((dirp = opendir(dir)) == NULL) {
printf("open %s failed\r\n", dir);
return;
}
while ((dp = readdir(dirp)) != NULL) {
n = strlen(dir);
if (dir[n-1] == '/') {
if (snprintf(path, BUF_SIZE, "%s%s", dir, dp->d_name) >= BUF_SIZE) {
printf("file path is too long...\r\n");
continue
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#define BUF_SIZE 1024
void test_dir(char *dir)
{
DIR *dirp;
struct dirent *dp;
struct stat statbuf;
char path[BUF_SIZE];
int n;
if ((dirp = opendir(dir)) == NULL) {
printf("open %s failed\r\n", dir);
return;
}
while ((dp = readdir(dirp)) != NULL) {
n = strlen(dir);
if (dir[n-1] == '/') {
if (snprintf(path, BUF_SIZE, "%s%s", dir, dp->d_name) >= BUF_SIZE) {
printf("file path is too long...\r\n");
continue