Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126359
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/util/system.cpp b/util/system.cpp
index e3682826..aadafea9 100644
--- a/util/system.cpp
+++ b/util/system.cpp
@@ -1,113 +1,108 @@
#include <string>
#include "system.h"
#include <stdint.h>
#include <stdio.h>
#include <fstream>
#ifndef WINDOWS
#include <unistd.h>
#include <sys/stat.h>
#include <sys/time.h>
#endif
#ifndef WINDOWS
-static bool isReadable(const std::string & path){
-#ifndef WII
- if (access(path.c_str(), R_OK) == 0){
- return true;
- } else {
- return false;
- }
-#else
-
- /*
- std::ifstream file(path.c_str());
- return file.good();
- */
- /*
- FILE * test = fopen(path.c_str(), "rb");
- printf("open of '%s' was %p\n", path.c_str(), test);
- if (test != NULL){
- fclose(test);
- return true;
- }
- return false;
- */
- /* stat doesn't seem to work on the wii */
+/* devkitpro doesn't have an implementation of access() yet. if it gets one this function
+ * can be removed.
+ */
+#ifdef WII
+int access(const char * path, int mode){
struct stat information;
- int ok = stat(path.c_str(), &information);
+ int ok = stat(path, &information);
// printf("stat of '%s' is %d\n", path.c_str(), ok);
if (ok == 0){
- return ((information.st_mode & S_IRUSR) == S_IRUSR) ||
- ((information.st_mode & S_IRGRP) == S_IRGRP) ||
- ((information.st_mode & S_IROTH) == S_IROTH);
+ if (mode == R_OK){
+ if (((information.st_mode & S_IRUSR) == S_IRUSR) ||
+ ((information.st_mode & S_IRGRP) == S_IRGRP) ||
+ ((information.st_mode & S_IROTH) == S_IROTH)){
+ return 0;
+ } else {
+ /* handle other modes if they become useful to us */
+ return -1;
+ }
+ } else {
+ return -1;
+ }
} else {
// perror("stat");
- return false;
+ return -1;
}
+}
#endif
+
+static bool isReadable(const std::string & path){
+ return access(path.c_str(), R_OK) == 0;
}
bool System::isDirectory(const std::string & path){
struct stat info;
if (stat(path.c_str(), &info) == 0){
if (S_ISDIR(info.st_mode) == 1){
return true;
} else {
return false;
}
}
return false;
}
bool System::readableFile(const std::string & path){
return isReadable(path) && ! isDirectory(path);
}
bool System::readable(const std::string & path){
return isReadable(path);
}
void System::makeDirectory(const std::string & path){
mkdir(path.c_str(), 0777);
}
uint64_t System::currentMicroseconds(){
struct timeval hold;
gettimeofday(&hold, NULL);
return hold.tv_sec * 1000 * 1000 + hold.tv_usec;
}
uint64_t System::getModificationTime(const std::string & path){
struct stat data;
if (stat(path.c_str(), &data) == 0){
return data.st_mtime;
}
return 0;
}
static void * start_memory = 0;
unsigned long System::memoryUsage(){
void * here = sbrk(0);
/* hopefully the heap is growing up */
return (char*) here - (char*) start_memory;
}
void System::startMemoryUsage(){
start_memory = sbrk(0);
}
#endif
void System::makeAllDirectory(const std::string & path){
unsigned int last = path.find('/');
while (last != std::string::npos){
std::string sofar = path.substr(0, last);
if (sofar != ""){
makeDirectory(sofar);
}
last = path.find('/', last + 1);
}
makeDirectory(path);
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 11:23 AM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68728
Default Alt Text
(3 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline