From 6ed439ecb8c09465ad4bdce53aaca59e935cbbd9 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 17 Aug 2010 10:00:27 +0800 Subject: easytool: open file read/write in case we want to modify content --- easytool/easytool.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'easytool') 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); -- cgit v1.2.3