Data Structures | Functions

# file.c File Reference

`#include "wizard/studio.h"`
`#include "wizard/blob.h"`
`#include "wizard/exception.h"`
`#include "wizard/exception-private.h"`
`#include "wizard/file.h"`
`#include "wizard/memory_.h"`
`#include "wizard/semaphore.h"`
`#include "wizard/string_.h"`
`#include "wizard/utility.h"`

## Data Structures
struct | _FileInfo
## Functions
static WizardBooleanType | RelinquishFileLock (FileInfo *, ExceptionInfo *)
static size_t | GetWizardThreadId (void)
static WizardBooleanType | AcquireFileLock (FileInfo *file_info, ExceptionInfo *exception)
WizardExport FileInfo * | AcquireFileInfo (const char *path, const char *relative_path, const FileMode mode, ExceptionInfo *exception)
WizardExport WizardBooleanType | DestroyFile (FileInfo *file_info, ExceptionInfo *exception)
WizardExport FileInfo * | DestroyFileInfo (FileInfo *file_info, ExceptionInfo *exception)
WizardExport int | GetFileDescriptor (const FileInfo *file_info)
WizardExport const char * | GetFilePath (const FileInfo *file_info)
WizardExport struct stat * | GetFileProperties (const FileInfo *file_info)
WizardExport int | ReadFileByte (FileInfo *file_info)
WizardExport WizardBooleanType | ReadFileChunk (FileInfo *file_info, void *data, const size_t length)
WizardExport WizardBooleanType | ReadFile16Bits (FileInfo *file_info, unsigned short *value)
WizardExport WizardBooleanType | ReadFile32Bits (FileInfo *file_info, size_t *value)
WizardExport WizardBooleanType | ReadFile64Bits (FileInfo *file_info, WizardSizeType *value)
WizardExport WizardBooleanType | WriteFileChunk (FileInfo *file_info, const void *data, const size_t length)
WizardExport WizardBooleanType | WriteFile16Bits (FileInfo *file_info, const unsigned short value)
WizardExport WizardBooleanType | WriteFile32Bits (FileInfo *file_info, const size_t value)
WizardExport WizardBooleanType | WriteFile64Bits (FileInfo *file_info, const WizardSizeType value)

## Function Documentation

WizardExport FileInfo* AcquireFileInfo | ( | const char * | path,
|  | const char * | relative_path,
|  | const FileMode | mode,
|  | ExceptionInfo * | exception |
| ) |  |  |

References AcquireFileLock(), AcquireString(), AcquireWizardMemory(), AllocateSemaphoreInfo(), ConcatenateWizardString(), CopyWizardString(), DestroyFileInfo(), DirectorySeparator, _FileInfo::file, GetEnvironmentValue(), GetWizardModule, LogWizardEvent(), MaxTextExtent, mkdir, O_BINARY, open, _FileInfo::path, _FileInfo::properties, ReadFileMode, RelinquishWizardMemory(), ResetWizardMemory(), S_MODE, _FileInfo::semaphore, _FileInfo::signature, ThrowWizardException(), _FileInfo::timestamp, TraceEvent, and WriteFileMode.

Referenced by ExportKeyringKey(), GetEntropyFromReservoir(), ImportKeyringKey(), PrintKeyringProperties(), and SaveEntropyToReservoir().

static WizardBooleanType AcquireFileLock | ( | FileInfo * | file_info,
|  | ExceptionInfo * | exception |
| ) |  |  | `[static]`

References AcquireString(), AppendFileExtension(), close, DestroyString(), _FileInfo::file, getpid, GetWizardModule, GetWizardThreadId(), LockSemaphoreInfo(), LogWizardEvent(), open, _FileInfo::path, ReadFileChunk(), S_MODE, _FileInfo::semaphore, _FileInfo::signature, ThrowWizardException(), TraceEvent, UnlockSemaphoreInfo(), WizardFalse, WizardSignature, WizardTrue, and WriteFileChunk().

Referenced by AcquireFileInfo().

WizardExport WizardBooleanType DestroyFile | ( | FileInfo * | file_info,
|  | ExceptionInfo * | exception |
| ) |  |  |

References close, _FileInfo::file, GetWizardModule, _FileInfo::path, ThrowWizardException(), WizardFalse, and WizardTrue.

WizardExport FileInfo* DestroyFileInfo | ( | FileInfo * | file_info,
|  | ExceptionInfo * | exception |
| ) |  |  |

References close, DestroySemaphoreInfo(), DestroyString(), _FileInfo::file, GetWizardModule, LockSemaphoreInfo(), LogWizardEvent(), _FileInfo::path, RelinquishFileLock(), RelinquishWizardMemory(), _FileInfo::semaphore, _FileInfo::signature, ThrowWizardException(), TraceEvent, UnlockSemaphoreInfo(), and WizardSignature.

Referenced by AcquireFileInfo(), ExportKeyringKey(), GetEntropyFromReservoir(), ImportKeyringKey(), PrintKeyringProperties(), and SaveEntropyToReservoir().

WizardExport int GetFileDescriptor | ( | const FileInfo * | file_info | ) |

References _FileInfo::file, GetWizardModule, LogWizardEvent(), _FileInfo::signature, TraceEvent, and WizardSignature.

Referenced by ImportKeyringKey().

WizardExport const char* GetFilePath | ( | const FileInfo * | file_info | ) |

References GetWizardModule, LogWizardEvent(), _FileInfo::path, _FileInfo::signature, TraceEvent, and WizardSignature.

Referenced by ExportKeyringKey(), GetEntropyFromReservoir(), ImportKeyringKey(), PrintKeyringProperties(), and SaveEntropyToReservoir().

WizardExport struct stat* GetFileProperties | ( | const FileInfo * | file_info | ) | `[read]`

References GetWizardModule, LogWizardEvent(), _FileInfo::properties, _FileInfo::signature, TraceEvent, and WizardSignature.

Referenced by PrintKeyringProperties().

static size_t GetWizardThreadId | ( | void |  | ) | `[static]`

References getpid.

Referenced by AcquireFileLock(), AllocateSemaphoreInfo(), GenerateEntropicChaos(), and LockSemaphoreInfo().

WizardExport WizardBooleanType ReadFile16Bits | ( | FileInfo * | file_info,
|  | unsigned short * | value |
| ) |  |  |

References ReadFileChunk(), _FileInfo::signature, WizardFalse, and WizardSignature.

Referenced by ExportKeyringKey(), GetEntropyFromReservoir(), and PrintKeyringProperties().

WizardExport WizardBooleanType ReadFile32Bits | ( | FileInfo * | file_info,
|  | size_t * | value |
| ) |  |  |

References ReadFileChunk(), _FileInfo::signature, WizardFalse, and WizardSignature.

Referenced by ExportKeyringKey(), GetEntropyFromReservoir(), and PrintKeyringProperties().

WizardExport WizardBooleanType ReadFile64Bits | ( | FileInfo * | file_info,
|  | WizardSizeType * | value |
| ) |  |  |

References ReadFileChunk(), _FileInfo::signature, WizardFalse, and WizardSignature.

Referenced by ExportKeyringKey(), GetEntropyFromReservoir(), and PrintKeyringProperties().

WizardExport int ReadFileByte | ( | FileInfo * | file_info | ) |

References ReadFileChunk(), _FileInfo::signature, WizardFalse, and WizardSignature.

WizardExport WizardBooleanType ReadFileChunk | ( | FileInfo * | file_info,
|  | void * | data,
|  | const size_t | length |
| ) |  |  |

References _FileInfo::file, GetWizardModule, LogWizardEvent(), Min, _FileInfo::path, read, _FileInfo::signature, TraceEvent, WizardFalse, WizardMaxBufferExtent, WizardSignature, and WizardTrue.

Referenced by AcquireFileLock(), ExportKeyringKey(), GetEntropyFromReservoir(), PrintKeyringProperties(), ReadFile16Bits(), ReadFile32Bits(), ReadFile64Bits(), and ReadFileByte().

static WizardBooleanType RelinquishFileLock | ( | FileInfo * | file_info,
|  | ExceptionInfo * | exception |
| ) |  |  | `[static]`

References AcquireString(), AppendFileExtension(), DestroyString(), GetWizardModule, _FileInfo::path, ThrowWizardException(), WizardFalse, and WizardTrue.

Referenced by DestroyFileInfo().

WizardExport WizardBooleanType WriteFile16Bits | ( | FileInfo * | file_info,
|  | const unsigned short | value |
| ) |  |  |

References _FileInfo::signature, WizardSignature, and WriteFileChunk().

Referenced by ImportKeyringKey(), and SaveEntropyToReservoir().

WizardExport WizardBooleanType WriteFile32Bits | ( | FileInfo * | file_info,
|  | const size_t | value |
| ) |  |  |

References GetWizardModule, LogWizardEvent(), TraceEvent, and WriteFileChunk().

Referenced by ImportKeyringKey(), and SaveEntropyToReservoir().

WizardExport WizardBooleanType WriteFile64Bits | ( | FileInfo * | file_info,
|  | const WizardSizeType | value |
| ) |  |  |

References GetWizardModule, LogWizardEvent(), TraceEvent, and WriteFileChunk().

Referenced by ImportKeyringKey(), and SaveEntropyToReservoir().

WizardExport WizardBooleanType WriteFileChunk | ( | FileInfo * | file_info,
|  | const void * | data,
|  | const size_t | length |
| ) |  |  |

References _FileInfo::file, GetWizardModule, LogWizardEvent(), _FileInfo::path, _FileInfo::signature, TraceEvent, WizardFalse, WizardSignature, WizardTrue, and write.

Referenced by AcquireFileLock(), ImportKeyringKey(), SaveEntropyToReservoir(), WriteFile16Bits(), WriteFile32Bits(), and WriteFile64Bits().