migrated write_chunk() to chunk_write()
This commit is contained in:
@@ -208,7 +208,7 @@ void chunk_split(chunk_t chunk, const char *mode, ...)
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
bool chunk_write(chunk_t chunk, char *path, mode_t mask, bool force)
|
||||
bool chunk_write(chunk_t chunk, char *path, char *label, mode_t mask, bool force)
|
||||
{
|
||||
mode_t oldmask;
|
||||
FILE *fd;
|
||||
@@ -216,7 +216,7 @@ bool chunk_write(chunk_t chunk, char *path, mode_t mask, bool force)
|
||||
|
||||
if (!force && access(path, F_OK) == 0)
|
||||
{
|
||||
DBG1(" file '%s' already exists", path);
|
||||
DBG1(" %s file '%s' already exists", label, path);
|
||||
return FALSE;
|
||||
}
|
||||
oldmask = umask(mask);
|
||||
@@ -225,18 +225,20 @@ bool chunk_write(chunk_t chunk, char *path, mode_t mask, bool force)
|
||||
{
|
||||
if (fwrite(chunk.ptr, sizeof(u_char), chunk.len, fd) == chunk.len)
|
||||
{
|
||||
DBG1(" written to %s file '%s' (%d bytes)",
|
||||
label, path, chunk.len);
|
||||
good = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG1(" writing to file '%s' failed: %s", path, strerror(errno));
|
||||
DBG1(" writing to %s file '%s' failed: %s",
|
||||
label, path, strerror(errno));
|
||||
}
|
||||
fclose(fd);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG1(" could not open file '%s': %s", path, strerror(errno));
|
||||
DBG1(" could not open %s file '%s': %s", label, path, strerror(errno));
|
||||
}
|
||||
umask(oldmask);
|
||||
return good;
|
||||
|
||||
@@ -86,8 +86,14 @@ void chunk_split(chunk_t chunk, const char *mode, ...);
|
||||
|
||||
/**
|
||||
* Write the binary contents of a chunk_t to a file
|
||||
*/
|
||||
bool chunk_write(chunk_t chunk, char *path, mode_t mask, bool force);
|
||||
*
|
||||
* @param path path where file is written to
|
||||
* @param label label specifying file type
|
||||
* @param mask file mode creation mask
|
||||
* @param force overwrite existing file by force
|
||||
* @return TRUE if write operation was successful
|
||||
*/
|
||||
bool chunk_write(chunk_t chunk, char *path, char *label, mode_t mask, bool force);
|
||||
|
||||
/**
|
||||
* Convert a chunk of data to hex encoding.
|
||||
@@ -95,7 +101,6 @@ bool chunk_write(chunk_t chunk, char *path, mode_t mask, bool force);
|
||||
* The resulting string is '\\0' terminated, but the chunk does not include
|
||||
* the '\\0'. If buf is supplied, it must hold at least (chunk.len * 2 + 1).
|
||||
*
|
||||
* @param chunk data to convert
|
||||
* @param buf buffer to write to, NULL to malloc
|
||||
* @param uppercase TRUE to use uppercase letters
|
||||
* @return chunk of encoded data
|
||||
|
||||
Reference in New Issue
Block a user