Loading [MathJax]/extensions/tex2jax.js
CS350 COS
COS
All Data Structures Files Functions Variables Typedefs Macros
dir.c File Reference
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#include <syscall.h>
Include dependency graph for dir.c:

Go to the source code of this file.

Functions

DIRopendir (const char *path)
 
struct direntreaddir (DIR *d)
 
void rewinddir (DIR *d)
 
void seekdir (DIR *d, long offset)
 
long telldir (DIR *d)
 
int closedir (DIR *d)
 

Function Documentation

◆ closedir()

int closedir ( DIR d)

Definition at line 54 of file dir.c.

55{
56 OSClose(d->fd);
57 free(d);
58
59 return 0;
60}
int fd
Definition: dirent.h:8
int OSClose(uint64_t fd)
Definition: syscall.c:83
void free(void *buf)
Definition: malloc.c:169
Here is the call graph for this function:

◆ opendir()

DIR * opendir ( const char *  path)

Definition at line 11 of file dir.c.

12{
13 DIR *d = (DIR *)malloc(sizeof(DIR));
14
15 d->fd = OSOpen(path, 0);
16 if (d->fd < 0) {
17 free(d);
18 return NULL;
19 }
20
21 return d;
22}
Definition: dirent.h:7
uint64_t OSOpen(const char *path, uint64_t flags)
Definition: syscall.c:77
#define NULL
Definition: stddef.h:6
void * malloc(size_t sz)
Definition: malloc.c:160
Here is the call graph for this function:

◆ readdir()

struct dirent * readdir ( DIR d)

Definition at line 25 of file dir.c.

26{
27 int status = OSReadDir(d->fd, (char *)&d->de, sizeof(struct dirent), &d->offset);
28 if (status == 0) {
29 return NULL;
30 }
31
32 return &d->de;
33}
uint64_t offset
Definition: dirent.h:9
struct dirent de
Definition: dirent.h:10
int OSReadDir(uint64_t fd, char *buf, size_t length, uint64_t *offset)
Definition: syscall.c:95
Definition: dirent.h:9
Here is the call graph for this function:

◆ rewinddir()

void rewinddir ( DIR d)

Definition at line 36 of file dir.c.

37{
38 d->offset = 0;
39}

◆ seekdir()

void seekdir ( DIR d,
long  offset 
)

Definition at line 42 of file dir.c.

43{
44 d->offset = offset;
45}

◆ telldir()

long telldir ( DIR d)

Definition at line 48 of file dir.c.

49{
50 return d->offset;
51}