summaryrefslogtreecommitdiff
path: root/easytool
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-08-17 10:00:27 +0800
committerHarald Welte <laforge@gnumonks.org>2010-08-17 10:00:27 +0800
commit6ed439ecb8c09465ad4bdce53aaca59e935cbbd9 (patch)
tree0fc28de0c8cbe50926ef5bf35d32275697d7f25b /easytool
parentd3c282f9179de48d66b850444ea688bfd02c40d7 (diff)
easytool: open file read/write in case we want to modify content
Diffstat (limited to 'easytool')
-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