DWORD TinyMemoryFile::Write(const void* pData, DWORD cbData) { if (pData == NULL || cbData == 0) return FALSE; if ((m_dwPosition + cbData) < m_dwPosition) return FALSE; //超出当前缓冲区大小重新分配大小 if ((m_dwPosition + cbData) > m_dwBufferSize) { if (!Realloc((m_dwPosition + cbData))) return FALSE; } memcpy_s((BYTE*)pData + m_dwPosition, cbData, (BYTE*)pData, cbData); m_dwPosition += cbData; if (m_dwPosition > m_dwBufferSize) m_dwBufferSize = m_dwPosition; return cbData; }
int ipstr_list_parse(const char* ipstr_list, struct in_addr** ip_list) { int count; for (ip_list=NULL, count=0; ipstr_list; count++) { struct in_addr a; if (inet_aton(ipstr_list, &a) == -1) break; *ip_list = Realloc(*ip_list, (count+1) * sizeof(struct in_addr)); if (!ip_list) { return -1; } (*ip_list)[count] = a; ipstr_list = strchr(ipstr_list, ':'); if (ipstr_list) ipstr_list++; } return count; }
BOOL prs_set_buffer_size(prs_struct *ps, uint32 newsize) { if (newsize > ps->buffer_size) return prs_force_grow(ps, newsize - ps->buffer_size); if (newsize < ps->buffer_size) { char *new_data_p = Realloc(ps->data_p, newsize); /* if newsize is zero, Realloc acts like free() & returns NULL*/ if (new_data_p == NULL && newsize != 0) { DEBUG(0,("prs_set_buffer_size: Realloc failure for size %u.\n", (unsigned int)newsize)); DEBUG(0,("prs_set_buffer_size: Reason %s\n",strerror(errno))); return False; } ps->data_p = new_data_p; ps->buffer_size = newsize; } return True; }
int MemoryBuffer::Load(const void *buf, __MEMBUF_INT__ bytes) // Load this object with a unique copy of the specified buffer. // Returns true if successful or false if an error occurs. { if(!mptr) { // Ensure that this buffer has been initialized if(!Alloc(bytes)) return 0; } if(d_length < bytes) { // Ensure enough byte have been allocated if(!Realloc(bytes, 0, 0)) return 0; } else { // Reuse the current memory segment l_length = bytes; } // PC-lint 09/14/2005: Possible use of null pointer if(!mptr) return 0; memmove(mptr, (unsigned char *)buf, l_length); return 1; }
TString::TString( const char* c, unsigned int len ) { data = NULL; if( len==0 ) { data = NULL; length = 0; } else { Realloc( len ); if( c ) { char *copied = (char*) memccpy( data, c, 0, len ); if( copied ) { copied--; memset( copied, ' ', len - ( copied - data ) ); } } else memset( data, ' ', len ); data[len] = 0; } }
int CLightmapManager::Load (int nLevel) { CFile cf; tLightmapDataHeader ldh; int i, bOk; char szFilename [FILENAME_LEN]; CSegFace *faceP; if (!(gameStates.app.bCacheLightmaps)) return 0; if (!cf.Open (Filename (szFilename, nLevel), gameFolders.szCacheDir, "rb", 0)) return 0; bOk = (cf.Read (&ldh, sizeof (ldh), 1) == 1); if (bOk) bOk = (ldh.nVersion == LIGHTMAP_DATA_VERSION) && (ldh.nCheckSum == CalcSegmentCheckSum ()) && (ldh.nSegments == gameData.segs.nSegments) && (ldh.nVertices == gameData.segs.nVertices) && (ldh.nFaces == gameData.segs.nFaces) && (ldh.nLights == m_list.nLights) && (ldh.nMaxLightRange == MAX_LIGHT_RANGE); if (bOk) { for (i = ldh.nFaces, faceP = FACES.faces.Buffer (); i; i--, faceP++) { bOk = cf.Read (&faceP->nLightmap, sizeof (faceP->nLightmap), 1) == 1; if (!bOk) break; } } if (bOk) { for (i = 0; i < ldh.nBuffers; i++) { bOk = cf.Read (m_list.buffers [i].bmP, sizeof (m_list.buffers [i].bmP), 1) == 1; if (!bOk) break; } } if (bOk) Realloc (ldh.nBuffers); cf.Close (); return bOk; }
SEC_ACL *build_acl(struct ace_entry *ace_list) { SEC_ACE *aces = NULL; SEC_ACL *result; int num_aces = 0; if (ace_list == NULL) return NULL; /* Create aces */ while(ace_list->sid) { SEC_ACCESS sa; struct dom_sid sid; /* Create memory for new ACE */ if (!(aces = Realloc(aces, sizeof(SEC_ACE) * (num_aces + 1)))) { return NULL; } /* Create ace */ init_sec_access(&sa, ace_list->mask); char_to_sid(&sid, ace_list->sid); init_sec_ace(&aces[num_aces], &sid, ace_list->type, sa, ace_list->flags); num_aces++; ace_list++; } /* Create ACL from list of ACEs */ result = make_sec_acl(ACL_REVISION, num_aces, aces); free(aces); return result; }
void add_zone(zonetbl_t *tbl, char *str) { zonename_t *entp; zoneid_t id; char *cp; /* * str should be either the name of a configured zone, or the * id of a running zone. If str is a zone name, store the name * in the table; otherwise, just store the id. */ if (zone_get_id(str, &id) != 0) { Die(gettext("unknown zone -- %s\n"), str); /*NOTREACHED*/ } /* was zone specified by name or id? */ errno = 0; if (id == (zoneid_t)strtol(str, &cp, 0) && errno == 0 && cp != str && *cp == '\0') { /* found it by id, don't store the name */ str = NULL; } if (tbl->z_size == tbl->z_nent) { /* reallocation */ if ((tbl->z_size *= 2) == 0) tbl->z_size = 4; /* first time */ tbl->z_list = Realloc(tbl->z_list, tbl->z_size * sizeof (zonename_t)); } entp = &tbl->z_list[tbl->z_nent++]; if (str) (void) strlcpy(entp->z_name, str, ZONENAME_MAX); else entp->z_name[0] = '\0'; entp->z_id = id; }
// Adds an empty row at the end of the value buffer. The row will be // marked invalid until the first value is set in the row. This will // re-allocate the existing value buffer. If you know beforehand how // many rows will exist in the table it is more efficient to use // one SetNumRows(N) instead of N times AddRow()! The method returns // the index of the newly added row. The row will be filled with // the row attribute's default values. int CValueTable::AddRow() { if (NumRows >= AllocatedRows) { int NewNumRows = AllocatedRows + AllocatedRows; if (NewNumRows == 0) NewNumRows = 10; Realloc(RowPitch, NewNumRows); } if (Flags.Is(_TrackModifications)) { if (FirstNewRowIndex > NumRows) FirstNewRowIndex = NumRows; RowStateBuffer[NumRows] |= NewRow; ++NewRowsCount; Flags.Set(_IsModified); } //UserData.Append(NULL); SetRowToDefaultValues(NumRows++); // Copy to stack, then increment, then call. Intended, don't change. return NumRows - 1; }
static void msgput(msginfo *m, const char *b, int n) { char *msg, *msg0, *msgend; const char *be; ftnlen msglen0; msg = m->msg; msgend = m->msgend; be = b + n; while(b < be) { if (msg >= msgend) { msglen0 = m->msglen; msg0 = m->msg0 = (char*) Realloc(m->msg0, m->msglen += MSGGULP); msg = msg0 + msglen0; m->msgend = msg0 + m->msglen; } *msg++ = *b++; } m->msg = msg; }
void ERR_add_error_data(int num, ...) { va_list args; int i,n,s; char *str,*p,*a; s=64; str=Malloc(s+1); if (str == NULL) return; str[0]='\0'; va_start(args, num); n=0; for (i=0; i<num; i++) { a=va_arg(args, char*); /* ignore NULLs, thanks to Bob Beck <*****@*****.**> */ if (a != NULL) { n+=strlen(a); if (n > s) { s=n+20; p=Realloc(str,s+1); if (p == NULL) { Free(str); return; } else str=p; } strcat(str,a); } } ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING); va_end(args); }
/* * Move internal buffer content to common buffer: */ static size_t _log_cat_ibuf( LogInfo log, const char *buf, size_t size ) { size_t blen = strlen( buf ); if( blen ) { if( size + blen >= log->ibuf_size ) { char *ptr = Realloc( log->ibuf, ( ( size + blen ) * 2 ) + 1 ); if( !ptr ) { return 0; } log->ibuf = ptr; log->ibuf_size = ( size + blen ) * 2; } memcpy( log->ibuf + size, buf, blen ); size += blen - 1; } return size; }
void add_session_user(const char *user) { fstring suser; struct passwd *passwd; if (!(passwd = Get_Pwnam(user))) return; fstrcpy(suser,passwd->pw_name); if(!*suser) return; if( session_userlist && in_list(suser,session_userlist,False) ) return; if( !session_userlist || (strlen(suser) + strlen(session_userlist) + 2 >= len_session_userlist) ) { char *newlist; if (len_session_userlist > 128 * PSTRING_LEN) { DEBUG(3,("add_session_user: session userlist already too large.\n")); return; } newlist = Realloc( session_userlist, len_session_userlist + PSTRING_LEN ); if( newlist == NULL ) { DEBUG(1,("Unable to resize session_userlist\n")); return; } if (!session_userlist) { *newlist = '\0'; } session_userlist = newlist; len_session_userlist += PSTRING_LEN; } safe_strcat(session_userlist," ",len_session_userlist-1); safe_strcat(session_userlist,suser,len_session_userlist-1); }
/***************************************************** set a variable in the shared area *******************************************************/ void smbw_setshared(const char *name, const char *val) { int l1, l2; char *var; /* we don't allow variable overwrite */ if (smbw_getshared(name)) return; lockit(); l1 = strlen(name)+1; l2 = strlen(val)+1; var = (char *)Realloc(variables, shared_size + l1+l2+4, True); if (!var) { DEBUG(0,("out of memory in smbw_setshared\n")); exit(1); } variables = var; SSVAL(&variables[shared_size], 0, l1); SSVAL(&variables[shared_size], 2, l2); safe_strcpy(&variables[shared_size] + 4, name, l1-1); safe_strcpy(&variables[shared_size] + 4 + l1, val, l2-1); shared_size += l1+l2+4; lseek(shared_fd, 0, SEEK_SET); if (write(shared_fd, variables, shared_size) != shared_size) { DEBUG(0,("smbw_setshared failed (%s)\n", strerror(errno))); exit(1); } unlockit(); }
/************************************************************************* Routine to return the next entry in the smbdomainalias list. *************************************************************************/ BOOL add_domain_alias(LOCAL_GRP **alss, int *num_alss, LOCAL_GRP *als) { if (alss == NULL || num_alss == NULL || als == NULL) { return False; } (*alss) = Realloc((*alss), ((*num_alss)+1) * sizeof(LOCAL_GRP)); if ((*alss) == NULL) { return False; } DEBUG(10,("adding alias %s(%s)\n", als->name, als->comment)); fstrcpy((*alss)[(*num_alss)].name , als->name); fstrcpy((*alss)[(*num_alss)].comment, als->comment); (*alss)[(*num_alss)].rid = als->rid; (*num_alss)++; return True; }
int sk_insert(STACK *st, char *data, int loc) { char **s; if(st == NULL) return 0; if (st->num_alloc <= st->num+1) { s=(char **)Realloc((char *)st->data, (unsigned int)sizeof(char *)*st->num_alloc*2); if (s == NULL) return(0); st->data=s; st->num_alloc*=2; } if ((loc >= (int)st->num) || (loc < 0)) st->data[st->num]=data; else { int i; char **f,**t; f=(char **)st->data; t=(char **)&(st->data[1]); for (i=st->num; i>=loc; i--) t[i]=f[i]; #ifdef undef /* no memmove on sunos :-( */ memmove( (char *)&(st->data[loc+1]), (char *)&(st->data[loc]), sizeof(char *)*(st->num-loc)); #endif st->data[loc]=data; } st->num++; st->sorted=0; return(st->num); }
// Parameters are taken from EV_SET (see kevent(2)) static int enqueue_kqueue_change(poller *p,uintptr_t ident,short filter,u_short flags, u_int fflags,intptr_t data,void *udata){ // This unlikely event could occur if, for instance, every fd is being // used, and on the last sysdep_poll() every one had event changes, // and then a verdict was injected while the poller was blocked.... or // (far more likely) in the case of programming error, heheh if(p->kchanges >= p->csize){ typeof(p->csize) tmpcsize = p->csize * 2; typeof(*p->cv) *tmpcv; // If we've not yet been initialized, or reset, don't start // growing buffers...that's a serious problem. Should this be // changed, insert a p->csize check around the Kevent() failure // case involving vector dump and reuse of implied first slot! if(p->csize == 0){ bitch("Used with uninitialized poller\n"); return -1; } if((tmpcv = Realloc("kchange vector",p->cv,sizeof(*tmpcv) * tmpcsize)) == NULL){ // If the realloc failed, dump the current vector... if(Kevent(p->kq,p->cv,p->kchanges,NULL,0,NULL)){ inc_stateexceptions(); return -1; } // Reinitialize the buffer. We're assured that there's // room for at least one of us now by p->csize check p->kchanges = 0; }else{ p->cv = tmpcv; p->csize = tmpcsize; } } EV_SET(&p->cv[p->kchanges++],ident,filter,flags,fflags,data,udata); return 0; }
/* list the rights for an account. This involves traversing the database */ NTSTATUS privilege_enum_account_rights(DOM_SID *sid, uint32 *count, char ***rights) { TDB_DATA key, nextkey; char *right; if (!tdb) { return NT_STATUS_INTERNAL_ERROR; } *rights = NULL; *count = 0; for (key = tdb_firstkey(tdb); key.dptr; key = nextkey) { nextkey = tdb_nextkey(tdb, key); right = key.dptr; if (privilege_sid_has_right(sid, right)) { (*rights) = (char **)Realloc(*rights,sizeof(char *) * ((*count)+1)); if (! *rights) { safe_free(nextkey.dptr); free(key.dptr); return NT_STATUS_NO_MEMORY; } (*rights)[*count] = strdup(right); (*count)++; } free(key.dptr); } return NT_STATUS_OK; }
BOOL prs_force_grow(prs_struct *ps, uint32 extra_space) { uint32 new_size = ps->buffer_size + extra_space; char *new_data; if(!UNMARSHALLING(ps) || !ps->is_dynamic) { DEBUG(0,("prs_force_grow: Buffer overflow - unable to expand buffer by %u bytes.\n", (unsigned int)extra_space)); return False; } if((new_data = Realloc(ps->data_p, new_size)) == NULL) { DEBUG(0,("prs_force_grow: Realloc failure for size %u.\n", (unsigned int)new_size)); return False; } memset(&new_data[ps->buffer_size], '\0', (size_t)(new_size - ps->buffer_size)); ps->buffer_size = new_size; ps->data_p = new_data; return True; }
void sTextControl::Engine(sInt pos,sInt count,sChar *insert) { sInt len; sInt i; if(Static) return; Post(DoneCmd); Changed = 1; len = sGetStringLen(Text); if(insert) { Realloc(len+count+1); for(i=len;i>=pos;i--) Text[i+count] = Text[i]; sCopyMem(Text+pos,insert,count); } else { if(pos+count<=len) sCopyMem(Text+pos,Text+pos+count,len-pos-count+1); } }
void nproc(void) { Symtab *sym; Word *w; if(sym = symlook("NPROC", S_VAR, 0)) { w = (Word *) sym->value; if (w && w->s && w->s[0]) nproclimit = atoi(w->s); } if(nproclimit < 1) nproclimit = 1; if(DEBUG(D_EXEC)) printf("nprocs = %d\n", nproclimit); if(nproclimit > nevents){ if(nevents) events = (Event *)Realloc((char *)events, nproclimit*sizeof(Event)); else events = (Event *)Malloc(nproclimit*sizeof(Event)); while(nevents < nproclimit) events[nevents++].pid = 0; } }
auto_sz::auto_sz(const STRRET& sr, LPCITEMIDLIST piid) : m_sz(NULL) , m_bDelete(false) , m_nSize(0) { switch (sr.uType) { case STRRET_CSTR: { size_t len = lstrlenA(sr.cStr)+1; Realloc(len); MultiByteToWideChar(CP_ACP, 0, sr.cStr, -1, *this, (int)len); } break; case STRRET_WSTR: operator=(sr.pOleStr); break; case STRRET_OFFSET: operator=((LPCWSTR)(&piid->mkid)+sr.uOffset); break; default: assert(0); } }
void * AfxGlImage::SetFormat(GLsizei width, GLsizei height, GLenum format, GLenum type) { unsigned char numComponents; if (!_CalcNumComponents(format, &numComponents)) return 0; unsigned char sizeComponent; bool componentSigned; if (!_CalcSizeComponent(type, &sizeComponent, &componentSigned)) return 0; size_t pixelSize = (size_t)numComponents * (size_t)sizeComponent; size_t rowSize = width * pixelSize; // assuming GL_PIXEL_ALIGNMENT == 4: if (rowSize & 0x03) // is not divideable by 4 (has remainder) rowSize = (1+ (rowSize >> 2))<<2; // fill up to 4 size_t imageSize = height * rowSize; void * newMemory = Realloc(imageSize); if(!newMemory) return 0; m_Format = format; m_Height = height; m_Pitch = rowSize; m_Type = type; m_Width = width; return newMemory; }
//--------------------------------------------------------------------------- tjs_uint TJS_INTF_METHOD tTVPMemoryStream::Write(const void *buffer, tjs_uint write_size) { // writing may increase the internal buffer size. if(Reference) TVPThrowExceptionMessage(TVPWriteError); tjs_uint newpos = CurrentPos + write_size; if(newpos >= AllocSize) { // exceeds AllocSize tjs_uint onesize; if(AllocSize < 64*1024) onesize = 4*1024; else if(AllocSize < 512*1024) onesize = 16*1024; else if(AllocSize < 4096*1024) onesize = 256*1024; else onesize = 2024*1024; AllocSize += onesize; if(CurrentPos + write_size >= AllocSize) // still insufficient ? { AllocSize = CurrentPos + write_size; } Block = Realloc(Block, AllocSize); if(AllocSize && !Block) TVPThrowExceptionMessage(TVPInsufficientMemory); // this exception cannot be repaird; a fatal error. } memcpy((tjs_uint8*)Block + CurrentPos, buffer, write_size); CurrentPos = newpos; if(CurrentPos > Size) Size = CurrentPos; return write_size; }
/* * make_message -- allocate a sufficiently large string and print into it. * * Inputs: * * Format and variable number of arguments. * * Outputs: * * Pointer to the string, * * The code for this function is from the Debian Linux "woody" sprintf man * page. Modified slightly to use wrapper functions for malloc and realloc. */ char * make_message(const char *fmt, ...) { int n; /* Guess we need no more than 100 bytes. */ size_t size = 100; char *p; va_list ap; p = Malloc (size); while (1) { /* Try to print in the allocated space. */ va_start(ap, fmt); n = vsnprintf (p, size, fmt, ap); va_end(ap); /* If that worked, return the string. */ if (n > -1 && n < (int) size) return p; /* Else try again with more space. */ if (n > -1) /* glibc 2.1 */ size = n+1; /* precisely what is needed */ else /* glibc 2.0 */ size *= 2; /* twice the old size */ p = Realloc (p, size); } }
static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(char *, char *), int c ) /* ------------------------------------------------------------------------ ** * Scan a parameter name and value, and pass these two fields to pfunc(). * * Input: InFile - The input source. * pfunc - A pointer to the function that will be called to * process the parameter, once it has been scanned. * c - The first character of the parameter name, which * would have been read by Parse(). Unlike a comment * line or a section header, there is no lead-in * character that can be discarded. * * Output: True if the parameter name and value were scanned and processed * successfully, else False. * * Notes: This function is in two parts. The first loop scans the * parameter name. Internal whitespace is compressed, and an * equal sign (=) terminates the token. Leading and trailing * whitespace is discarded. The second loop scans the parameter * value. When both have been successfully identified, they are * passed to pfunc() for processing. * * ------------------------------------------------------------------------ ** */ { int i = 0; /* Position within bufr. */ int end = 0; /* bufr[end] is current end-of-string. */ int vstart = 0; /* Starting position of the parameter value. */ char *func = "params.c:Parameter() -"; /* Read the parameter name. */ while( 0 == vstart ) /* Loop until we've found the start of the value. */ { if( i > (bSize - 2) ) /* Ensure there's space for next char. */ { bSize += BUFR_INC; bufr = Realloc( bufr, bSize ); if( NULL == bufr ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return( False ); } } switch( c ) { case '=': /* Equal sign marks end of param name. */ if( 0 == end ) /* Don't allow an empty name. */ { DEBUG(0, ("%s Invalid parameter name in config. file.\n", func )); return( False ); } bufr[end++] = '\0'; /* Mark end of string & advance. */ i = end; /* New string starts here. */ vstart = end; /* New string is parameter value. */ bufr[i] = '\0'; /* New string is nul, for now. */ break; case '\n': /* Find continuation char, else error. */ i = Continuation( bufr, i ); if( i < 0 ) { bufr[end] = '\0'; DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n", func, bufr )); return( True ); } end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); c = mygetc( InFile ); /* Read past eoln. */ break; case '\0': /* Shouldn't have EOF within param name. */ case EOF: bufr[i] = '\0'; DEBUG(1,("%s Unexpected end-of-file at: %s\n", func, bufr )); return( True ); default: if( isspace( c ) ) /* One ' ' per whitespace region. */ { bufr[end] = ' '; i = end + 1; c = EatWhitespace( InFile ); } else /* All others verbatim. */ { bufr[i++] = c; end = i; c = mygetc( InFile ); } } } /* Now parse the value. */ c = EatWhitespace( InFile ); /* Again, trim leading whitespace. */ while( (EOF !=c) && (c > 0) ) { if( i > (bSize - 2) ) /* Make sure there's enough room. */ { bSize += BUFR_INC; bufr = Realloc( bufr, bSize ); if( NULL == bufr ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return( False ); } } switch( c ) { case '\r': /* Explicitly remove '\r' because the older */ c = mygetc( InFile ); /* version called fgets_slash() which also */ break; /* removes them. */ case '\n': /* Marks end of value unless there's a '\'. */ i = Continuation( bufr, i ); if( i < 0 ) c = 0; else { for( end = i; (end >= 0) && isspace(bufr[end]); end-- ) ; c = mygetc( InFile ); } break; default: /* All others verbatim. Note that spaces do */ bufr[i++] = c; /* not advance <end>. This allows trimming */ if( !isspace( c ) ) /* of whitespace at the end of the line. */ end = i; c = mygetc( InFile ); break; } } bufr[end] = '\0'; /* End of value. */ return( pfunc( bufr, &bufr[vstart] ) ); /* Pass name & value to pfunc(). */ } /* Parameter */
static BOOL Section( myFILE *InFile, BOOL (*sfunc)(char *) ) /* ------------------------------------------------------------------------ ** * Scan a section name, and pass the name to function sfunc(). * * Input: InFile - Input source. * sfunc - Pointer to the function to be called if the section * name is successfully read. * * Output: True if the section name was read and True was returned from * <sfunc>. False if <sfunc> failed or if a lexical error was * encountered. * * ------------------------------------------------------------------------ ** */ { int c; int i; int end; char *func = "params.c:Section() -"; i = 0; /* <i> is the offset of the next free byte in bufr[] and */ end = 0; /* <end> is the current "end of string" offset. In most */ /* cases these will be the same, but if the last */ /* character written to bufr[] is a space, then <end> */ /* will be one less than <i>. */ c = EatWhitespace( InFile ); /* We've already got the '['. Scan */ /* past initial white space. */ while( (EOF != c) && (c > 0) ) { /* Check that the buffer is big enough for the next character. */ if( i > (bSize - 2) ) { bSize += BUFR_INC; bufr = Realloc( bufr, bSize ); if( NULL == bufr ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return( False ); } } /* Handle a single character. */ switch( c ) { case ']': /* Found the closing bracket. */ bufr[end] = '\0'; if( 0 == end ) /* Don't allow an empty name. */ { DEBUG(0, ("%s Empty section name in configuration file.\n", func )); return( False ); } if( !sfunc( bufr ) ) /* Got a valid name. Deal with it. */ return( False ); (void)EatComment( InFile ); /* Finish off the line. */ return( True ); case '\n': /* Got newline before closing ']'. */ i = Continuation( bufr, i ); /* Check for line continuation. */ if( i < 0 ) { bufr[end] = '\0'; DEBUG(0, ("%s Badly formed line in configuration file: %s\n", func, bufr )); return( False ); } end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); c = mygetc( InFile ); /* Continue with next line. */ break; default: /* All else are a valid name chars. */ if( isspace( c ) ) /* One space per whitespace region. */ { bufr[end] = ' '; i = end + 1; c = EatWhitespace( InFile ); } else /* All others copy verbatim. */ { bufr[i++] = c; end = i; c = mygetc( InFile ); } } } /* We arrive here if we've met the EOF before the closing bracket. */ DEBUG(0, ("%s Unexpected EOF in the configuration file: %s\n", func, bufr )); return( False ); } /* Section */
/**************************************************************************** get a printer queue ****************************************************************************/ int get_printqueue(int snum,int cnum,print_queue_struct **queue, print_status_struct *status) { char *lpq_command = lp_lpqcommand(snum); char *printername = PRINTERNAME(snum); int ret=0,count=0; pstring syscmd; fstring outfile; pstring line; FILE *f; struct stat sbuf; BOOL dorun=True; int cachetime = lp_lpqcachetime(); *line = 0; check_lpq_cache(snum); if (!printername || !*printername) { DEBUG(6,("xx replacing printer name with service (snum=(%s,%d))\n", lp_servicename(snum),snum)); printername = lp_servicename(snum); } if (!lpq_command || !(*lpq_command)) { DEBUG(5,("No lpq command\n")); return(0); } pstrcpy(syscmd,lpq_command); string_sub(syscmd,"%p",printername); standard_sub(cnum,syscmd); slprintf(outfile,sizeof(outfile)-1, "%s/lpq.%08x",tmpdir(),str_checksum(syscmd)); if (!lpq_cache_reset[snum] && cachetime && !stat(outfile,&sbuf)) { if (time(NULL) - sbuf.st_mtime < cachetime) { DEBUG(3,("Using cached lpq output\n")); dorun = False; } } if (dorun) { ret = smbrun(syscmd,outfile,True); DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret)); } lpq_cache_reset[snum] = False; f = fopen(outfile,"r"); if (!f) { return(0); } if (status) { fstrcpy(status->message,""); status->status = LPSTAT_OK; } while (fgets(line,sizeof(pstring),f)) { DEBUG(6,("QUEUE2: %s\n",line)); *queue = Realloc(*queue,sizeof(print_queue_struct)*(count+1)); if (! *queue) { count = 0; break; } bzero((char *)&(*queue)[count],sizeof(**queue)); /* parse it */ if (!parse_lpq_entry(snum,line,&(*queue)[count],status,count==0)) continue; count++; } fclose(f); if (!cachetime) { unlink(outfile); } else { /* we only expect this to succeed on trapdoor systems, on normal systems the file is owned by root */ chmod(outfile,0666); } return(count); }
int TString::vprintf( const char* format, va_list args ) { int len = vsnprintf( NULL, 0, format, args ); Realloc( len ); return vsprintf( data, format, args ); }
int main(int argc, char *argv[]) { DAZZ_DB _ablock, _bblock; DAZZ_DB *ablock = &_ablock, *bblock = &_bblock; char *afile, *bfile; char *aroot, *broot, *apwd; void *aindex, *bindex; int alen, blen; int isdam, nblocks; // of reference (a-argument) int mflag; char *command; Align_Spec *settings; int COVER, NOMAP; int KMER_LEN; int MAX_REPS; double AVE_ERROR; int NTHREADS; int MAP_ORDER; int MMAX, MTOP, *MSTAT; char **MASK; { int i, j, k; int flags[128]; char *eptr; DIR *dirp; ARG_INIT("damapper") KMER_LEN = 20; MAX_REPS = 0; AVE_ERROR = .85; SPACING = 100; // Globally visible to map.c BEST_TIE = 1.0; NTHREADS = 4; SORT_PATH = "/tmp"; MEM_PHYSICAL = getMemorySize(); MEM_LIMIT = MEM_PHYSICAL; if (MEM_PHYSICAL == 0) { fprintf(stderr,"\nWarning: Could not get physical memory size\n"); fflush(stderr); } MTOP = 0; MMAX = 10; MASK = (char **) Malloc(MMAX*sizeof(char *),"Allocating mask track array"); MSTAT = (int *) Malloc(MMAX*sizeof(int),"Allocating mask status array"); if (MASK == NULL || MSTAT == NULL) exit (1); j = 1; for (i = 1; i < argc; i++) if (argv[i][0] == '-') switch (argv[i][1]) { default: ARG_FLAGS("vbpzCN") break; case 'e': ARG_REAL(AVE_ERROR) if (AVE_ERROR < .7 || AVE_ERROR >= 1.) { fprintf(stderr,"%s: Average correlation must be in [.7,1.) (%g)\n", Prog_Name,AVE_ERROR); exit (1); } break; case 'k': ARG_POSITIVE(KMER_LEN,"K-mer length") if (KMER_LEN > 32) { fprintf(stderr,"%s: K-mer length must be 32 or less\n",Prog_Name); exit (1); } break; case 'm': if (MTOP >= MMAX) { MMAX = 1.2*MTOP + 10; MASK = (char **) Realloc(MASK,MMAX*sizeof(char *),"Reallocating mask track array"); MSTAT = (int *) Realloc(MSTAT,MMAX*sizeof(int),"Reallocating mask status array"); if (MASK == NULL || MSTAT == NULL) exit (1); } MASK[MTOP++] = argv[i]+2; break; case 'n': ARG_REAL(BEST_TIE) if (BEST_TIE < .7 || BEST_TIE > 1.) { fprintf(stderr,"%s: Near optimal threshold must be in [.7,1.] (%g)\n", Prog_Name,BEST_TIE); exit (1); } break; case 's': ARG_POSITIVE(SPACING,"Trace spacing") break; case 't': ARG_POSITIVE(MAX_REPS,"Tuple supression frequency") break; case 'M': { int limit; ARG_NON_NEGATIVE(limit,"Memory allocation (in Gb)") MEM_LIMIT = limit * 0x40000000ll; break; } case 'P': SORT_PATH = argv[i]+2; if ((dirp = opendir(SORT_PATH)) == NULL) { fprintf(stderr,"%s: -P option: cannot open directory %s\n",Prog_Name,SORT_PATH); exit (1); } closedir(dirp); break; case 'T': ARG_POSITIVE(NTHREADS,"Number of threads") break; } else argv[j++] = argv[i]; argc = j; VERBOSE = flags['v']; // Globally declared in map.h BIASED = flags['b']; PROFILE = flags['p']; COVER = flags['C']; NOMAP = flags['N']; MAP_ORDER = 1-flags['z']; if (argc <= 2) { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage[0]); fprintf(stderr," %*s %s\n",(int) strlen(Prog_Name),"",Usage[1]); fprintf(stderr," %*s %s\n",(int) strlen(Prog_Name),"",Usage[2]); fprintf(stderr,"\n"); fprintf(stderr," -k: k-mer size (must be <= 32).\n"); fprintf(stderr," -t: Ignore k-mers that occur >= -t times in a block.\n"); fprintf(stderr," -M: Use only -M GB of memory by ignoring most frequent k-mers.\n"); fprintf(stderr,"\n"); fprintf(stderr," -e: Look for alignments with -e percent similarity.\n"); fprintf(stderr," -s: Use -s as the trace point spacing for encoding alignments.\n"); fprintf(stderr," -n: Output all matches within this %% of the best\n"); fprintf(stderr,"\n"); fprintf(stderr," -T: Use -T threads.\n"); fprintf(stderr," -P: Do sorts and merges in directory -P.\n"); fprintf(stderr," -m: Soft mask the blocks with the specified mask.\n"); fprintf(stderr," -b: For AT/GC biased data, compensate k-mer counts (deprecated).\n"); fprintf(stderr,"\n"); fprintf(stderr," -v: Verbose mode, output statistics as proceed.\n"); fprintf(stderr," -z: sort .las by A,B-read pairs (overlap piles)\n"); fprintf(stderr," off => sort .las by A-read,A-position pairs"); fprintf(stderr," (default for mapping)\n"); fprintf(stderr," -p: Output repeat profile track\n"); fprintf(stderr," -C: Output reference vs reads .las.\n"); fprintf(stderr," -N: Do not output reads vs reference .las.\n"); exit (1); } if (COVER) if (NOMAP) mflag = FLAG_DOB; else mflag = FLAG_DOA | FLAG_DOB; else if (NOMAP) { fprintf(stderr,"%s: Cannot specify both C and N flags together\n",Prog_Name); exit (1); } else mflag = FLAG_DOA; if (NOMAP && PROFILE) { fprintf(stderr,"%s: Cannot specify both N and p flags together\n",Prog_Name); exit (1); } for (j = 0; j < MTOP; j++) MSTAT[j] = -2; }