summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--easytool/easytool.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/easytool/easytool.c b/easytool/easytool.c
index 2e7ada3..c504003 100644
--- a/easytool/easytool.c
+++ b/easytool/easytool.c
@@ -140,6 +140,7 @@ int main(int argc, char **argv)
int delta = 0;
int option_index = 0;
int rc;
+ int prot, flags = O_RDONLY;
global.mode = MODE_DUMP;
@@ -166,10 +167,12 @@ int main(int argc, char **argv)
break;
case 'r':
global.mode = MODE_RECHARGE;
+ flags = O_RDWR;
delta = atoi(optarg);
break;
case 'p':
global.mode = MODE_PURCHASE;
+ flags = O_RDWR;
delta = atoi(optarg);
break;
case 'h':
@@ -186,7 +189,7 @@ int main(int argc, char **argv)
exit(2);
}
- global.fd = open(argv[optind], O_RDONLY);
+ global.fd = open(argv[optind], flags);
if (global.fd < 0) {
perror("Error opening the MFD file");
exit(1);
@@ -196,8 +199,12 @@ int main(int argc, char **argv)
exit(1);
}
global.size = st.st_size;
- global.mft = mmap(NULL, global.size, PROT_READ, MAP_SHARED,
- global.fd, 0);
+
+ prot = PROT_READ;
+ if (flags == O_RDWR)
+ prot |= PROT_WRITE;
+
+ global.mft = mmap(NULL, global.size, prot, MAP_SHARED, global.fd, 0);
if (!global.mft) {
perror("Error mmap()ing the MFD file");
exit(1);
personal git repositories of Harald Welte. Your mileage may vary