CS350 COS
COS
Loading...
Searching...
No Matches
ls.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <syscall.h>
#include <sys/syscall.h>
#include <sys/dirent.h>
Include dependency graph for ls.c:

Go to the source code of this file.

Functions

int main (int argc, const char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Definition at line 13 of file ls.c.

14{
15 int fd;
16 int status;
17 uintptr_t offset = 0;
18
19 if (argc != 2) {
20 fputs("Requires an argument\n", stdout);
21 return 1;
22 }
23
24 fd = OSOpen(argv[1], 0);
25 if (fd < 0) {
26 fputs("Cannot open directory\n", stdout);
27 return 1;
28 }
29
30 while (1) {
31 struct dirent de;
32
33 status = OSReadDir(fd, (char *)&de, sizeof(de), &offset);
34 if (status == 0) {
35 break;
36 }
37 if (status < 0) {
38 printf("OSReadDir Error: %x\n", -status);
39 return 1;
40 }
41
42 printf("%s\n", de.d_name);
43 }
44
45 return 0;
46}
uint64_t OSOpen(const char *path, uint64_t flags)
Definition: syscall.c:77
int OSReadDir(uint64_t fd, char *buf, size_t length, uint64_t *offset)
Definition: syscall.c:95
int printf(const char *fmt,...)
Definition: printf.c:212
int fputs(const char *str, FILE *fh)
Definition: file.c:132
FILE * stdout
Definition: file.c:16
Definition: dirent.h:9
uint64_t uintptr_t
Definition: types.h:16
Here is the call graph for this function: