summaryrefslogtreecommitdiff
path: root/cd-tool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cd-tool.cpp')
-rw-r--r--cd-tool.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/cd-tool.cpp b/cd-tool.cpp
index 8cd5d6e..4b601ba 100644
--- a/cd-tool.cpp
+++ b/cd-tool.cpp
@@ -24,6 +24,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
+#include <unistd.h>
#include "cdutils.h"
#include "generic.h"
#include "fileutils.h"
@@ -57,7 +58,7 @@ void showhelp(void) {
int main(int argc, char ** argv) {
int type = GUESS, c, size, force = 0, sector;
- FILE * iso_r, * iso_w;
+ int iso_r, iso_w;
char * ppf = 0, * iso_name = 0, * arg1 = 0, * arg2 = 0, * f;
verbosity = M_WARNING;
@@ -89,7 +90,7 @@ int main(int argc, char ** argv) {
iso_name = argv[optind++];
- if (!(iso_r = fopen(iso_name, "r"))) {
+ if ((iso_r = open(iso_name, O_RDONLY)) < 0) {
printm(M_ERROR, "Failed to open %s for reading.\n", iso_name);
exit(-1);
}
@@ -129,7 +130,7 @@ int main(int argc, char ** argv) {
show_dir(iso_r, &dir);
} else if (!strcmp(argv[optind], "extract-file")) {
struct DirEntry dir;
- FILE * file;
+ int file;
optind++;
if ((argc - 2) != optind) {
@@ -139,7 +140,7 @@ int main(int argc, char ** argv) {
}
arg1 = argv[optind++];
arg2 = argv[optind++];
- if (!(file = fopen(arg1, "w"))) {
+ if ((file = open(arg1, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
printm(M_ERROR, "Failed to open file %s for writing.\n", arg1);
exit(-1);
}
@@ -152,7 +153,7 @@ int main(int argc, char ** argv) {
printm(M_STATUS, "Reading path %s to file %s.\n", arg2, arg1);
read_file(iso_r, file, type, dir.Sector, dir.Size);
} else if (!strcmp(argv[optind], "extract")) {
- FILE * file;
+ int file;
optind++;
if ((argc - 3) != optind) {
@@ -163,7 +164,7 @@ int main(int argc, char ** argv) {
arg1 = argv[optind++];
size = atoi(argv[optind++]);
sector = atoi(argv[optind++]);
- if (!(file = fopen(arg1, "w"))) {
+ if ((file = open(arg1, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
printm(M_ERROR, "Failed to open file %s for writing.\n", arg1);
exit(-1);
}
@@ -172,13 +173,13 @@ int main(int argc, char ** argv) {
} else if (!strcmp(argv[optind], "insert-file")) {
struct DirEntry dir, * d;
unsigned char * buffer;
- FILE * file;
+ int file;
int old_type;
- if (!(iso_w = fopen(iso_name, "wa"))) {
+ if ((iso_w = open(iso_name, O_WRONLY)) < 0) {
printm(M_ERROR, "Failed to open %s for writing.\n", iso_name);
exit(-1);
}
- fseek(iso_w, 0, SEEK_SET);
+ lseek(iso_w, 0, SEEK_SET);
if (ppf) {
if (open_ppf(ppf, iso_r, "Created by CD-Tool") < 0) {
@@ -194,7 +195,7 @@ int main(int argc, char ** argv) {
}
arg1 = argv[optind++];
arg2 = argv[optind++];
- if (!(file = fopen(arg1, "r"))) {
+ if ((file = open(arg1, O_RDONLY)) < 0) {
printm(M_ERROR, "Failed to open file %s for reading.\n", arg1);
exit(-1);
}
@@ -234,12 +235,12 @@ int main(int argc, char ** argv) {
write_datas(iso_r, iso_w, buffer, GUESS, dir.Sector, dir.Size);
free(buffer);
} else if (!strcmp(argv[optind], "insert")) {
- FILE * file;
- if (!(iso_w = fopen(iso_name, "wa"))) {
+ int file;
+ if ((iso_w = open(iso_name, O_WRONLY)) < 0) {
printm(M_ERROR, "Failed to open %s for writing.\n", iso_name);
exit(-1);
}
- fseek(iso_w, 0, SEEK_SET);
+ lseek(iso_w, 0, SEEK_SET);
if (ppf) {
if (open_ppf(ppf, iso_r, "Created by CD-Tool") < 0) {
@@ -255,7 +256,7 @@ int main(int argc, char ** argv) {
}
arg1 = argv[optind++];
sector = atoi(argv[optind++]);
- if (!(file = fopen(arg1, "r"))) {
+ if ((file = open(arg1, O_RDONLY)) < 0) {
printm(M_ERROR, "Failed to open file %s for reading.\n", arg1);
exit(-1);
}