Skip to content

Commit

Permalink
Added --readonly flag (see #59)
Browse files Browse the repository at this point in the history
  • Loading branch information
raff authored and prigaux committed Sep 29, 2022
1 parent eab92dc commit 91d92e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions hexedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<n> | --linelength <n>]"
const char * const usage = "usage: %s [-s | --sector] [-m | --maximize] [-l<n> | --linelength <n>] [-r | --readonly]"
#ifdef HAVE_COLORS
" [--color]"
#endif
Expand All @@ -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;
Expand Down

0 comments on commit 91d92e3

Please sign in to comment.