summaryrefslogtreecommitdiff
path: root/src/MSL_C.PPCEABI.bare.H/buffer_io.c
blob: e760ba872f1ddb73af360b910e96b9f6c22d4d01 (plain)
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
#include "buffer_io.h"

void __convert_from_newlines(unsigned char* buf, size_t* n) {
}

void __convert_to_newlines(unsigned char* buf, size_t* n) {
}

void __prep_buffer(FILE* file) {
  file->buffer_ptr = file->buffer;
  file->buffer_len = file->buffer_size;
  file->buffer_len -= file->position & file->buffer_alignment;
  file->buffer_pos = file->position;
}

int __flush_buffer(FILE* file, size_t* bytes_flushed) {
  size_t buffer_len;
  int ioresult;

  buffer_len = file->buffer_ptr - file->buffer;

  if (buffer_len) {
    file->buffer_len = buffer_len;

    if (!file->mode.binary_io)
      __convert_from_newlines(file->buffer, (size_t*)&file->buffer_len);

    ioresult = (*file->write_proc)(file->handle, file->buffer, (size_t*)&file->buffer_len,
                                   file->idle_proc);

    if (bytes_flushed)
      *bytes_flushed = file->buffer_len;

    if (ioresult)
      return (ioresult);

    file->position += file->buffer_len;
  }

  __prep_buffer(file);

  return 0;
}