migrated write_chunk() to chunk_write()

This commit is contained in:
Andreas Steffen
2009-04-20 06:58:00 +00:00
parent 4f4ae2f465
commit 3eb5042e9c
8 changed files with 25 additions and 81 deletions
+1 -1
View File
@@ -308,7 +308,7 @@ insert_crl(chunk_t blob, chunk_t crl_uri, bool cache_crl)
datatot(subjectKeyID.ptr, subjectKeyID.len, 16, buf, BUF_LEN);
snprintf(path, BUF_LEN, "%s/%s.crl", CRL_PATH, buf);
write_chunk(path, "crl", crl->certificateList, 0022, TRUE);
chunk_write(crl->certificateList, path, "crl", 0022, TRUE);
}
/* is the fetched crl valid? */
-49
View File
@@ -94,55 +94,6 @@ mv_chunk(u_char **pos, chunk_t content)
}
}
/*
* write the binary contents of a chunk_t to a file
*/
bool
write_chunk(const char *filename, const char *label, chunk_t ch
, mode_t mask, bool force)
{
mode_t oldmask;
FILE *fd;
size_t written;
if (!force)
{
fd = fopen(filename, "r");
if (fd)
{
fclose(fd);
plog(" %s file '%s' already exists", label, filename);
return FALSE;
}
}
/* set umask */
oldmask = umask(mask);
fd = fopen(filename, "w");
if (fd)
{
written = fwrite(ch.ptr, sizeof(u_char), ch.len, fd);
fclose(fd);
if (written != ch.len)
{
plog(" writing to %s file '%s' failed", label, filename);
umask(oldmask);
return FALSE;
}
plog(" written %s file '%s' (%d bytes)", label, filename, (int)ch.len);
umask(oldmask);
return TRUE;
}
else
{
plog(" could not open %s file '%s' for writing", label, filename);
umask(oldmask);
return FALSE;
}
}
/* checks if the expiration date has been reached and
* warns during the warning_interval of the imminent
* expiry. strict=TRUE declares a fatal error,
-6
View File
@@ -63,10 +63,6 @@ extern const char* concatenate_paths(const char *a, const char *b);
/* move a chunk to a memory position and free it after insertion */
extern void mv_chunk(u_char **pos, chunk_t content);
/* write the binary contents of a chunk_t to a file */
extern bool write_chunk(const char *filename, const char *label, chunk_t ch
,mode_t mask, bool force);
/* warns a predefined interval before expiry */
extern const char* check_expiry(time_t expiration_date,
int warning_interval, bool strict);
@@ -88,10 +84,8 @@ typedef struct dirent dirent_t;
extern int file_select(const dirent_t *entry);
/* cleanly exit Pluto */
extern void exit_pluto(int /*status*/) NEVER_RETURNS;
/* zero all bytes */
#define zero(x) memset((x), '\0', sizeof(*(x)))