diff --git a/src/ddhx/common.d b/src/ddhx/common.d index ed119ad..f8909e6 100644 --- a/src/ddhx/common.d +++ b/src/ddhx/common.d @@ -93,7 +93,8 @@ } -//TODO: --process - Memory edit by PID +// TODO: Do not follow symlink +// TODO: --process - Memory edit by PID string[] commonopts(string[] args) { GetoptResult res = void; diff --git a/src/ddhx/document.d b/src/ddhx/document.d index 04803a5..46d8147 100644 --- a/src/ddhx/document.d +++ b/src/ddhx/document.d @@ -7,6 +7,7 @@ import ddhx.os.file; import ddhx.os.error; +import std.file; private enum DocType { @@ -26,12 +27,16 @@ void openFile(string path, bool readOnly) { + if (isDir(path)) + throw new Exception("Is a directory"); int e = file.open(path, readOnly ? OFlags.read : OFlags.readWrite); if (e) throw new Exception(messageFromCode(e)); doctype = DocType.disk; } + // + //void openProcess(int pid, bool readOnly) ubyte[] read(void *buffer, size_t size) diff --git a/src/ddhx/os/error.d b/src/ddhx/os/error.d index 54e10ff..7d5a93b 100644 --- a/src/ddhx/os/error.d +++ b/src/ddhx/os/error.d @@ -13,14 +13,14 @@ else { import core.stdc.string; + import std.string; } -import std.string; - string messageFromCode(int code) { version (Windows) { + // TODO: Get console codepage enum BUFSZ = 1024; __gshared char[BUFSZ] buffer; uint len = FormatMessageA( diff --git a/src/ddhx/os/file.d b/src/ddhx/os/file.d index 99157de..9554fae 100644 --- a/src/ddhx/os/file.d +++ b/src/ddhx/os/file.d @@ -13,6 +13,7 @@ { import core.sys.windows.winnt; import core.sys.windows.winbase; + import std.utf : toUTF16z; private alias OSHANDLE = HANDLE; private alias SEEK_SET = FILE_BEGIN; @@ -29,6 +30,7 @@ import core.sys.posix.fcntl; import core.stdc.errno; import core.stdc.stdio : SEEK_SET, SEEK_CUR, SEEK_END; + import std.string : toStringz; // BLKGETSIZE64 missing from dmd 2.098.1 and ldc 1.24.0 // ldc 1.24 missing core.sys.linux.fs @@ -56,7 +58,12 @@ private enum BLKGETSIZE64 = cast(int)_IOR!(0x12,114,size_t.sizeof); private alias BLOCKSIZE = BLKGETSIZE64; - private extern (C) int ioctl(int,long,...); + version (Android) + alias off_t = int; + else + alias off_t = long; + + private extern (C) int ioctl(int,off_t,...); private alias OSHANDLE = int; } @@ -68,9 +75,6 @@ //TODO: FileType GetType(string) // Pipe, device, etc. -import std.string : toStringz; -import std.utf : toUTF16z; - /// File seek origin. enum Seek { @@ -147,8 +151,8 @@ { LARGE_INTEGER i = void; i.QuadPart = pos; - int r = SetFilePointerEx(handle, i, &i, origin); - return r == FALSE ? GetLastError : 0; + return SetFilePointerEx(handle, i, &i, origin) == FALSE ? + GetLastError() : 0; } else version (OSX) {