Skip to content

Commit

Permalink
impl some file operations
Browse files Browse the repository at this point in the history
  • Loading branch information
omdxp committed Sep 9, 2024
1 parent e765795 commit 84c5a65
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
22 changes: 22 additions & 0 deletions rc_includes/stdio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef STDIO_H
#define STDIO_H
#include <stdlib.h>

typedef struct _iobuf {
char *_ptr;
int _cnt;
char *_base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char *_tmpfname;
} FILE;

FILE *fopen(const char *filename, const char *mode);
int fclose(FILE *stream);
size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream);
size_t fread(void *ptr, size_t size, size_t count, FILE *stream);
int printf(const char *format, ...);

#endif // STDIO_H
6 changes: 6 additions & 0 deletions rc_includes/stdlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef STDLIB_H
#define STDLIB_H

typedef int size_t;

#endif // STDLIB_H
18 changes: 5 additions & 13 deletions test.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
#include <stdarg.h>
#include <stdio.h>

int sum(int num, ...) {
int res = 0;
va_list args;
va_start(args, num);
int i;
for (i = 0; i < num; i++) {
res += va_arg(args, int);
}
va_end(args);
return res;
int main() {
FILE *f = fopen("test.txt", "w");
fwrite("Hello, World!\n", 1, 14, f);
fclose(f);
}

int main() { return sum(10, 20, 30); }

0 comments on commit 84c5a65

Please sign in to comment.