From 91d92e342a042f1c1480f68cb321010c7ecba91e Mon Sep 17 00:00:00 2001 From: Raffaele Sena Date: Wed, 28 Sep 2022 17:45:44 -0700 Subject: [PATCH] Added --readonly flag (see https://github.com/pixel/hexedit/issues/59) --- file.c | 2 +- hexedit.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/file.c b/file.c index 000a962..77901cb 100644 --- a/file.c +++ b/file.c @@ -26,7 +26,7 @@ void openFile(void) } /* edited should be cleaned here (assert(edited == NULL)) */ - if ((fd = open(fileName, O_RDWR)) == -1) { + if (isReadOnly || (fd = open(fileName, O_RDWR)) == -1) { isReadOnly = TRUE; if ((fd = open(fileName, O_RDONLY)) == -1) { if (page) exitCurses(); diff --git a/hexedit.c b/hexedit.c index 6ab2ed7..c00515d 100644 --- a/hexedit.c +++ b/hexedit.c @@ -25,7 +25,7 @@ INT mark_min, mark_max, mark_set; INT base, oldbase; int normalSpaces, cursor, cursorOffset, hexOrAscii; int cursor, blocSize, lineLength, colsUsed, page; -int isReadOnly, fd, nbBytes, oldcursor, oldattr, oldcursorOffset; +int fd, nbBytes, oldcursor, oldattr, oldcursorOffset; int sizeCopyBuffer, *bufferAttr; char *progName, *fileName, *baseName; unsigned char *buffer, *copyBuffer; @@ -40,8 +40,9 @@ const modeParams modes[LAST] = { }; modeType mode = maximized; int colored = FALSE; +int isReadOnly = FALSE; -const char * const usage = "usage: %s [-s | --sector] [-m | --maximize] [-l | --linelength ]" +const char * const usage = "usage: %s [-s | --sector] [-m | --maximize] [-l | --linelength ] [-r | --readonly]" #ifdef HAVE_COLORS " [--color]" #endif @@ -60,6 +61,8 @@ int main(int argc, char **argv) { if (streq(*argv, "-s") || streq(*argv, "--sector")) mode = bySector; + else if (streq(*argv, "-r") || streq(*argv, "--readonly")) + isReadOnly = TRUE; else if (streq(*argv, "-m") || streq(*argv, "--maximize")) { mode = maximized; lineLength = 0;