aboutsummaryrefslogtreecommitdiff
path: root/ls.c
blob: 4b48c9c9053306fc2504b3a6d578c291dc65dd1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>

int main(int argc, char **argv)
{
    char *dirname;
    DIR *dir;
    struct dirent *dirent;

    if (argc > 1) {
        dirname = argv[1];
    } else {
        dirname = ".";
    }

    dir = opendir(dirname);

    while ((dirent = readdir(dir)) != NULL) {
        fprintf(stdout, "%s\n", dirent->d_name);
    }

    exit(EXIT_SUCCESS);
}