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

Side by Side Diff: client/deps/glbench/src/utils.cc

Issue 897003: set resource loading path relative to the executable (Closed)
Patch Set: Created 10 years, 9 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
« no previous file with comments | « client/deps/glbench/src/utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <fcntl.h> 5 #include <fcntl.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h> 7 #include <string.h>
8 #include <sys/mman.h> 8 #include <sys/mman.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
11 #include "utils.h" 11 #include "utils.h"
12 12
13 #include "base/file_path.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "main.h" 15 #include "main.h"
15 16
16 void *MmapFile(const char *name, size_t *length) { 17 FilePath *g_base_path = new FilePath();
17 int fd = open(name, O_RDONLY); 18
19 // Sets the base path for MmapFile to `dirname($argv0)`/$relative.
20 void SetBasePathFromArgv0(const char* argv0, const char* relative) {
Alexey Marinichev 2010/03/12 19:22:59 Everywhere else, including line 17, pointers are d
21 if (g_base_path) {
22 delete g_base_path;
23 }
24 FilePath argv0_path = FilePath(argv0).DirName();
25 FilePath base_path = relative ? argv0_path.Append(relative) : argv0_path;
26 g_base_path = new FilePath(base_path);
27 }
28
29 void *MmapFile(const char* name, size_t* length) {
Alexey Marinichev 2010/03/12 19:22:59 Same thing here.
30 FilePath filename = g_base_path->Append(name);
31 int fd = open(filename.value().c_str(), O_RDONLY);
18 if (fd == -1) 32 if (fd == -1)
19 return NULL; 33 return NULL;
20 34
21 struct stat sb; 35 struct stat sb;
22 CHECK(fstat(fd, &sb) != -1); 36 CHECK(fstat(fd, &sb) != -1);
23 37
24 char *mmap_ptr = static_cast<char *>( 38 char *mmap_ptr = static_cast<char *>(
25 mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0)); 39 mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0));
26 40
27 close(fd); 41 close(fd);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 glAttachShader(program, fragment_shader); 82 glAttachShader(program, fragment_shader);
69 glLinkProgram(program); 83 glLinkProgram(program);
70 print_info_log(program); 84 print_info_log(program);
71 glUseProgram(program); 85 glUseProgram(program);
72 86
73 glDeleteShader(vertex_shader); 87 glDeleteShader(vertex_shader);
74 glDeleteShader(fragment_shader); 88 glDeleteShader(fragment_shader);
75 89
76 return program; 90 return program;
77 } 91 }
OLDNEW
« no previous file with comments | « client/deps/glbench/src/utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698