/* --------------------------------------------------------------------------- * reallocates memory for a dynamic length string if necessary */ static void DSRealloc (DynamicStringTypePtr Ptr, size_t Length) { int input_null = (Ptr->Data == NULL); if (input_null || Length >= Ptr->MaxLength) { Ptr->MaxLength = Length + 512; Ptr->Data = MyRealloc (Ptr->Data, Ptr->MaxLength, "ReallocDS()"); if (input_null) Ptr->Data[0] = '\0'; } }
static void grow_whowas() { int osize = ww_size; Debug((DEBUG_ERROR, "grow_whowas ww:%d, lk:%d, #%d, %#x/%#x", ww_size, lk_size, numclients, was, locked)); ww_size = (int)((float)numclients * 1.1); was = (aName *)MyRealloc((char *)was, sizeof(*was) * ww_size); bzero((char *)(was + osize), sizeof(*was) * (ww_size - osize)); Debug((DEBUG_ERROR, "grow_whowas %#x", was)); ircd_writetune(tunefile); }
static void LinkStructPointer(void *ptr, struct Level **list) { ++(*list)->numptrs; if (!(*list)->typeptrs) (*list)->typeptrs = (void **) MyMalloc(sizeof(void *)); else (*list)->typeptrs = (void **) MyRealloc((*list)->typeptrs, sizeof(void *) * (*list)->numptrs); (*list)->typeptrs[(*list)->numptrs - 1] = ptr; } /* LinkStructPointer() */
void OpenUtility::CStream::AddVFormatStream(const char *StrFormat,va_list argList) { int RealLen,tailletemp; tailletemp=NbCharFormat(StrFormat,argList); Stream=(char*)MyRealloc(Stream,(taille+tailletemp+1)*sizeof(char)); if ((RealLen=vsprintf(&Stream[taille],StrFormat,argList))>(int)tailletemp) { GetCMyExceptionObj(E,ERR_PRGM); throw(E); } taille+=RealLen; }
void OpenUtility::CStream::VFormat(const char *StrFormat,va_list argList) { int RealLen; taille=NbCharFormat(StrFormat,argList); Stream=(char*)MyRealloc(Stream,(taille+1)*sizeof(char)); if ((RealLen=vsprintf(Stream,StrFormat,argList))>(int)taille) { GetCMyExceptionObj(E,ERR_PRGM); throw(E); } taille=RealLen; }
static void grow_locked() { #ifdef CONSERVATIVE_NDELAY_MALLOC int osize = lk_size; lk_size = ww_size; locked = (aLock *)MyRealloc((char *)locked, sizeof(*locked) * lk_size); bzero((char *)(locked + osize), sizeof(*locked) * (lk_size - osize)); #else if ((lk_size += LOCKMEMORYALLOCATIONSTEP) > MAXLOCKS) { #ifdef REALLOC_IF_MAX_BROKEN /* ** Maximum locks limit broken, then set index to zero ** and reallocate locks memory to minimal value. -kmale */ lk_index = 0; locked = (aLock *)MyRealloc((char *)locked, sizeof(*locked) * MINLOCKS); bzero((char *)(locked), sizeof(*locked) * MINLOCKS); lk_size = MINLOCKS; #else lk_index = 0; #endif } else { /* ** All is ok, reallocating memory -kmale */ locked = (aLock *)MyRealloc((char *)locked, sizeof(*locked) * lk_size); bzero((char *)(locked + lk_size - LOCKMEMORYALLOCATIONSTEP), sizeof(*locked) * LOCKMEMORYALLOCATIONSTEP); } #endif }
void KickBan(int ban, char *source, struct Channel *channel, char *nicks, char *reason) { char *mask, *tempnix, **av, *bans; char temp[MAXLINE]; int ac, ii; struct Luser *lptr; if (!source || !channel || !nicks) return; tempnix = MyStrdup(nicks); ac = SplitBuf(tempnix, &av); if (ban) { bans = (char *) MyMalloc(sizeof(char)); bans[0] = '\0'; for (ii = 0; ii < ac; ii++) { if (!(lptr = FindClient(av[ii]))) continue; mask = HostToMask(lptr->username, lptr->hostname); ircsprintf(temp, "*!%s", mask); bans = (char *) MyRealloc(bans, strlen(bans) + strlen(temp) + (2 * sizeof(char))); strcat(bans, temp); strcat(bans, " "); MyFree(mask); } SetModes(source, 1, 'b', channel, bans); MyFree(bans); } for (ii = 0; ii < ac; ii++) { toserv(":%s REMOVE %s %s :%s\n", source, channel->name, av[ii], reason ? reason : ""); RemoveFromChannel(channel, FindClient(av[ii])); } MyFree(tempnix); MyFree(av); } /* KickBan() */
/* --------------------------------------------------------------------------- * get next slot for an element, allocates memory if necessary */ ElementTypePtr GetElementMemory (DataTypePtr Data) { ElementTypePtr element = Data->Element; int i; /* realloc new memory if necessary and clear it */ if (Data->ElementN >= Data->ElementMax) { Data->ElementMax += STEP_ELEMENT; if (Data->element_tree) r_destroy_tree (&Data->element_tree); element = MyRealloc (element, Data->ElementMax * sizeof (ElementType), "GetElementMemory()"); Data->Element = element; memset (element + Data->ElementN, 0, STEP_ELEMENT * sizeof (ElementType)); Data->element_tree = r_create_tree (NULL, 0, 0); for (i = 0; i < MAX_ELEMENTNAMES; i++) { if (Data->name_tree[i]) r_destroy_tree (&Data->name_tree[i]); Data->name_tree[i] = r_create_tree (NULL, 0, 0); } ELEMENT_LOOP (Data); { r_insert_entry (Data->element_tree, (BoxType *) element, 0); PIN_LOOP (element); { pin->Element = element; } END_LOOP; PAD_LOOP (element); { pad->Element = element; } END_LOOP; ELEMENTTEXT_LOOP (element); { text->Element = element; r_insert_entry (Data->name_tree[n], (BoxType *) text, 0); } END_LOOP; } END_LOOP; } return (element + Data->ElementN++); }
void OpenUtility::CStream::AddFormatStream(const char *StrFormat,...) { va_list marker; int RealLen,tailletemp; va_start(marker,StrFormat); // Initialise la variable arguments tailletemp=NbCharFormat(StrFormat,marker); Stream=(char*)MyRealloc(Stream,(taille+tailletemp+1)*sizeof(char)); if ((RealLen=vsprintf(&Stream[taille],StrFormat,marker))>(int)tailletemp) THROW(Exception,"Implementation problem, contact OpenUtility developpers"); taille+=RealLen; va_end(marker); // Lib�re la variable arguments }
OpenUtility::CBlockStream& OpenUtility::CBlockStream::operator=(const char car) { unsigned int newTailleBlock; if ((newTailleBlock=((1/IncBlock)+1)*IncBlock)!=TailleBlock) { TailleBlock=newTailleBlock; Stream=(char*)MyRealloc(Stream,TailleBlock*sizeof(char)); } Stream[0]=car; Stream[1]='\0'; taille=1; return(*this); }
OpenUtility::CBlockStream& OpenUtility::CBlockStream::operator=(CStream &S) { unsigned int newTailleBlock; if ((newTailleBlock=(((S.GetSize()+1)/IncBlock)+1)*IncBlock)!=TailleBlock) { TailleBlock=newTailleBlock; Stream=(char*)MyRealloc(Stream,TailleBlock*sizeof(char)); } if (S.GetSize()) memcpy(Stream,S.GetStream(),sizeof(char)*S.GetSize()); Stream[S.GetSize()]='\0'; taille=S.GetSize(); return(*this); }
void OpenUtility::CBlockStream::Format(const char *StrFormat,...) { va_list marker; int RealLen; va_start(marker,StrFormat); // Initialise la variable arguments taille=NbCharFormat(StrFormat,marker); TailleBlock=(((taille+1)/IncBlock)+1)*IncBlock; Stream=(char*)MyRealloc(Stream,TailleBlock*sizeof(char)); if ((RealLen=vsprintf(Stream,StrFormat,marker))>(int)taille) THROW(Exception,"Implementation problem, contact OpenUtility developpers"); taille=RealLen; va_end(marker); // Libère la variable arguments }
/* --------------------------------------------------------------------------- * get next slot for a subnet, allocates memory if necessary */ NetTypePtr GetNetMemory (NetListTypePtr Netlist) { NetTypePtr net = Netlist->Net; /* realloc new memory if necessary and clear it */ if (Netlist->NetN >= Netlist->NetMax) { Netlist->NetMax += STEP_POINT; net = MyRealloc (net, Netlist->NetMax * sizeof (NetType), "GetNetMemory()"); Netlist->Net = net; memset (net + Netlist->NetN, 0, STEP_POINT * sizeof (NetType)); } return (net + Netlist->NetN++); }
/* --------------------------------------------------------------------------- * get next slot for a Drill, allocates memory if necessary */ DrillTypePtr GetDrillInfoDrillMemory (DrillInfoTypePtr DrillInfo) { DrillTypePtr drill = DrillInfo->Drill; /* realloc new memory if necessary and clear it */ if (DrillInfo->DrillN >= DrillInfo->DrillMax) { DrillInfo->DrillMax += STEP_DRILL; drill = MyRealloc (drill, DrillInfo->DrillMax * sizeof (DrillType), "GetDrillInfoDrillMemory()"); DrillInfo->Drill = drill; memset (drill + DrillInfo->DrillN, 0, STEP_DRILL * sizeof (DrillType)); } return (drill + DrillInfo->DrillN++); }
/* --------------------------------------------------------------------------- * get next slot for a connection, allocates memory if necessary */ ConnectionTypePtr GetConnectionMemory (NetTypePtr Net) { ConnectionTypePtr con = Net->Connection; /* realloc new memory if necessary and clear it */ if (Net->ConnectionN >= Net->ConnectionMax) { Net->ConnectionMax += STEP_POINT; con = MyRealloc (con, Net->ConnectionMax * sizeof (ConnectionType), "GetConnectionMemory()"); Net->Connection = con; memset (con + Net->ConnectionN, 0, STEP_POINT * sizeof (ConnectionType)); } return (con + Net->ConnectionN++); }
/* --------------------------------------------------------------------------- * get next slot for a library menu, allocates memory if necessary */ LibraryMenuTypePtr GetLibraryMenuMemory (LibraryTypePtr lib) { LibraryMenuTypePtr menu = lib->Menu; /* realloc new memory if necessary and clear it */ if (lib->MenuN >= lib->MenuMax) { lib->MenuMax += STEP_LIBRARYMENU; menu = MyRealloc (menu, lib->MenuMax * sizeof (LibraryMenuType), "GetLibraryMenuMemory()"); lib->Menu = menu; memset (menu + lib->MenuN, 0, STEP_LIBRARYMENU * sizeof (LibraryMenuType)); } return (menu + lib->MenuN++); }
/* --------------------------------------------------------------------------- * gets the next slot for a point in a polygon struct, allocates memory * if necessary */ Cardinal * GetHoleIndexMemoryInPolygon (PolygonTypePtr Polygon) { Cardinal *holeindex = Polygon->HoleIndex; /* realloc new memory if necessary and clear it */ if (Polygon->HoleIndexN >= Polygon->HoleIndexMax) { Polygon->HoleIndexMax += STEP_POLYGONHOLEINDEX; holeindex = MyRealloc (holeindex, Polygon->HoleIndexMax * sizeof (int), "GetHoleIndexMemoryInPolygon()"); Polygon->HoleIndex = holeindex; memset (holeindex + Polygon->HoleIndexN, 0, STEP_POLYGONHOLEINDEX * sizeof (int)); } return (holeindex + Polygon->HoleIndexN++); }
/* --------------------------------------------------------------------------- * gets the next slot for a point in a polygon struct, allocates memory * if necessary */ PointTypePtr GetPointMemoryInPolygon (PolygonTypePtr Polygon) { PointTypePtr points = Polygon->Points; /* realloc new memory if necessary and clear it */ if (Polygon->PointN >= Polygon->PointMax) { Polygon->PointMax += STEP_POLYGONPOINT; points = MyRealloc (points, Polygon->PointMax * sizeof (PointType), "GetPointMemoryInPolygon()"); Polygon->Points = points; memset (points + Polygon->PointN, 0, STEP_POLYGONPOINT * sizeof (PointType)); } return (points + Polygon->PointN++); }
/* --------------------------------------------------------------------------- * get next slot for a box, allocates memory if necessary */ BoxTypePtr GetBoxMemory (BoxListTypePtr Boxes) { BoxTypePtr box = Boxes->Box; /* realloc new memory if necessary and clear it */ if (Boxes->BoxN >= Boxes->BoxMax) { Boxes->BoxMax = STEP_POINT + (2 * Boxes->BoxMax); box = MyRealloc (box, Boxes->BoxMax * sizeof (BoxType), "GetBoxMemory()"); Boxes->Box = box; memset (box + Boxes->BoxN, 0, (Boxes->BoxMax - Boxes->BoxN) * sizeof (BoxType)); } return (box + Boxes->BoxN++); }
/* --------------------------------------------------------------------------- * get next slot for a library entry, allocates memory if necessary */ LibraryEntryTypePtr GetLibraryEntryMemory (LibraryMenuTypePtr Menu) { LibraryEntryTypePtr entry = Menu->Entry; /* realloc new memory if necessary and clear it */ if (Menu->EntryN >= Menu->EntryMax) { Menu->EntryMax += STEP_LIBRARYENTRY; entry = MyRealloc (entry, Menu->EntryMax * sizeof (LibraryEntryType), "GetLibraryEntryMemory()"); Menu->Entry = entry; memset (entry + Menu->EntryN, 0, STEP_LIBRARYENTRY * sizeof (LibraryEntryType)); } return (entry + Menu->EntryN++); }
OpenUtility::CBlockStream& OpenUtility::CBlockStream::operator=(const char* buffer) { int i=(int)strlen(buffer); unsigned int newTailleBlock; if ((newTailleBlock=(((i+1)/IncBlock)+1)*IncBlock)!=TailleBlock) { TailleBlock=newTailleBlock; Stream=(char*)MyRealloc(Stream,TailleBlock*sizeof(char)); } if (i) memcpy(Stream,buffer,sizeof(char)*i); Stream[i]='\0'; taille=i; return(*this); }
/************************************************************************** * RetreiveFileSecurity [SETUPAPI.@] * * Retrieve the security descriptor that is associated with the given file. * * PARAMS * lpFileName [I] Name of the file * * RETURNS * Success: ERROR_SUCCESS * Failure: other */ DWORD WINAPI RetreiveFileSecurity(LPCWSTR lpFileName, PSECURITY_DESCRIPTOR *pSecurityDescriptor) { PSECURITY_DESCRIPTOR SecDesc; DWORD dwSize = 0x100; DWORD dwError; TRACE("%s %p\n", debugstr_w(lpFileName), pSecurityDescriptor); SecDesc = MyMalloc(dwSize); if (SecDesc == NULL) return ERROR_NOT_ENOUGH_MEMORY; if (GetFileSecurityW(lpFileName, OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, SecDesc, dwSize, &dwSize)) { *pSecurityDescriptor = SecDesc; return ERROR_SUCCESS; } dwError = GetLastError(); if (dwError != ERROR_INSUFFICIENT_BUFFER) { MyFree(SecDesc); return dwError; } SecDesc = MyRealloc(SecDesc, dwSize); if (SecDesc == NULL) return ERROR_NOT_ENOUGH_MEMORY; if (GetFileSecurityW(lpFileName, OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, SecDesc, dwSize, &dwSize)) { *pSecurityDescriptor = SecDesc; return ERROR_SUCCESS; } dwError = GetLastError(); MyFree(SecDesc); return dwError; }
/* --------------------------------------------------------------------------- * get next slot for a DrillPoint, allocates memory if necessary */ PinTypeHandle GetDrillPinMemory (DrillTypePtr Drill) { PinTypePtr *pin; pin = Drill->Pin; /* realloc new memory if necessary and clear it */ if (Drill->PinN >= Drill->PinMax) { Drill->PinMax += STEP_POINT; pin = MyRealloc (pin, Drill->PinMax * sizeof (PinTypeHandle), "GetDrillPinMemory()"); Drill->Pin = pin; memset (pin + Drill->PinN, 0, STEP_POINT * sizeof (PinTypeHandle)); } return (pin + Drill->PinN++); }
void OpenUtility::CStream::AddFormatStream(const char *StrFormat,...) { va_list marker; int RealLen,tailletemp; va_start(marker,StrFormat); // Initialise la variable arguments tailletemp=NbCharFormat(StrFormat,marker); Stream=(char*)MyRealloc(Stream,(taille+tailletemp+1)*sizeof(char)); if ((RealLen=vsprintf(&Stream[taille],StrFormat,marker))>(int)tailletemp) { GetCMyExceptionObj(E,ERR_PRGM); throw(E); } taille+=RealLen; va_end(marker); // Lib�re la variable arguments }
/* --------------------------------------------------------------------------- * get next slot for a rubberband connection, allocates memory if necessary */ RubberbandTypePtr GetRubberbandMemory (void) { RubberbandTypePtr ptr = Crosshair.AttachedObject.Rubberband; /* realloc new memory if necessary and clear it */ if (Crosshair.AttachedObject.RubberbandN >= Crosshair.AttachedObject.RubberbandMax) { Crosshair.AttachedObject.RubberbandMax += STEP_RUBBERBAND; ptr = MyRealloc (ptr, Crosshair.AttachedObject.RubberbandMax * sizeof (RubberbandType), "GetRubberbandMemory()"); Crosshair.AttachedObject.Rubberband = ptr; memset (ptr + Crosshair.AttachedObject.RubberbandN, 0, STEP_RUBBERBAND * sizeof (RubberbandType)); } return (ptr + Crosshair.AttachedObject.RubberbandN++); }
/* --------------------------------------------------------------------------- * get next slot for a DrillElement, allocates memory if necessary */ ElementTypeHandle GetDrillElementMemory (DrillTypePtr Drill) { ElementTypePtr *element; element = Drill->Element; /* realloc new memory if necessary and clear it */ if (Drill->ElementN >= Drill->ElementMax) { Drill->ElementMax += STEP_ELEMENT; element = MyRealloc (element, Drill->ElementMax * sizeof (ElementTypeHandle), "GetDrillElementMemory()"); Drill->Element = element; memset (element + Drill->ElementN, 0, STEP_ELEMENT * sizeof (ElementTypeHandle)); } return (element + Drill->ElementN++); }
LPTSTR ids( UINT idString) { static LPTSTR apsz[CSTRINGS]; // String resource array cache. LPTSTR psz; INT cch; if (apsz[idString]) return apsz[idString]; if (!(psz = MyAlloc(CCHTEXTMAX * sizeof(TCHAR)))) return szEmpty; if (!(cch = LoadString(ghInst, idString, psz, CCHTEXTMAX))) { MyFree(psz); return szEmpty; } apsz[idString] = psz = MyRealloc(psz, (cch + 1) * sizeof(TCHAR)); return (psz ? psz : szEmpty); }
PSTR ids( UINT idString) { static PSTR apstr[CSTRINGS]; // String resource array cache. PSTR pstr; INT cch; if (apstr[idString]) return apstr[idString]; if (!(pstr = MyAlloc(CCHTEXTMAX))) return ""; if (!(cch = LoadString(ghInst, idString, pstr, CCHTEXTMAX))) { MyFree(pstr); return ""; } apstr[idString] = pstr = MyRealloc(pstr, cch + 1); return (pstr ? pstr : ""); }
int OpenUtility::CBlockStream::ReplaceOne(char *StrFind,char *StrReplace,unsigned int pos) { int i,j,k,l; unsigned int SauvTailleBlock,SauvTaille; if ((i=FindString(StrFind,pos))!=-1) { j=(int)strlen(StrFind); k=(int)strlen(StrReplace); if (j!=k) { SauvTaille=taille; taille+=k-j; SauvTailleBlock=TailleBlock; TailleBlock=(((taille+1)/IncBlock)+1)*IncBlock; if (SauvTailleBlock!=TailleBlock) Stream=(char*)MyRealloc(Stream,TailleBlock*sizeof(char)); memmove(&Stream[i+k],&Stream[i+j],SauvTaille-i-j+1); } for(l=0;l<k;l++) Stream[i+l]=StrReplace[l]; } return(i); }
static int BreakupHost(char *hostname, char ***array) { int argnum = 4; /* initial number of slots in our array */ int pieces; /* number of "pieces" in hostname */ char *tmp, *founddot; *array = (char **) MyMalloc(sizeof(char *) * argnum); pieces = 0; tmp = hostname; while (*tmp) { if (pieces == argnum) { /* * We've filled up all the slots allocated so far, * allocate some more */ argnum += 4; *array = (char **) MyRealloc(*array, sizeof(char *) * argnum); } founddot = strstr(tmp, "."); if (founddot) *founddot++ = '\0'; else founddot = tmp + strlen(tmp); (*array)[pieces++] = tmp; tmp = founddot; } return (pieces); } /* BreakupHost() */