diff --git a/bin/uce_fastcgi.debug.linux.bin b/bin/uce_fastcgi.debug.linux.bin index 41a916e..e218c0f 100755 Binary files a/bin/uce_fastcgi.debug.linux.bin and b/bin/uce_fastcgi.debug.linux.bin differ diff --git a/src/lib/sys.cpp b/src/lib/sys.cpp index 0f2c023..6008954 100644 --- a/src/lib/sys.cpp +++ b/src/lib/sys.cpp @@ -6,7 +6,8 @@ #include #include #include - +#include +#include #include "sys.h" String shell_exec(String cmd) @@ -91,33 +92,48 @@ bool file_exists(String path) String file_get_contents(String file_name) { - try - { - std::ifstream ifs(file_name); - String content( - (std::istreambuf_iterator(ifs) ), - (std::istreambuf_iterator() ) ); - return(content); - } - catch(std::exception e) + /*std::ifstream ifs(file_name); + printf("stream file desc %i\n", ifs.filedesc()); + String content( + (std::istreambuf_iterator(ifs) ), + (std::istreambuf_iterator() ) );*/ + char buf[512]; + String content; + s32 fd = open(file_name.c_str(), O_RDONLY); + if(fd == -1) { + printf("(!) Could not read %s\n", file_name.c_str()); return(""); } + flock(fd, LOCK_SH); + s64 bytes_read = 0; + //s64 size = lseek(fd, 0, SEEK_END); + //lseek(fd, 0, SEEK_SET); + //content.reserve(size+1); + + while((bytes_read = read(fd, buf, 512)) > 0) + { + content.append(buf, bytes_read); + } + + flock(fd, LOCK_UN); + close(fd); + return(content); } bool file_put_contents(String file_name, String content) { - try - { - std::ofstream out(file_name); - out << content; - out.close(); - return(true); - } - catch(std::exception e) + s32 fd = open(file_name.c_str(), O_WRONLY | O_CREAT | O_TRUNC); + if(fd == -1) { + printf("(!) Could not write %s\n", file_name.c_str()); return(false); } + flock(fd, LOCK_EX); + write(fd, content.data(), content.length()); + flock(fd, LOCK_UN); + close(fd); + return(true); } String get_cwd() diff --git a/test/fileio.uce b/test/fileio.uce new file mode 100644 index 0000000..69474bc --- /dev/null +++ b/test/fileio.uce @@ -0,0 +1,22 @@ + + +RENDER() +{ + DTree t; + + <> + +

+ UCE Test: + FileI/O +

+ + File IO: + +
+ + Params +
params) ?>
+ + +} diff --git a/test/index.uce b/test/index.uce index f47d7c5..12001db 100644 --- a/test/index.uce +++ b/test/index.uce @@ -23,6 +23,7 @@ RENDER()
  • JSON
  • Memcached
  • MySQL Connector
  • +
  • File I/O
  • 
    +	<>
    "/> @@ -14,7 +14,7 @@ void show_form()
    - + } diff --git a/todo.txt b/todo.txt index 03d7dbd..b066945 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,7 @@ Library ================================= - sha1 / md5 / meow +- fold StringList into DTree _OR_ make better StringList Bugs @@ -10,19 +11,27 @@ Bugs Framework ================================= -- Locks for file i/o -- Locks for compiler - Check: File Upload - Proxy mode - WebSockets -- Persistent code / Cron / Tick? -- Fork -- Multithreading -- Optionally store compiled units alongside source +- Resident code / Cron / Tick? +- Automated Test Suite + + +Performance +================================= +- Arena Allocator +- Array implementation Nice to Have ================================= - pseudorandom - XML components +- Optionally store compiled units alongside source + + +Finally +================================= +- DO WE DO OUR OWN LANGUAGE OR DO WE KEEP USING C?!?