-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmystdio.h
113 lines (102 loc) · 3.06 KB
/
mystdio.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef MYFILE_HPP
#define MYFILE_HPP
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <vector>
#include <string>
#include <string.h>
#include "myfs.hpp"
// https://www.equestionanswers.com/c/c-printf-scanf-working-principle.php
using namespace std;
// enum Permission
// {
// PERMISSION_READ, // 0
// PERMISSION_WRITE, // 1
// PERMISSION_EXECUTE, // 2
// PERMISSION_UNSET, // 3
// PERMISSION_READ_WRITE // 4
// };
class simple_file
{
public:
enum Permission permition;
int file_num;
int current_offset;
int used_size;
int size;
int first_block;
char name[8];
enum FileType type;
simple_file() = default;
simple_file(int file_num, int current_offset, int used_size, int size, int first_block, char name[8], enum FileType type, enum Permission permition)
{
this->file_num = file_num;
this->current_offset = current_offset;
this->used_size = used_size;
this->size = size;
this->first_block = first_block;
strcpy(this->name, name);
this->type = type;
this->permition = permition;
}
};
extern vector<string> myFILEs_open;
extern vector<simple_file *> myFILEs;
class myFILE
{
// constructor
public:
simple_file *file;
char file_buffer[5120];
myFILE();
~myFILE();
myFILE(simple_file *file)
{
myFILEs.push_back(file);
// myFILEs.push_back(simple_file(file_num, curr_offset, used_size, size, first_block, name, type, permition));
myFILEs_open.push_back(file->name);
}
};
myFILE *myfopen(const char *pathname, const char *mode); // finished
int myfclose(myFILE *stream); // finished
size_t myfread(void *ptr, size_t size, size_t nmemb, myFILE *stream); // finished
size_t myfwrite(const void *ptr, size_t size, size_t nmemb, myFILE *stream); // finished
int myfseek(myFILE *stream, long offset, int whence); // finished
int myfscanf(myFILE *stream, const char *format, ...); // finished
int myfprintf(myFILE *stream, const char *format, ...); // finished
// myprintf();
char *_strrev(char *str);
char *_itoa(int i, char *strout, int base);
int myprint(char *str, ...);
// myprintf()
// myscanf();
int myscanf(char *str, ...);
// myscanf();
// int main(int argc, char *argv[])
// {
// char c;
// int i;
// int h;
// int o;
// char str_buff[20];
// int ret = 0;
// printf("Enter char int hex oct string\n");
// ret = scan("%c %d %x %o %s", &c, &i, &h, &o, str_buff);
// printf("C = %c, I = %d, H = %d, O = %d, S = %s returns %d", c, i, h, o, str_buff, ret);
// return 0;
// }
// int main(int argc, char *argv[])
// {
// int ret;
// std::string str = "hello world";
// std::string param = "%c %d %o %x %s\n";
// ret = myprint((char *) param.c_str(), 'A', 10, 100, 1000, str.c_str());
// printf("printf returns %d bytes\n", ret);
// return 0;
// }
#endif