-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoufs_append.c
More file actions
39 lines (31 loc) · 877 Bytes
/
oufs_append.c
File metadata and controls
39 lines (31 loc) · 877 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <string.h>
#include "oufs_lib.h"
#include "virtual_disk.h"
#define BUF_SIZE 500
int main(int argc, char** argv) {
// Fetch the key environment vars
char cwd[MAX_PATH_LENGTH];
char disk_name[MAX_PATH_LENGTH];
char pipe_name_base[MAX_PATH_LENGTH];
oufs_get_environment(cwd, disk_name, pipe_name_base);
// Open the virtual disk
virtual_disk_attach(disk_name, pipe_name_base);
if(argc == 1) {
// skeleton file here said usage: oufs_create .. I assume that is wrong
fprintf(stderr, "Usage: oufs_append <file name>\n");
}else{
OUFILE *fp = oufs_fopen(cwd, argv[1], "a");
unsigned char buf[BUF_SIZE];
if(fp != NULL) {
int n;
while((n = read(0, buf, BUF_SIZE)) != 0) {
oufs_fwrite(fp, buf, n);
}
oufs_fclose(fp);
}
}
// Clean up
virtual_disk_detach();
return(0);
}