Skip to content

Commit 4c2d88c

Browse files
committed
Make code match tutorial.
1 parent c07388e commit 4c2d88c

File tree

1 file changed

+0
-36
lines changed

1 file changed

+0
-36
lines changed

db.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,8 @@
1-
#include <fcntl.h>
21
#include <stdbool.h>
32
#include <stdio.h>
43
#include <stdlib.h>
54
#include <string.h>
65

7-
struct Connection_t {
8-
int file_descriptor;
9-
};
10-
typedef struct Connection_t Connection;
11-
12-
Connection* open_connection(char* filename) {
13-
int fd = open(filename,
14-
O_RDWR | // Read/Write mode
15-
O_CREAT, // Create file if it does not exist
16-
S_IWUSR | // Create file with user write permission
17-
S_IRUSR // Create file with user read permission
18-
);
19-
20-
if (fd == -1) {
21-
printf("Unable to open file '%s'\n", filename);
22-
exit(EXIT_FAILURE);
23-
}
24-
25-
Connection* connection = malloc(sizeof(Connection));
26-
connection->file_descriptor = fd;
27-
28-
return connection;
29-
}
30-
31-
char* get_db_filename(int argc, char* argv[]) {
32-
if (argc < 2) {
33-
printf("Must supply a filename for the database.\n");
34-
exit(EXIT_FAILURE);
35-
}
36-
return argv[1];
37-
}
38-
396
struct InputBuffer_t {
407
char* buffer;
418
size_t buffer_length;
@@ -69,9 +36,6 @@ void read_input(InputBuffer* input_buffer) {
6936
}
7037

7138
int main(int argc, char* argv[]) {
72-
char* db_filename = get_db_filename(argc, argv);
73-
Connection* connection = open_connection(db_filename);
74-
7539
InputBuffer* input_buffer = new_input_buffer();
7640
while (true) {
7741
print_prompt();

0 commit comments

Comments
 (0)