Added fwrite

This commit is contained in:
pjht 2019-04-09 09:16:37 -05:00
parent 680defd654
commit f4b82ec850
2 changed files with 18 additions and 0 deletions

View File

@ -219,6 +219,23 @@ int puts(const char* s) {
return fputs(s,stdout);
}
size_t fwrite(void* buffer_ptr,size_t size,size_t count,FILE* stream) {
if (!stream->wr) {
errno=EBADF;
stream->error=1;
return 0;
}
char* buffer=(char*)buffer_ptr;
size_t bytes=size*count;
for (size_t i=0;i<bytes;i++) {
int c=fputs(stream,buffer[i]);
if (c==EOF) {
return (size_t)(i/size);
}
}
return count;
}
int vfprintf(FILE* stream,const char* format,va_list arg) {
int c;
for(;*format!='\0';format++) {

View File

@ -34,6 +34,7 @@ size_t fread(void* buffer,size_t size,size_t count,FILE* stream);
int fputc(int c,FILE* stream);
int putc(int c);
int fputs(const char* s,FILE* stream);
size_t fwrite(void* buffer_ptr,size_t size,size_t count,FILE* stream);
int puts(const char* s);
int fprintf(FILE* stream,const char* format,...);
int vfprintf(FILE* stream,const char* format,va_list arg);