- if (debugsw)
- fprintf (stderr, "caching by copying %s...\n", ce->ce_file);
-
- file = NULL;
- if ((*ct->c_ceopenfnx) (ct, &file) == NOTOK)
- goto reset_umask;
-
- if ((fp = fopen (cachefile, "w"))) {
- int cc;
- char buffer[BUFSIZ];
- FILE *gp = ce->ce_fp;
-
- fseek (gp, 0L, SEEK_SET);
-
- while ((cc = fread (buffer, sizeof(*buffer), sizeof(buffer), gp))
- > 0)
- fwrite (buffer, sizeof(*buffer), cc, fp);
- fflush (fp);
-
- if (ferror (gp)) {
- admonish (ce->ce_file, "error reading");
- unlink (cachefile);
- } else {
- if (ferror (fp)) {
- admonish (cachefile, "error writing");
- unlink (cachefile);
- }
- }
- fclose (fp);
- } else
- content_error (cachefile, ct, "unable to fopen for writing");
+ if (ce->ce_file) {
+ int mask = umask(cachetype ? ~m_gmprot() : 0222);
+ FILE *fp;
+
+ if (debugsw)
+ fprintf(stderr, "caching by copying %s...\n",
+ ce->ce_file);
+
+ file = NULL;
+ if ((*ct->c_ceopenfnx) (ct, &file) == NOTOK)
+ goto reset_umask;
+
+ if ((fp = fopen(cachefile, "w"))) {
+ int cc;
+ char buffer[BUFSIZ];
+ FILE *gp = ce->ce_fp;
+
+ fseek(gp, 0L, SEEK_SET);
+
+ while ((cc = fread(buffer, sizeof(*buffer),
+ sizeof(buffer), gp)) > 0)
+ fwrite(buffer, sizeof(*buffer), cc, fp);
+ fflush(fp);
+
+ if (ferror(gp)) {
+ admonish(ce->ce_file, "error reading");
+ unlink(cachefile);
+ } else {
+ if (ferror(fp)) {
+ admonish(cachefile, "error writing");
+ unlink(cachefile);
+ }
+ }
+ fclose(fp);
+ } else
+ content_error(cachefile, ct,
+ "unable to fopen for writing");