/* Make * make an initialized structure * NB - does NOT attach reference to dir, but steals it */ static rc_t KDatabaseMake ( KDatabase **dbp, const KDirectory *dir, const char *path, KMD5SumFmt *md5, bool read_only ) { KDatabase *db; rc_t rc = 0; assert ( dbp != NULL ); assert ( path != NULL ); db = malloc ( sizeof * db + strlen ( path ) ); if ( db == NULL ) { * dbp = NULL; return RC ( rcDB, rcDatabase, rcConstructing, rcMemory, rcExhausted ); } memset ( db, 0, sizeof * db ); db -> dir = ( KDirectory* ) dir; db -> md5 = md5; rc = KMD5SumFmtAddRef ( md5 ); db -> use_md5 = ( md5 == NULL ) ? false : true; KRefcountInit ( & db -> refcount, 1, "KDatabase", "make", path ); db -> opencount = 1; db -> read_only = read_only; strcpy ( db -> path, path ); db->sym.u.obj = db; StringInitCString (&db->sym.name, db->path); db->sym.type = kptDatabase; * dbp = db; return rc; }
rc_t CCCopyMake (CCCopy ** p, const KDirectory * in, KDirectory * out, KDirectory * xml, bool force, KMD5SumFmt * md5, CCFileFormat * ff, CCTree * tree, const char * path) { rc_t rc; size_t pathlen; CCCopy * self; char relpath [4096]; assert (in != NULL); assert (out != NULL); assert (xml != NULL); assert (path != NULL); rc = KDirectoryVResolvePath (in, false, relpath, sizeof relpath, path, NULL); if (rc != 0) { pLOGERR (klogErr, rc, "unable to resolve path $(P)", PLOG_S(P), path); return rc; } if ((relpath[0] == '.') && (relpath[1] == '.') && (relpath[2] == '/')) { rc = RC (rcExe, rcDirectory, rcResolving, rcPath, rcOutOfKDirectory); pLOGERR (klogErr, rc, "Path must resolve to current directory or subdirectories $(P)", PLOG_S(P), relpath); return rc; } pathlen = strlen(relpath); self = malloc (sizeof (*self) - sizeof (*self->path) + pathlen + 1); if (self == NULL) rc = RC (rcExe, rcNoTarg, rcAllocating, rcMemory, rcExhausted); else { atomic32_set (&self->refcount, 1); KDirectoryAddRef (in); KDirectoryAddRef (out); KDirectoryAddRef (xml); KMD5SumFmtAddRef (md5); CCFileFormatAddRef (ff); self->in = in; self->out = out; self->xml = xml; self->force = force; self->md5 = md5; self->ff = ff; self->tree = tree; memcpy (self->path, relpath, pathlen+1); *p = self; } return rc; }
rc_t ProcessOneMake (ProcessOne ** ppo, const KDirectory * dir, KDirectory * xml, const KFile * file, KMD5SumFmt *md5, CCFileFormat * ff, const char * path) { ProcessOne * self; rc_t rc = 0; size_t pathlen; PLOGMSG (klogDebug10, "ProcessOneMake $(f)", PLOG_S(f), path); /* legit seeming inputs? these could be replaced with RC returns */ assert (ppo != NULL); assert (file != NULL); assert (path != NULL); /* allocate the object */ pathlen = strlen (path); self = malloc (sizeof (*self) - sizeof(self->path) + pathlen + 1); if (self == NULL) { rc = RC (rcExe, rcNoTarg, rcAllocating, rcMemory, rcExhausted); } else { atomic32_set (&self->refcount, 1); KDirectoryAddRef (dir); KDirectoryAddRef (xml); KMD5SumFmtAddRef (md5); CCFileFormatAddRef (ff); KFileAddRef (file); self->dir = dir; self->xml = xml; self->md5 = md5; self->file = file; self->ff = ff; memcpy (self->path, path, pathlen); self->path[pathlen] = '\0'; rc = 0; } *ppo = self; return rc; }