static int pcinfo(int n, Rpccall *cmd, Rpccall *reply) { uchar *argptr = cmd->args; uchar *dataptr = reply->results; String vers, cm; int i; chat("host=%I, port=%ld: pcinfo...", cmd->host, cmd->port); if(n <= 16) return garbage(reply, "count too small"); argptr += string2S(argptr, &vers); argptr += string2S(argptr, &cm); if(argptr != &((uchar *)cmd->args)[n]) return garbage(reply, "bad count"); chat("\"%.*s\",\"%.*s\"\n", utfnlen(vers.s, vers.n), vers.s, utfnlen(cm.s, cm.n), cm.s); PLONG(sizeof(pc_vers)-1); PPTR(pc_vers, sizeof(pc_vers)-1); PLONG(sizeof(no_comment)-1); PPTR(no_comment, sizeof(no_comment)-1); PLONG(nelem(pcfacilities)); for(i=0; i<nelem(pcfacilities); i++) PLONG(pcfacilities[i]); return dataptr - (uchar *)reply->results; }
static int pc1auth(int n, Rpccall *cmd, Rpccall *reply) { uchar *argptr = cmd->args; uchar *dataptr = reply->results; String id, pw; Unixidmap *m; int uid; chat("host=%I, port=%ld: pcauth...", cmd->host, cmd->port); if(n <= 8) return garbage(reply, "count too small"); argptr += string2S(argptr, &id); argptr += string2S(argptr, &pw); if(argptr != &((uchar*)cmd->args)[n]) return garbage(reply, "bad count"); scramble(&id); scramble(&pw); m = pair2idmap("pcnfsd", cmd->host); uid = -1; if(m) uid = name2id(&m->u.ids, id.s); if(uid < 0) uid = 1; chat("\"%.*s\",\"%.*s\" uid=%d\n", utfnlen(id.s, id.n), id.s, utfnlen(pw.s, pw.n), pw.s, uid); PLONG(0); /* status */ PLONG(uid); /* uid */ PLONG(uid); /* gid */ return dataptr - (uchar*)reply->results; }
static int creat(int n, Rpccall *cmd, Rpccall *reply, int chdir) { Xfid *xf, *newxf; Xfile *xp; String elem; Dir dir; Sattr sattr; uchar *argptr = cmd->args; uchar *dataptr = reply->results; int trunced; if(n <= FHSIZE) return garbage(reply, "count too small"); xf = rpc2xfid(cmd, 0); argptr += FHSIZE; argptr += string2S(argptr, &elem); argptr += convM2sattr(argptr, &sattr); if(argptr != &((uchar *)cmd->args)[n]) return garbage(reply, "bad count"); if(xf == 0) return error(reply, NFSERR_STALE); xp = xf->xp; if(!(xp->qid.type & QTDIR)) return error(reply, NFSERR_NOTDIR); chat("%s/%.*s...", xp->name, utfnlen(elem.s, elem.n), elem.s); trunced = 0; if(xp->parent == xp && elem.s[0] == '#'){ newxf = xfauth(xp, &elem); if(newxf == 0) return error(reply, NFSERR_PERM); if(xfauthremove(newxf, cmd->user) < 0) return error(reply, NFSERR_PERM); trunced = 1; }else newxf = xfwalkcr(Twalk, xf, &elem, 0); if(newxf == 0){ newxf = xfwalkcr(Tcreate, xf, &elem, chdir|(sattr.mode&0777)); if(newxf) trunced = 1; else newxf = xfwalkcr(Twalk, xf, &elem, 0); } if(newxf == 0) return error(reply, NFSERR_PERM); if(!trunced && chdir) return error(reply, NFSERR_EXIST); if(!trunced && xfopen(newxf, Trunc|Oread|Owrite) < 0) return error(reply, NFSERR_PERM); if(xfstat(newxf, &dir) < 0) return error(reply, NFSERR_IO); PLONG(NFS_OK); dataptr += xp2fhandle(newxf->xp, dataptr); dataptr += dir2fattr(cmd->up, &dir, dataptr); chat("OK\n"); return dataptr - (uchar *)reply->results; }
static int nfssetattr(int n, Rpccall *cmd, Rpccall *reply) { Xfid *xf; Dir dir, nd; Sattr sattr; int r; uchar *argptr = cmd->args; uchar *dataptr = reply->results; chat("setattr..."); if(n <= FHSIZE) return garbage(reply, "count too small"); xf = rpc2xfid(cmd, &dir); argptr += FHSIZE; argptr += convM2sattr(argptr, &sattr); if(argptr != &((uchar *)cmd->args)[n]) return garbage(reply, "bad count"); chat("mode=0%lo,u=%ld,g=%ld,size=%ld,atime=%ld,mtime=%ld...", sattr.mode, sattr.uid, sattr.gid, sattr.size, sattr.atime, sattr.mtime); if(xf == 0) return error(reply, NFSERR_STALE); if(sattr.uid != NOATTR || sattr.gid != NOATTR) return error(reply, NFSERR_PERM); if(sattr.size == 0){ if(xf->xp->s != xf->xp->parent->s){ if(xfauthremove(xf, cmd->user) < 0) return error(reply, NFSERR_PERM); }else if(dir.length && xfopen(xf, Trunc|Oread|Owrite) < 0) return error(reply, NFSERR_PERM); }else if(sattr.size != NOATTR) return error(reply, NFSERR_PERM); r = 0; nulldir(&nd); if(sattr.mode != NOATTR) ++r, nd.mode = (dir.mode & ~0777) | (sattr.mode & 0777); if(sattr.atime != NOATTR) ++r, nd.atime = sattr.atime; if(sattr.mtime != NOATTR) ++r, nd.mtime = sattr.mtime; chat("sattr.mode=%luo dir.mode=%luo nd.mode=%luo...", sattr.mode, dir.mode, nd.mode); if(r){ r = xfwstat(xf, &nd); if(r < 0) return error(reply, NFSERR_PERM); } if(xfstat(xf, &dir) < 0) return error(reply, NFSERR_STALE); PLONG(NFS_OK); dataptr += dir2fattr(cmd->up, &dir, dataptr); chat("OK\n"); return dataptr - (uchar *)reply->results; }
static int mntmnt(int n, Rpccall *cmd, Rpccall *reply) { int i; char dom[64]; uchar *argptr = cmd->args; uchar *dataptr = reply->results; Authunix au; Xfile *xp; String root; chat("mntmnt...\n"); if(n < 8) return garbage(reply, "n too small"); argptr += string2S(argptr, &root); if(argptr != &((uchar *)cmd->args)[n]) return garbage(reply, "bad count"); clog("host=%I, port=%ld, root=\"%.*s\"...", cmd->host, cmd->port, utfnlen(root.s, root.n), root.s); if(auth2unix(&cmd->cred, &au) != 0){ chat("auth flavor=%ld, count=%ld\n", cmd->cred.flavor, cmd->cred.count); for(i=0; i<cmd->cred.count; i++) chat(" %.2ux", ((uchar *)cmd->cred.data)[i]); chat("\n"); clog("auth: bad credentials"); return error(reply, 1); } clog("auth: %ld %.*s u=%ld g=%ld", au.stamp, utfnlen(au.mach.s, au.mach.n), au.mach.s, au.uid, au.gid); for(i=0; i<au.gidlen; i++) chat(", %ld", au.gids[i]); chat("..."); if(getdom(cmd->host, dom, sizeof(dom))<0){ clog("auth: unknown ip address"); return error(reply, 1); } chat("dom=%s...", dom); xp = xfroot(root.s, root.n); if(xp == 0){ chat("xp=0..."); clog("mntmnt: no fs"); return error(reply, 3); } PLONG(0); dataptr += xp2fhandle(xp, dataptr); chat("OK\n"); return dataptr - (uchar *)reply->results; }
static int remov(int n, Rpccall *cmd, Rpccall *reply) { Session *s; Xfile *xp; Xfid *xf, *newxf; String elem; Fid *nfid; uchar *argptr = cmd->args; uchar *dataptr = reply->results; if(n <= FHSIZE) return garbage(reply, "count too small"); xf = rpc2xfid(cmd, 0); argptr += FHSIZE; argptr += string2S(argptr, &elem); if(argptr != &((uchar *)cmd->args)[n]) return garbage(reply, "bad count"); if(xf == 0) return error(reply, NFSERR_STALE); xp = xf->xp; if(!(xp->qid.type & QTDIR)) return error(reply, NFSERR_NOTDIR); chat("%s/%.*s...", xp->name, utfnlen(elem.s, elem.n), elem.s); if(xp->s->noauth == 0 && xp->parent == xp && elem.s[0] == '#') return error(reply, NFSERR_PERM); newxf = xfwalkcr(Twalk, xf, &elem, 0); if(newxf == 0) return error(reply, NFSERR_NOENT); s = xp->s; nfid = newfid(s); setfid(s, newxf->urfid); s->f.newfid = nfid - s->fids; s->f.nwname = 0; if(xmesg(s, Twalk) < 0){ putfid(s, nfid); return error(reply, NFSERR_IO); } s->f.fid = nfid - s->fids; if(xmesg(s, Tremove) < 0){ putfid(s, nfid); return error(reply, NFSERR_PERM); } putfid(s, nfid); xpclear(newxf->xp); PLONG(NFS_OK); chat("OK\n"); return dataptr - (uchar *)reply->results; }
struct blk * copy(struct blk *hptr,int size) { register struct blk *hdr; register unsigned sz; register char *ptr; all++; nbytes += size; sz = length(hptr); ptr = nalloc(hptr->beg, (unsigned)size); if(ptr == 0){ garbage("copy"); if((ptr = nalloc(hptr->beg, (unsigned)size)) == NULL){ printf("copy size %d\n",size); ospace("copy"); } } if((hdr = hfree) == 0)hdr = morehd(); hfree = (struct blk *)hdr->rd; hdr->rd = hdr->beg = ptr; hdr->last = ptr+size; hdr->wt = ptr+sz; ptr = hdr->wt; while(ptr<hdr->last)*ptr++ = '\0'; return(hdr); }
Blk* salloc(int size) { Blk *hdr; char *ptr; all++; lall++; if(all - rel > active) active = all - rel; nbytes += size; lbytes += size; if(nbytes >maxsize) maxsize = nbytes; if(size > longest) longest = size; ptr = malloc((unsigned)size); if(ptr == 0){ garbage("salloc"); if((ptr = malloc((unsigned)size)) == 0) ospace("salloc"); } if((hdr = hfree) == 0) hdr = morehd(); hfree = (Blk *)hdr->rd; hdr->rd = hdr->wt = hdr->beg = ptr; hdr->last = ptr+size; return(hdr); }
/* Change $ptr's records. Called in mallfuncs context. */ static void *regarbage(void *ptr, void *newptr, size_t size) { struct ero_st *prev, *mem; if (!newptr) return NULL; /* Adjust the ->size of $ptr's $mem if we alredy keep a record of it. */ for (prev = NULL, mem = Memories; mem; prev = mem, mem = mem->next) if (mem->ptr == ptr) { NAllocations++; Allocated += size - mem->size; if (Peak < Allocated) Peak = Allocated; mem->ptr = newptr; mem->size = size; /* Try to keep the head of $Memories hot and move $mem there. */ if (prev) { prev->next = mem->next; mem->next = Memories; Memories = mem; } return newptr; } /* Haven't seen $ptr yet. */ return garbage(newptr, size, 1); } /* regarbage */
static int mntexport(int n, Rpccall *cmd, Rpccall *reply) { uchar *dataptr = reply->results; Authunix au; int i; chat("mntexport..."); if(n != 0) return garbage(reply, "mntexport"); if(auth2unix(&cmd->cred, &au) != 0){ chat("auth flavor=%ld, count=%ld\n", cmd->cred.flavor, cmd->cred.count); for(i=0; i<cmd->cred.count; i++) chat(" %.2ux", ((uchar *)cmd->cred.data)[i]); chat("..."); au.mach.n = 0; }else chat("%ld@%.*s...", au.uid, utfnlen(au.mach.s, au.mach.n), au.mach.s); PLONG(TRUE); PLONG(1); PPTR("/", 1); if(au.mach.n > 0){ PLONG(TRUE); PLONG(au.mach.n); PPTR(au.mach.s, au.mach.n); } PLONG(FALSE); PLONG(FALSE); chat("OK\n"); return dataptr - (uchar *)reply->results; }
void GarbageTestCase::LoadGarbage() { srand(1234); wxInitAllImageHandlers(); for (size_t size = 1; size < GARBAGE_DATA_SIZE; size *= size+1) { // first, generate some garbage data unsigned char *data = new unsigned char[size]; for (size_t i = 0; i < size; i++) data[i] = rand(); // write it to a file wxString garbagename = wxFileName::CreateTempFileName("garbage"); CPPUNIT_ASSERT( !garbagename.empty() ); wxFile garbage(garbagename, wxFile::write); CPPUNIT_ASSERT( garbage.IsOpened() ); CPPUNIT_ASSERT( garbage.Write(data, size) == size ); garbage.Close(); // try to load it by name DoLoadFile(garbagename); // try to load it from a wxInputStream wxMemoryInputStream stream(data, size); DoLoadStream(stream); wxDELETEA(data); } }
static int nfsstatfs(int n, Rpccall *cmd, Rpccall *reply) { uchar *dataptr = reply->results; enum { Xfersize = 2048, Maxlong = (long)((1ULL<<31) - 1), Maxfreeblks = Maxlong / Xfersize, }; chat("statfs..."); showauth(&cmd->cred); if(n != FHSIZE) return garbage(reply, "bad count"); PLONG(NFS_OK); PLONG(4096); /* tsize (fs block size) */ PLONG(Xfersize); /* bsize (optimal transfer size) */ PLONG(Maxfreeblks); /* blocks in fs */ PLONG(Maxfreeblks); /* bfree to root*/ PLONG(Maxfreeblks); /* bavail (free to mortals) */ chat("OK\n"); /*conftime = 0; readunixidmaps(config);*/ return dataptr - (uchar *)reply->results; }
static int nfsrename(int n, Rpccall *cmd, Rpccall *reply) { Xfid *xf, *newxf; Xfile *xp; uchar *fromdir, *todir; String fromelem, toelem; Dir dir; uchar *argptr = cmd->args; uchar *dataptr = reply->results; chat("rename..."); if(n <= FHSIZE) return garbage(reply, "count too small"); xf = rpc2xfid(cmd, 0); fromdir = argptr; argptr += FHSIZE; argptr += string2S(argptr, &fromelem); todir = argptr; argptr += FHSIZE; argptr += string2S(argptr, &toelem); if(argptr != &((uchar *)cmd->args)[n]) return garbage(reply, "bad count"); if(xf == 0) return error(reply, NFSERR_STALE); xp = xf->xp; if(!(xp->qid.type & QTDIR)) return error(reply, NFSERR_NOTDIR); if(memcmp(fromdir, todir, FHSIZE) != 0) return error(reply, NFSERR_NXIO); newxf = xfwalkcr(Twalk, xf, &fromelem, 0); if(newxf == 0) return error(reply, NFSERR_NOENT); if(xfstat(newxf, &dir) < 0) return error(reply, NFSERR_IO); if(xp->parent == xp && toelem.s[0] == '#') return error(reply, NFSERR_PERM); nulldir(&dir); dir.name = toelem.s; if(xfwstat(newxf, &dir) < 0) return error(reply, NFSERR_PERM); PLONG(NFS_OK); chat("OK\n"); return dataptr - (uchar *)reply->results; }
static int mntumntall(int n, Rpccall *cmd, Rpccall *reply) { if(n != 0) return garbage(reply, "mntumntall"); USED(cmd); chat("mntumntall\n"); return 0; }
static int mntdump(int n, Rpccall *cmd, Rpccall *reply) { if(n != 0) return garbage(reply, "mntdump"); USED(cmd); chat("mntdump..."); return error(reply, FALSE); }
static int pcauth(int n, Rpccall *cmd, Rpccall *reply) { uchar *argptr = cmd->args; uchar *dataptr = reply->results; String sys, id, pw, cm; Unixidmap *m; int uid; chat("host=%I, port=%ld: pcauth...", cmd->host, cmd->port); if(n <= 16) return garbage(reply, "count too small"); argptr += string2S(argptr, &sys); argptr += string2S(argptr, &id); argptr += string2S(argptr, &pw); argptr += string2S(argptr, &cm); if(argptr != &((uchar *)cmd->args)[n]) return garbage(reply, "bad count"); scramble(&id); scramble(&pw); m = pair2idmap("pcnfsd", cmd->host); uid = -1; if(m) uid = name2id(&m->u.ids, id.s); if(uid < 0) uid = 1; chat("\"%.*s\",\"%.*s\",\"%.*s\",\"%.*s\"\n", utfnlen(sys.s, sys.n), sys.s, utfnlen(id.s, id.n), id.s, utfnlen(pw.s, pw.n), pw.s, utfnlen(cm.s, cm.n), cm.s); PLONG(0); /* status - OK */ PLONG(uid); PLONG(uid); /* gid */ PLONG(0); /* ngids */ PLONG(sizeof(pc_home)-1); PPTR(pc_home, sizeof(pc_home)-1); PLONG(0); /* umask */ PLONG(sizeof(no_comment)-1); PPTR(no_comment, sizeof(no_comment)-1); return dataptr - (uchar *)reply->results; }
/** @todo probably this can be done in a more clever way. Anyone...? */ string randStr (size_t len) { static const string alpha ("aaaabbccddeeeeffgghiiiijjkkllmmnnooooppqqrrssttuuuuvvwwxxyyyyzz0123456789"); static const size_t MAXAL (alpha.size()); string garbage(len,'\0'); size_t p = len; while (p) garbage[--p] = alpha[rand() % MAXAL]; return garbage; }
int main() { int a = 2323523; int b = 423; mips_print_string("A("); mips_print_int(a); mips_print_string(", "); mips_print_int(b); mips_print_string(") = "); mips_print_int(garbage(a,b)); mips_print_string("\n"); return 0; }
static int nfslookup(int n, Rpccall *cmd, Rpccall *reply) { Xfile *xp; Xfid *xf, *newxf; String elem; Dir dir; uchar *argptr = cmd->args; uchar *dataptr = reply->results; chat("lookup..."); if(n <= FHSIZE) return garbage(reply, "count too small"); xf = rpc2xfid(cmd, 0); argptr += FHSIZE; argptr += string2S(argptr, &elem); if(argptr != &((uchar *)cmd->args)[n]) return garbage(reply, "bad count"); if(xf == 0) return error(reply, NFSERR_STALE); xp = xf->xp; if(!(xp->qid.type & QTDIR)) return error(reply, NFSERR_NOTDIR); chat("%s -> \"%.*s\"...", xp->name, utfnlen(elem.s, elem.n), elem.s); if(xp->s->noauth == 0 && xp->parent == xp && elem.s[0] == '#') newxf = xfauth(xp, &elem); else newxf = xfwalkcr(Twalk, xf, &elem, 0); if(newxf == 0) return error(reply, NFSERR_NOENT); if(xfstat(newxf, &dir) < 0) return error(reply, NFSERR_IO); PLONG(NFS_OK); dataptr += xp2fhandle(newxf->xp, dataptr); dataptr += dir2fattr(cmd->up, &dir, dataptr); chat("OK\n"); return dataptr - (uchar *)reply->results; }
int main() { std::cout << "Proper: " std::endl; std::vector<int> proper( 50 ); for ( unsigned g = 50; g--; ) { std::cout << proper[g] << ", "; } std::cout << std::endl; std::cout << "Garbage: " std::endl; std::vector<int, uninitialized_allocator<int>> garbage( 50 ); for ( unsigned g = 50; g--; ) { std::cout << garbage[g] << ", "; } }
struct blk * morehd(void){ register struct blk *h,*kk; headmor++; nbytes += HEADSZ; hfree = h = (struct blk *)malloc(HEADSZ); if(hfree == 0){ garbage("morehd"); if((hfree = h = (struct blk *)malloc(HEADSZ)) == 0) ospace("headers"); } kk = h; while(h<hfree+(HEADSZ/BLK))(h++)->rd = (char *)++kk; (--h)->rd=0; return(hfree); }
bool Log::WriteFileToLog ( std::string filePath, std::string itemName ) { std::ifstream file; file.open ( filePath.c_str(), std::ios::out ); // create the file if ( !file ) // if we can't create the file { logfile << itemName << ":" << std::endl << "Can't access " << filePath << std::endl << std::endl << std::flush; return false; // failure! } // trim any trailing spaces or ">" from system command piping from the item name std::string garbage ( " >" ); size_t found; found = itemName.find_last_not_of ( garbage ); if ( found != std::string::npos ) { itemName.erase ( found + 1 ); } if ( file.peek() != EOF ) { logfile << itemName // item name << ":" // colon << std::endl << std::endl // linebreaks << file.rdbuf() // file contents << std::endl // linebreak << std::flush; // clear the buffer } else { logfile << itemName // item name << ":" // colon << std::endl << std::endl // linebreaks << std::endl // linebreak << std::flush; // clear the buffer } file.close(); // close the file return true; // success }
static int nfsread(int n, Rpccall *cmd, Rpccall *reply) { Session *s; Xfid *xf; Dir dir; int offset, count; uchar *argptr = cmd->args; uchar *dataptr = reply->results; uchar *readptr = dataptr + 4 + 17*4 + 4; chat("read..."); if(n != FHSIZE+12) return garbage(reply, "bad count"); xf = rpc2xfid(cmd, 0); argptr += FHSIZE; offset = GLONG(); count = GLONG(); if(xf == 0) return error(reply, NFSERR_STALE); chat("%s %d %d...", xf->xp->name, offset, count); if(xf->xp->s != xf->xp->parent->s){ count = xfauthread(xf, offset, readptr, count); }else{ if(xfopen(xf, Oread) < 0) return error(reply, NFSERR_PERM); if(count > 8192) count = 8192; s = xf->xp->s; setfid(s, xf->opfid); xf->opfid->tstale = nfstime + 60; s->f.offset = offset; s->f.count = count; if(xmesg(s, Tread) < 0) return error(reply, NFSERR_IO); count = s->f.count; memmove(readptr, s->f.data, count); } if(xfstat(xf, &dir) < 0) return error(reply, NFSERR_IO); PLONG(NFS_OK); dataptr += dir2fattr(cmd->up, &dir, dataptr); PLONG(count); dataptr += ROUNDUP(count); chat("%d OK\n", count); return dataptr - (uchar *)reply->results; }
static int nfswrite(int n, Rpccall *cmd, Rpccall *reply) { Session *s; Xfid *xf; Dir dir; int offset, count; uchar *argptr = cmd->args; uchar *dataptr = reply->results; chat("write..."); if(n < FHSIZE+16) return garbage(reply, "count too small"); xf = rpc2xfid(cmd, 0); argptr += FHSIZE + 4; offset = GLONG(); argptr += 4; count = GLONG(); if(xf == 0) return error(reply, NFSERR_STALE); chat("%s %d %d...", xf->xp->name, offset, count); if(xf->xp->s != xf->xp->parent->s){ if(xfauthwrite(xf, offset, argptr, count) < 0) return error(reply, NFSERR_IO); }else{ if(xfopen(xf, Owrite) < 0) return error(reply, NFSERR_PERM); s = xf->xp->s; setfid(s, xf->opfid); xf->opfid->tstale = nfstime + 60; s->f.offset = offset; s->f.count = count; s->f.data = (char *)argptr; if(xmesg(s, Twrite) < 0) return error(reply, NFSERR_IO); } if(xfstat(xf, &dir) < 0) return error(reply, NFSERR_IO); PLONG(NFS_OK); dataptr += dir2fattr(cmd->up, &dir, dataptr); chat("OK\n"); return dataptr - (uchar *)reply->results; }
struct blk * salloc(int size) { register struct blk *hdr; register char *ptr; all++; nbytes += size; ptr = malloc((unsigned)(size?size:1)); if(ptr == 0){ garbage("salloc"); if((ptr = malloc((unsigned)(size?size:1))) == 0) ospace("salloc"); } if((hdr = hfree) == 0)hdr = morehd(); hfree = (struct blk *)hdr->rd; hdr->rd = hdr->wt = hdr->beg = ptr; hdr->last = ptr+size; return(hdr); }
static int nfsgetattr(int n, Rpccall *cmd, Rpccall *reply) { Xfid *xf; Dir dir; uchar *dataptr = reply->results; chat("getattr..."); if(n != FHSIZE) return garbage(reply, "bad count"); xf = rpc2xfid(cmd, &dir); if(xf == 0) return error(reply, NFSERR_STALE); chat("%s...", xf->xp->name); PLONG(NFS_OK); dataptr += dir2fattr(cmd->up, &dir, dataptr); chat("OK\n"); return dataptr - (uchar *)reply->results; }
void more(struct blk *hptr) { register unsigned size; register char *p; if((size=(hptr->last-hptr->beg)*2) == 0)size=1; nbytes += size/2; /*free(hptr->beg);*/ p = realloc(hptr->beg, (unsigned)size); if(p == 0){ hptr->beg = realloc(hptr->beg, (unsigned)(hptr->last-hptr->beg)); garbage("more"); if((p = realloc(hptr->beg,size)) == 0) ospace("more"); } hptr->rd = hptr->rd-hptr->beg+p; hptr->wt = hptr->wt-hptr->beg+p; hptr->beg = p; hptr->last = p+size; return; }
int main(int argc, char *argv[]) { struct sigaction sa; char const *errstr; int i; if (argc != 2) return (1); errno = 0; i = strtonum(argv[1], 0, INT_MAX, &errstr); if (i == 0 && errno != 0) { fprintf(stderr, "%s\n", errstr); return (1); } memset(&sa, 0, sizeof sa); sa.sa_handler = &handler; if (sigaction(SIGTERM, &sa, NULL)) err(3, "sigaction"); garbage(); printf("%d\n", sleep(i)); return (0); }
void seekc(struct blk *hptr,int n) { register char *nn,*p; nn = hptr->beg+n; if(nn > hptr->last){ nbytes += nn - hptr->last; /*free(hptr->beg);*/ p = realloc(hptr->beg, (unsigned)n); if(p == 0){ hptr->beg = realloc(hptr->beg, (unsigned)(hptr->last-hptr->beg)); garbage("seekc"); if((p = realloc(hptr->beg, (unsigned)n)) == 0) ospace("seekc"); } hptr->beg = p; hptr->wt = hptr->last = hptr->rd = p+n; return; } hptr->rd = nn; if(nn>hptr->wt)hptr->wt = nn; return; }
Arena::~Arena(){ //calls destructor on each object in vector garbage(); }