Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: src/shared/gio/gio_mem_snapshot.c

Issue 12226119: Factor out duplicated GioMemoryFileSnapshotCtor() + NaClAppLoadFile() calls (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/shared/gio/gio.h ('k') | src/trusted/service_runtime/build.scons » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « src/shared/gio/gio.h ('k') | src/trusted/service_runtime/build.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698