summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schroeder <mls@suse.de>2011-03-08 10:20:54 +0100
committerMichael Schroeder <mls@suse.de>2011-03-08 10:20:54 +0100
commit45af6d35a0f28d77731014ddf27bc0282dea1215 (patch)
tree459a5c01111df19a0a3355dbc4dab66fa10b80d6
parentf8fbf5ca792ea7ce16e67958d700caaec5863910 (diff)
downloadlibsolv-45af6d35a0f28d77731014ddf27bc0282dea1215.tar.gz
libsolv-45af6d35a0f28d77731014ddf27bc0282dea1215.tar.bz2
libsolv-45af6d35a0f28d77731014ddf27bc0282dea1215.zip
- add mode argument to sat_xfopen* functions
-rw-r--r--examples/solv.c2
-rw-r--r--ext/sat_xfopen.c23
-rw-r--r--ext/sat_xfopen.h4
-rw-r--r--tools/installcheck.c2
-rw-r--r--tools/patchcheck.c2
-rw-r--r--tools/rpmmd2solv.c8
-rw-r--r--tools/susetags2solv.c8
7 files changed, 27 insertions, 22 deletions
diff --git a/examples/solv.c b/examples/solv.c
index f33b8c8..f9a0f7a 100644
--- a/examples/solv.c
+++ b/examples/solv.c
@@ -850,7 +850,7 @@ curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsign
return 0;
}
if (uncompress)
- return sat_xfopen_fd(".gz", fd);
+ return sat_xfopen_fd(".gz", fd, 0);
fcntl(fd, F_SETFD, FD_CLOEXEC);
return fdopen(fd, "r");
}
diff --git a/ext/sat_xfopen.c b/ext/sat_xfopen.c
index b745826..07fcfe3 100644
--- a/ext/sat_xfopen.c
+++ b/ext/sat_xfopen.c
@@ -46,42 +46,47 @@ static FILE *mygzfopen(gzFile* gzf)
}
FILE *
-sat_xfopen(const char *fn)
+sat_xfopen(const char *fn, const char *mode)
{
char *suf;
gzFile *gzf;
if (!fn)
return 0;
+ if (!mode)
+ mode = "r";
suf = strrchr(fn, '.');
if (!suf || strcmp(suf, ".gz") != 0)
- return fopen(fn, "r");
- gzf = gzopen(fn, "r");
+ return fopen(fn, mode);
+ gzf = gzopen(fn, mode);
if (!gzf)
return 0;
return mygzfopen(gzf);
}
FILE *
-sat_xfopen_fd(const char *fn, int fd)
+sat_xfopen_fd(const char *fn, int fd, const char *mode)
{
char *suf;
gzFile *gzf;
suf = fn ? strrchr(fn, '.') : 0;
- if (!suf || strcmp(suf, ".gz") != 0)
+ if (!mode)
{
int fl = fcntl(fd, F_GETFL, 0);
if (fl == -1)
return 0;
fl &= O_RDONLY|O_WRONLY|O_RDWR;
if (fl == O_WRONLY)
- return fdopen(fd, "w");
+ mode = "w";
else if (fl == O_RDWR)
- return fdopen(fd, "r+");
- return fdopen(fd, "r");
+ mode = "r+";
+ else
+ mode = "r";
}
- gzf = gzdopen(fd, "r");
+ if (!suf || strcmp(suf, ".gz") != 0)
+ return fdopen(fd, mode);
+ gzf = gzdopen(fd, mode);
if (!gzf)
return 0;
return mygzfopen(gzf);
diff --git a/ext/sat_xfopen.h b/ext/sat_xfopen.h
index 826627d..910dfab 100644
--- a/ext/sat_xfopen.h
+++ b/ext/sat_xfopen.h
@@ -1,7 +1,7 @@
#ifndef SAT_XFOPEN_H
#define SAT_XFOPEN_H
-extern FILE *sat_xfopen(const char *fn);
-extern FILE *sat_xfopen_fd(const char *fn, int fd);
+extern FILE *sat_xfopen(const char *fn, const char *mode);
+extern FILE *sat_xfopen_fd(const char *fn, int fd, const char *mode);
#endif
diff --git a/tools/installcheck.c b/tools/installcheck.c
index 98c764f..f189e9c 100644
--- a/tools/installcheck.c
+++ b/tools/installcheck.c
@@ -97,7 +97,7 @@ main(int argc, char **argv)
l = strlen(argv[i]);
if (!strcmp(argv[i], "-"))
fp = stdin;
- else if ((fp = sat_xfopen(argv[i])) == 0)
+ else if ((fp = sat_xfopen(argv[i], 0)) == 0)
{
perror(argv[i]);
exit(1);
diff --git a/tools/patchcheck.c b/tools/patchcheck.c
index 82c612b..5a27525 100644
--- a/tools/patchcheck.c
+++ b/tools/patchcheck.c
@@ -527,7 +527,7 @@ main(int argc, char **argv)
l = strlen(argv[i]);
if (!strcmp(argv[i], "-"))
fp = stdin;
- else if ((fp = sat_xfopen(argv[i])) == 0)
+ else if ((fp = sat_xfopen(argv[i], 0)) == 0)
{
perror(argv[i]);
exit(1);
diff --git a/tools/rpmmd2solv.c b/tools/rpmmd2solv.c
index 328af85..18ec7ed 100644
--- a/tools/rpmmd2solv.c
+++ b/tools/rpmmd2solv.c
@@ -80,7 +80,7 @@ main(int argc, char **argv)
l = strlen(dir) + 128;
fnp = sat_malloc(l+1);
snprintf(fnp, l, "%s/primary.xml.gz", dir);
- if (!(fp = sat_xfopen(fnp)))
+ if (!(fp = sat_xfopen(fnp, 0)))
{
perror(fnp);
exit(1);
@@ -88,7 +88,7 @@ main(int argc, char **argv)
repo_add_rpmmd(repo, fp, 0, flags);
fclose(fp);
snprintf(fnp, l, "%s/diskusagedata.xml.gz", dir);
- if ((fp = sat_xfopen(fnp)))
+ if ((fp = sat_xfopen(fnp, 0)))
{
repo_add_rpmmd(repo, fp, 0, flags);
fclose(fp);
@@ -100,7 +100,7 @@ main(int argc, char **argv)
fprintf(stderr, "-l parameter too long\n");
exit(1);
}
- while (!(fp = sat_xfopen(fnp)))
+ while (!(fp = sat_xfopen(fnp, 0)))
{
fprintf(stderr, "not opened %s\n", fnp);
if (strlen(locale) > 2)
@@ -110,7 +110,7 @@ main(int argc, char **argv)
fprintf(stderr, "-l parameter too long\n");
exit(1);
}
- if ((fp = sat_xfopen(fnp)))
+ if ((fp = sat_xfopen(fnp, 0)))
break;
}
perror(fnp);
diff --git a/tools/susetags2solv.c b/tools/susetags2solv.c
index 2b926bb..a10adb3 100644
--- a/tools/susetags2solv.c
+++ b/tools/susetags2solv.c
@@ -171,7 +171,7 @@ main(int argc, char **argv)
if (!strcmp(fn, "packages") || !strcmp(fn, "packages.gz"))
{
sprintf(fnp, "%s/%s", descrdir, fn);
- FILE *fp = sat_xfopen(fnp);
+ FILE *fp = sat_xfopen(fnp, 0);
if (!fp)
{
perror(fn);
@@ -183,7 +183,7 @@ main(int argc, char **argv)
else if (!strcmp(fn, "packages.DU") || !strcmp(fn, "packages.DU.gz"))
{
sprintf(fnp, "%s/%s", descrdir, fn);
- FILE *fp = sat_xfopen(fnp);
+ FILE *fp = sat_xfopen(fnp, 0);
if (!fp)
{
perror(fn);
@@ -196,7 +196,7 @@ main(int argc, char **argv)
{
#if 0
sprintf(fnp, "%s/%s", descrdir, fn);
- FILE *fp = sat_xfopen(fnp);
+ FILE *fp = sat_xfopen(fnp, 0);
if (!fp)
{
perror(fn);
@@ -224,7 +224,7 @@ main(int argc, char **argv)
continue;
strcpy(lang, p + 1);
sprintf(fnp, "%s/%s", descrdir, fn);
- FILE *fp = sat_xfopen(fnp);
+ FILE *fp = sat_xfopen(fnp, 0);
if (!fp)
{
perror(fn);