Files: use the new open() wrappers

Adds use of everything from the new wrappers(), but the
opendir() one.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Lubomir I. Ivanov 2013-12-19 15:00:51 +02:00 committed by Dirk Hohndel
parent f487953ad3
commit fbff6127ac
3 changed files with 13 additions and 13 deletions

6
file.c
View file

@ -25,7 +25,7 @@ int readfile(const char *filename, struct memblock *mem)
mem->buffer = NULL; mem->buffer = NULL;
mem->size = 0; mem->size = 0;
fd = open(filename, O_RDONLY | O_BINARY, 0); fd = subsurface_open(filename, O_RDONLY | O_BINARY, 0);
if (fd < 0) if (fd < 0)
return fd; return fd;
ret = fstat(fd, &st); ret = fstat(fd, &st);
@ -81,7 +81,7 @@ static int try_to_open_zip(const char *filename, struct memblock *mem, char **er
{ {
int success = 0; int success = 0;
/* Grr. libzip needs to re-open the file, it can't take a buffer */ /* Grr. libzip needs to re-open the file, it can't take a buffer */
struct zip *zip = zip_open(filename, ZIP_CHECKCONS, NULL); struct zip *zip = subsurface_zip_open_readonly(filename, ZIP_CHECKCONS, NULL);
if (zip) { if (zip) {
int index; int index;
@ -93,7 +93,7 @@ static int try_to_open_zip(const char *filename, struct memblock *mem, char **er
zip_fclose(file); zip_fclose(file);
success++; success++;
} }
zip_close(zip); subsurface_zip_close(zip);
} }
return success; return success;
} }

View file

@ -578,7 +578,7 @@ void save_dives_logic(const char *filename, const bool select_only)
struct dive *dive; struct dive *dive;
dive_trip_t *trip; dive_trip_t *trip;
FILE *f = fopen(filename, "w"); FILE *f = subsurface_fopen(filename, "w");
if (!f) if (!f)
return; return;
@ -639,7 +639,7 @@ void export_dives_uddf(const char *filename, const bool selected)
/* Save XML to file and convert it into a memory buffer */ /* Save XML to file and convert it into a memory buffer */
save_dives_logic(filename, selected); save_dives_logic(filename, selected);
f = fopen(filename, "r"); f = subsurface_fopen(filename, "r");
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
streamsize = ftell(f); streamsize = ftell(f);
rewind(f); rewind(f);
@ -677,7 +677,7 @@ void export_dives_uddf(const char *filename, const bool selected)
xmlFreeDoc(doc); xmlFreeDoc(doc);
/* Write the transformed XML to file */ /* Write the transformed XML to file */
f = fopen(filename, "w"); f = subsurface_fopen(filename, "w");
xmlDocFormatDump(f, transformed, 1); xmlDocFormatDump(f, transformed, 1);
xmlFreeDoc(transformed); xmlFreeDoc(transformed);

View file

@ -179,7 +179,7 @@ static bool uemis_init(const char *path)
return FALSE; return FALSE;
/* let's check if this is indeed a Uemis DC */ /* let's check if this is indeed a Uemis DC */
reqtxt_path = build_filename(path,"req.txt"); reqtxt_path = build_filename(path,"req.txt");
reqtxt_file = open(reqtxt_path, O_RDONLY, 0666); reqtxt_file = subsurface_open(reqtxt_path, O_RDONLY, 0666);
if (!reqtxt_file) { if (!reqtxt_file) {
#if UEMIS_DEBUG & 1 #if UEMIS_DEBUG & 1
fprintf(debugfile, ":EE req.txt can't be opened\n"); fprintf(debugfile, ":EE req.txt can't be opened\n");
@ -385,7 +385,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
int ans_file; int ans_file;
int timeout = UEMIS_LONG_TIMEOUT; int timeout = UEMIS_LONG_TIMEOUT;
reqtxt_file = open(reqtxt_path, O_RDWR | O_CREAT, 0666); reqtxt_file = subsurface_open(reqtxt_path, O_RDWR | O_CREAT, 0666);
snprintf(sb, BUFLEN, "n%04d12345678", filenr); snprintf(sb, BUFLEN, "n%04d12345678", filenr);
str_append_with_delim(sb, request); str_append_with_delim(sb, request);
for (i = 0; i < n_param_in; i++) for (i = 0; i < n_param_in; i++)
@ -426,7 +426,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
progress_bar_fraction = filenr / 4000.0; progress_bar_fraction = filenr / 4000.0;
snprintf(fl, 13, "ANS%d.TXT", filenr - 1); snprintf(fl, 13, "ANS%d.TXT", filenr - 1);
ans_path = build_filename(build_filename(path, "ANS"), fl); ans_path = build_filename(build_filename(path, "ANS"), fl);
ans_file = open(ans_path, O_RDONLY, 0666); ans_file = subsurface_open(ans_path, O_RDONLY, 0666);
read(ans_file, tmp, 100); read(ans_file, tmp, 100);
close(ans_file); close(ans_file);
#if UEMIS_DEBUG & 8 #if UEMIS_DEBUG & 8
@ -455,7 +455,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
more_files = FALSE; more_files = FALSE;
assembling_mbuf = FALSE; assembling_mbuf = FALSE;
} }
reqtxt_file = open(reqtxt_path, O_RDWR | O_CREAT, 0666); reqtxt_file = subsurface_open(reqtxt_path, O_RDWR | O_CREAT, 0666);
trigger_response(reqtxt_file, "n", filenr, file_length); trigger_response(reqtxt_file, "n", filenr, file_length);
} }
} else { } else {
@ -465,7 +465,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
assembling_mbuf = FALSE; assembling_mbuf = FALSE;
searching = FALSE; searching = FALSE;
} }
reqtxt_file = open(reqtxt_path, O_RDWR | O_CREAT, 0666); reqtxt_file = subsurface_open(reqtxt_path, O_RDWR | O_CREAT, 0666);
trigger_response(reqtxt_file, "r", filenr, file_length); trigger_response(reqtxt_file, "r", filenr, file_length);
uemis_increased_timeout(&timeout); uemis_increased_timeout(&timeout);
} }
@ -473,7 +473,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
int size; int size;
snprintf(fl, 13, "ANS%d.TXT", assembling_mbuf ? filenr - 2 : filenr - 1); snprintf(fl, 13, "ANS%d.TXT", assembling_mbuf ? filenr - 2 : filenr - 1);
ans_path = build_filename(build_filename(path, "ANS"), fl); ans_path = build_filename(build_filename(path, "ANS"), fl);
ans_file = open(ans_path, O_RDONLY, 0666); ans_file = subsurface_open(ans_path, O_RDONLY, 0666);
size = bytes_available(ans_file); size = bytes_available(ans_file);
if (size > 3) { if (size > 3) {
char *buf = malloc(size - 2); char *buf = malloc(size - 2);
@ -497,7 +497,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
if (!ismulti) { if (!ismulti) {
snprintf(fl, 13, "ANS%d.TXT", filenr - 1); snprintf(fl, 13, "ANS%d.TXT", filenr - 1);
ans_path = build_filename(build_filename(path, "ANS"), fl); ans_path = build_filename(build_filename(path, "ANS"), fl);
ans_file = open(ans_path, O_RDONLY, 0666); ans_file = subsurface_open(ans_path, O_RDONLY, 0666);
size = bytes_available(ans_file); size = bytes_available(ans_file);
if (size > 3) { if (size > 3) {
buf = malloc(size - 2); buf = malloc(size - 2);