Logo Search packages:      
Sourcecode: cbmconvert version File versions  Download package

enum WrStatus WriteArchive ( const struct Filename name,
const byte_t data,
size_t  length,
struct Archive archive,
log_t  log 

Write a file to an archive.

name native (PETSCII) name of the file
data the contents of the file
length length of the file contents
archive the archive the file is written to
log Call-back function for diagnostic output
status of the operation

Definition at line 64 of file archive.c.

References ArchiveEntry::data, DEL, Errors, Archive::first, Archive::last, ArchiveEntry::length, ArchiveEntry::name, ArchiveEntry::next, PRG, REL, SEQ, Filename::type, USR, WrFail, WrFileExists, WrNoSpace, and WrOK.

Referenced by writeFile().

  struct ArchiveEntry* ae;

  switch (name->type) {
    (*log) (Errors, name, "Unsupported file type.");
    return WrFail;
  case DEL:
  case SEQ:
  case PRG:
  case USR:
  case REL:

  /* check for duplicate file names */
  for (ae = archive->first; ae; ae = ae->next)
    if (!memcmp (&ae->name, name, sizeof (struct Filename)))
      return WrFileExists;

  if (!(ae = malloc (sizeof (*ae)))) {
    (*log) (Errors, name, "Out of memory.");
    return WrNoSpace;

  if (!(ae->data = malloc (length))) {
    free (ae);
    (*log) (Errors, name, "Out of memory.");
    return WrNoSpace;

  memcpy (&ae->name, name, sizeof (*name));
  memcpy (ae->data, data, length);
  ae->length = length;
  ae->next = 0;

  if (archive->last)
    archive->last->next = ae;
    archive->first = ae;

  archive->last = ae;

  return WrOK;

Generated by  Doxygen 1.6.0   Back to index