Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
diff --git a/util/system.cpp b/util/system.cpp
index 2dc01667..628cbc6c 100644
--- a/util/system.cpp
+++ b/util/system.cpp
@@ -1,194 +1,209 @@
#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
/* devkitpro doesn't have an implementation of access() yet. if it gets one this function
* can be removed.
*/
#if defined(WII) || defined(PS3)
int access(const char * path, int mode){
struct stat information;
int ok = stat(path, &information);
// printf("stat of '%s' is %d\n", path.c_str(), ok);
if (ok == 0){
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 -1;
}
}
#endif
#ifdef NACL
/* NOTE FIXME Missing I/O in Native Client */
+extern "C" {
+
int pipe (int filedes[2]){
return 0;
}
int mkdir (const char *filename, mode_t mode){
return 0;
}
int access (const char *filename, int how){
return 0;
}
char * getcwd (char *buffer, size_t size){
return NULL;
}
int lstat (const char *path, struct stat *buf){
return 0;
}
int rmdir (const char *filename){
return 0;
}
int chdir (const char *filename){
return 0;
}
int setuid (uid_t newuid){
return 0;
}
int seteuid (uid_t uid){
return 0;
}
uid_t geteuid (void){
return NULL;
}
int setgid (gid_t gid){
return 0;
}
gid_t getgid (void){
return NULL;
}
int setegid (gid_t gid){
return 0;
}
gid_t getegid (void){
return NULL;
}
char * getlogin (void){
return NULL;
}
+uid_t getuid(void){
+ return NULL;
+}
+
struct passwd * getpwuid (uid_t uid){
return NULL;
}
struct passwd * getpwnam (const char *name){
return NULL;
}
+struct group * getgrnam(const char *name){
+ return NULL;
+}
+
+struct group * getgrgid(gid_t gid){
+ return NULL;
+}
+
int link (const char *oldname, const char *newname){
return 0;
}
int unlink (const char *filename){
return 0;
}
int kill(pid_t pid, int sig){
return 0;
}
+}
#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

Mime Type
text/x-diff
Expires
Thu, Jun 11, 10:40 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68481
Default Alt Text
(4 KB)

Event Timeline