| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 /* | 7 /* |
| 8 * NaCl Generic I/O interface implementation: in-memory snapshot of a file. | 8 * NaCl Generic I/O interface implementation: in-memory snapshot of a file. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "native_client/src/include/portability.h" | 11 #include "native_client/src/include/portability.h" |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 #include <sys/stat.h> | 13 #include <sys/stat.h> |
| 14 #include <stdlib.h> | 14 #include <stdlib.h> |
| 15 | 15 |
| 16 #include "native_client/src/shared/gio/gio.h" | 16 #include "native_client/src/shared/gio/gio.h" |
| 17 | 17 |
| 18 struct GioVtbl const kGioMemoryFileSnapshotVtbl = { | 18 struct GioVtbl const kGioMemoryFileSnapshotVtbl = { |
| 19 GioMemoryFileSnapshotDtor, | 19 GioMemoryFileSnapshotDtor, |
| 20 GioMemoryFileRead, | 20 GioMemoryFileRead, |
| 21 GioMemoryFileWrite, | 21 GioMemoryFileWrite, |
| 22 GioMemoryFileSeek, | 22 GioMemoryFileSeek, |
| 23 GioMemoryFileFlush, | 23 GioMemoryFileFlush, |
| 24 GioMemoryFileClose, | 24 GioMemoryFileClose, |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 | 27 |
| 28 int GioMemoryFileSnapshotCtor(struct GioMemoryFileSnapshot *self, | 28 int GioMemoryFileSnapshotCtor(struct GioMemoryFileSnapshot *self, |
| 29 char *fn) { | 29 const char *filename) { |
| 30 FILE *iop; | 30 FILE *iop; |
| 31 struct stat stbuf; | 31 struct stat stbuf; |
| 32 char *buffer; | 32 char *buffer; |
| 33 | 33 |
| 34 ((struct Gio *) self)->vtbl = (struct GioVtbl *) NULL; | 34 ((struct Gio *) self)->vtbl = (struct GioVtbl *) NULL; |
| 35 if (0 == (iop = fopen(fn, "rb"))) { | 35 if (0 == (iop = fopen(filename, "rb"))) { |
| 36 return 0; | 36 return 0; |
| 37 } | 37 } |
| 38 if (fstat(fileno(iop), &stbuf) == -1) { | 38 if (fstat(fileno(iop), &stbuf) == -1) { |
| 39 abort0: | 39 abort0: |
| 40 fclose(iop); | 40 fclose(iop); |
| 41 return 0; | 41 return 0; |
| 42 } | 42 } |
| 43 if (0 == (buffer = malloc(stbuf.st_size))) { | 43 if (0 == (buffer = malloc(stbuf.st_size))) { |
| 44 goto abort0; | 44 goto abort0; |
| 45 } | 45 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 57 return 1; | 57 return 1; |
| 58 } | 58 } |
| 59 | 59 |
| 60 | 60 |
| 61 void GioMemoryFileSnapshotDtor(struct Gio *vself) { | 61 void GioMemoryFileSnapshotDtor(struct Gio *vself) { |
| 62 struct GioMemoryFileSnapshot *self = (struct GioMemoryFileSnapshot *) | 62 struct GioMemoryFileSnapshot *self = (struct GioMemoryFileSnapshot *) |
| 63 vself; | 63 vself; |
| 64 free(self->base.buffer); | 64 free(self->base.buffer); |
| 65 GioMemoryFileDtor(vself); | 65 GioMemoryFileDtor(vself); |
| 66 } | 66 } |
| OLD | NEW |