/* Import the contents of a file in a den archive. */ int AG_DenImportFile(AG_Den *den, int ind, const char *name, const char *lang, const char *infile) { char buf[8192]; AG_DenMember *memb; FILE *f; size_t size, rrv; off_t offs; offs = AG_Tell(den->buf); size = 0; if ((f = fopen(infile, "rb")) == NULL) { AG_SetError("Unable to open %s", infile); return (-1); } for (;;) { rrv = fread(buf, 1, sizeof(buf), f); size += rrv; if (AG_Write(den->buf, buf, rrv, 1) != 0) { return (-1); } } fclose(f); memb = &den->members[ind]; Strlcpy(memb->name, name, sizeof(memb->name)); Strlcpy(memb->lang, lang, sizeof(memb->lang)); memb->offs = offs; memb->size = size; return (0); }
/* Write the den mappings. */ void AG_DenWriteMappings(AG_Den *den) { Uint32 i; AG_Seek(den->buf, den->mapoffs, AG_SEEK_SET); for (i = 0; i < den->nmembers; i++) { AG_DenMember *memb = &den->members[i]; AG_WriteUint32(den->buf, (Uint32)sizeof(memb->name)); if (AG_Write(den->buf, memb->name, sizeof(memb->name), 1) != 0) AG_FatalError(NULL); AG_WriteUint32(den->buf, (Uint32)sizeof(memb->lang)); if (AG_Write(den->buf, memb->lang, sizeof(memb->lang), 1) != 0) AG_FatalError(NULL); AG_WriteUint32(den->buf, (Uint32)memb->offs); AG_WriteUint32(den->buf, (Uint32)memb->size); } }
static int Save(void *obj, AG_DataSource *ds) { AG_Config *cfg = obj; char buf[30]; AG_SetInt(cfg, "initial-run", 0); #ifdef AG_DEBUG AG_WriteUint8(ds, (Uint8)agDebugLvl); #else AG_WriteUint8(ds, 0); #endif /* For backward compatibility with <9.5 (pre-1.4.2) saves. */ memset(buf, 0, sizeof(buf)); AG_Write(ds, buf, sizeof(buf)); AG_WriteString(ds, ""); /* agRcsHostname */ AG_WriteUint16(ds, 0); /* agRcsPort */ AG_WriteString(ds, ""); /* agRcsUsername */ AG_WriteString(ds, ""); /* agRcsPassword */ return (0); }
/* Write Agar archive version information. */ int AG_WriteVersion(AG_DataSource *ds, const char *name, const AG_Version *ver) { char nbuf[AG_VERSION_NAME_MAX]; int i; for (i = 0; i < sizeof(nbuf); i += 4) { nbuf[i ] = 'a'; nbuf[i+1] = 'g'; nbuf[i+2] = 'a'; nbuf[i+3] = 'r'; } Strlcpy(nbuf, name, sizeof(nbuf)); if (AG_Write(ds, nbuf, sizeof(nbuf), 1) != 0) { AG_SetError("Writing magic: %s", AG_GetError()); return (-1); } if (AG_WriteUint32v(ds, &ver->major) == -1 || AG_WriteUint32v(ds, &ver->minor) == -1) { AG_SetError("Writing version numbers: %s", AG_GetError()); return (-1); } return (0); }