/* {{{ mail_free_errorlist * * Mail garbage collect FOBJECTLIST * Accepts: pointer to FOBJECTLIST pointer * Author: CJH */ static void mail_free_errorlist(ERRORLIST **errlist) { if (*errlist) { /* only free if exists */ if ((*errlist)->text.data) { fs_give((void **) &(*errlist)->text.data); } mail_free_errorlist (&(*errlist)->next); fs_give((void **) errlist); /* return string to free storage */ } }
void tcp_close (TCPSTREAM *stream) { tcp_abort (stream); /* nuke the stream */ /* flush host names */ if (stream->host) fs_give ((void **) &stream->host); if (stream->remotehost) fs_give ((void **) &stream->remotehost); if (stream->localhost) fs_give ((void **) &stream->localhost); fs_give ((void **) &stream); /* flush the stream */ }
void tcp_close (TCPSTREAM *stream) { int argblk[5]; argblk[1] = stream->jfn; /* close TCP */ jsys (CLOSF,argblk); /* flush host names */ fs_give ((void **) &stream->host); fs_give ((void **) &stream->localhost); fs_give ((void **) &stream); /* flush the stream */ }
/*---------------------------------------------------------------------- Release resources of a message part exception list Accepts: parts -- list of parts to free Returns: with specified structure and its members free'd ----*/ void msgno_free_exceptions(PARTEX_S **parts) { if(parts && *parts){ if((*parts)->next) msgno_free_exceptions(&(*parts)->next); fs_give((void **) &(*parts)->partno); fs_give((void **) parts); } }
void rfc2231_free_parmlist(PARMLIST_S **p) { if(*p){ if((*p)->value) fs_give((void **) &(*p)->value); mail_free_body_parameter(&(*p)->seen); fs_give((void **) p); } }
long smtp_auth (SENDSTREAM *stream,NETMBX *mb,char *tmp) { unsigned long trial,auths; char *lsterr = NIL; char usr[MAILTMPLEN]; AUTHENTICATOR *at; long ret = NIL; for (auths = ESMTP.auth, stream->saslcancel = NIL; !ret && stream->netstream && auths && (at = mail_lookup_auth (find_rightmost_bit (&auths) + 1)); ) { if (lsterr) { /* previous authenticator failed? */ sprintf (tmp,"Retrying using %s authentication after %.80s", at->name,lsterr); mm_log (tmp,NIL); fs_give ((void **) &lsterr); } trial = 0; /* initial trial count */ tmp[0] = '\0'; /* empty buffer */ if (stream->netstream) do { if (lsterr) { sprintf (tmp,"Retrying %s authentication after %.80s",at->name,lsterr); mm_log (tmp,WARN); fs_give ((void **) &lsterr); } stream->saslcancel = NIL; if (smtp_send (stream,"AUTH",at->name) == SMTPAUTHREADY) { /* hide client authentication responses */ if (!(at->flags & AU_SECURE)) stream->sensitive = T; if ((*at->client) (smtp_challenge,smtp_response,"smtp",mb,stream, &trial,usr)) { if (stream->replycode == SMTPAUTHED) { ESMTP.auth = NIL; /* disable authenticators */ ret = LONGT; } /* if main program requested cancellation */ else if (!trial) mm_log ("SMTP Authentication cancelled",ERROR); } stream->sensitive = NIL;/* unhide */ } /* remember response if error and no cancel */ if (!ret && trial) lsterr = cpystr (stream->reply); } while (!ret && stream->netstream && trial && (trial < smtp_maxlogintrials)); } if (lsterr) { /* previous authenticator failed? */ if (!stream->saslcancel) { /* don't do this if a cancel */ sprintf (tmp,"Can not authenticate to SMTP server: %.80s",lsterr); mm_log (tmp,ERROR); } fs_give ((void **) &lsterr); } return ret; /* authentication failed */ }
long slave_append (MAILSTREAM *stream,void *data,char **flags,char **date, STRING **message) { char tmp[MAILTMPLEN]; unsigned long n; int c; APPENDDATA *ad = (APPENDDATA *) data; /* flush text of previous message */ if (ad->flags) fs_give ((void **) &ad->flags); if (ad->date) fs_give ((void **) &ad->date); if (ad->msg) fs_give ((void **) &ad->msg); *flags = *date = NIL; /* assume no flags or date */ fputs ("A\n",slaveout); /* tell master we're doing append callback */ fflush (slaveout); switch (c = getc (slavein)) { /* what did master say? */ case '+': /* have message, get size of flags */ for (n = 0; isdigit (c = getc (slavein)); n *= 10, n += (c - '0')); if (c != ' ') { sprintf (tmp,"Missing delimiter after flag size %lu: %c",n,c); slave_fatal (tmp); } if (n) *flags = ad->flags = slave_append_read (n,"flags"); /* get size of date */ for (n = 0; isdigit (c = getc (slavein)); n *= 10, n += (c - '0')); if (c != ' ') { sprintf (tmp,"Missing delimiter after date size %lu: %c",n,c); slave_fatal (tmp); } if (n) *date = ad->date = slave_append_read (n,"date"); /* get size of message */ for (n = 0; isdigit (c = getc (slavein)); n *= 10, n += (c - '0')); if (c != ' ') { sprintf (tmp,"Missing delimiter after message size %lu: %c",n,c); slave_fatal (tmp); } if (n) { /* make buffer for message */ ad->msg = slave_append_read (n,"message"); /* initialize stringstruct */ INIT (&ad->message,mail_string,(void *) ad->msg,n); ad->first = NIL; /* no longer first message */ *message = &ad->message; /* return message */ } else *message = NIL; /* empty message */ return LONGT; case '-': /* error */ *message = NIL; /* set stop */ break; default: /* unknown event */ sprintf (tmp,"Unknown master response for append: %c",c); slave_fatal (tmp); } return NIL; /* return failure */ }
/* Write RFC822 address with 1522 decoding of personal name * and optional quoting. * * The idea is that there are some places where we'd just like to display * the personal name as is before applying confusing quoting. However, * we do want to be careful not to break things that should be quoted so * we'll only use this where we are sure. Quoting may look ugly but it * doesn't usually break anything. */ void rfc822_write_address_decode(char *dest, size_t destlen, struct mail_address *adr, int do_quote) { RFC822BUFFER buf; extern const char *rspecials; ADDRESS *copy, *a; /* * We want to print the adr list after decoding it. C-client knows * how to parse and print, so we want to use that. But c-client * doesn't decode. So we make a copy of the address list, decode * things there, and let c-client print that. */ copy = copyaddrlist(adr); for(a = copy; a; a = a->next){ if(a->host){ /* ordinary address? */ if(a->personal && *a->personal){ unsigned char *p; p = rfc1522_decode_to_utf8((unsigned char *) tmp_20k_buf, SIZEOF_20KBUF, a->personal); if(p && (char *) p != a->personal){ fs_give((void **) &a->personal); a->personal = cpystr((char *) p); } } } else if(a->mailbox && *a->mailbox){ /* start of group? */ unsigned char *p; p = rfc1522_decode_to_utf8((unsigned char *) tmp_20k_buf, SIZEOF_20KBUF, a->mailbox); if(p && (char *) p != a->mailbox){ fs_give((void **) &a->mailbox); a->mailbox = cpystr((char *) p); } } } buf.end = (buf.beg = buf.cur = dest) + destlen; buf.f = rfc822_dummy_soutr; *buf.cur = '\0'; buf.s = NIL; (void) rfc822_output_address_list(&buf, copy, 0, do_quote ? rspecials : rspecials_minus_quote_and_dot); *buf.cur = '\0'; if(copy) mail_free_address(©); }
static long ssl_abort (SSLSTREAM *stream) { if (stream->tcpstream) { /* close TCP stream */ DeleteSecurityContext (&stream->context); FreeCredentialHandle (&stream->cred); tcp_close (stream->tcpstream); stream->tcpstream = NIL; } if (stream->ibuf) fs_give ((void **) &stream->ibuf); if (stream->obuf) fs_give ((void **) &stream->obuf); return NIL; }
/* Context Manager apply name to context * Accepts: buffer to write, context to apply, ambiguous folder name * Returns: buffer filled with fully qualified name in context * No context applied if error */ char * context_apply(char *b, CONTEXT_S *c, char *name, size_t len) { if(!c || IS_REMOTE(name) || (!IS_REMOTE(c->context) && is_absolute_path(name))){ strncpy(b, name, len-1); /* no context! */ } else if(name[0] == '#'){ if(IS_REMOTE(c->context)){ char *p = strchr(c->context, '}'); /* name specifies namespace */ snprintf(b, len, "%.*s", MIN(p - c->context + 1, len-1), c->context); b[MIN(p - c->context + 1, len-1)] = '\0'; snprintf(b+strlen(b), len-strlen(b), "%.*s", len-1-strlen(b), name); } else{ strncpy(b, name, len-1); } } else if(c->dir && c->dir->ref){ /* has reference string! */ snprintf(b, len, "%.*s", len-1, c->dir->ref); b[len-1] = '\0'; snprintf(b+strlen(b), len-strlen(b), "%.*s", len-1-strlen(b), name); } else{ /* no ref, apply to context */ char *pq = NULL; /* * Have to quote %s for the sprintf because we're using context * as a format string. */ pq = context_percent_quote(c->context); if(strlen(c->context) + strlen(name) < len) snprintf(b, len, pq, name); else{ char *t; size_t l; l = strlen(pq)+strlen(name); t = (char *) fs_get((l+1) * sizeof(char)); snprintf(t, l+1, pq, name); strncpy(b, t, len-1); fs_give((void **)&t); } if(pq) fs_give((void **) &pq); } b[len-1] = '\0'; return(b); }
void free_color_name_list(struct color_name_list **nl) { if(nl && *nl){ if((*nl)->next) free_color_name_list(&(*nl)->next); if((*nl)->name) fs_give((void **) &(*nl)->name); fs_give((void **) nl); } }
void free_hist(HISTORY_S **history) { int i; if(history && *history){ for(i = 0; i < (*history)->histsize; i++) if((*history)->hist[i] && (*history)->hist[i]->str) fs_give((void **) &(*history)->hist[i]->str); fs_give((void **) history); } }
/* {{{ mail_free_foblist * * Mail garbage collect FOBJECTLIST * Accepts: pointer to FOBJECTLIST pointer * Author: CJH */ void mail_free_foblist(FOBJECTLIST **foblist, FOBJECTLIST **tail) { FOBJECTLIST *cur, *next; for (cur=*foblist, next=cur->next; cur; cur=next) { next = cur->next; if (cur->text.data) fs_give((void **)&(cur->text.data)); fs_give((void **)&cur); } *tail = NIL; *foblist = NIL; }
FILE *netmsg_slurp (NETSTREAM *stream,unsigned long *size,unsigned long *hsiz) { unsigned long i; char *s,*t,tmp[MAILTMPLEN]; FILE *f = tmpfile (); if (!f) { sprintf (tmp,".%lx.%lx",(unsigned long) time (0),(unsigned long)getpid ()); if (f = fopen (tmp,"wb+")) unlink (tmp); else { sprintf (tmp,"Unable to create scratch file: %.80s",strerror (errno)); MM_LOG (tmp,ERROR); return NIL; } } *size = 0; /* initially emtpy */ if (hsiz) *hsiz = 0; while (s = net_getline (stream)) { if (*s == '.') { /* possible end of text? */ if (s[1]) t = s + 1; /* pointer to true start of line */ else { fs_give ((void **) &s); /* free the line */ break; /* end of data */ } } else t = s; /* want the entire line */ if (f) { /* copy it to the file */ i = strlen (t); /* size of line */ if ((fwrite (t,(size_t) 1,(size_t) i,f) == i) && (fwrite ("\015\012",(size_t) 1,(size_t) 2,f) == 2)) { *size += i + 2; /* tally up size of data */ /* note header position */ if (!i && hsiz && !*hsiz) *hsiz = *size; } else { sprintf (tmp,"Error writing scratch file at byte %lu",*size); MM_LOG (tmp,ERROR); fclose (f); /* forget it */ f = NIL; /* failure now */ } } fs_give ((void **) &s); /* free the line */ } /* if making a file, rewind to start of file */ if (f) fseek (f,(unsigned long) 0,L_SET); /* header consumes entire message */ if (hsiz && !*hsiz) *hsiz = *size; return f; /* return the file descriptor */ }
int context_config_add(struct pine *ps, CONF_S **cl) { char *raw_ctxt; struct variable *var; char **lval; int count; if((raw_ctxt = context_edit_screen(ps, "ADD", NULL, NULL, NULL, NULL)) != NULL){ /* * If var is non-NULL we add to the end of that var. * If it is NULL, that means we're adding to the current_val, so * we'll have to soak up the default values from there into our * own variable. */ if((*cl)->var){ var = (*cl)->var; lval = LVAL((*cl)->var, ew); } else{ q_status_message(SM_ORDER|SM_DING, 3, 3, "Programmer botch in context_config_add"); return(0); } for(count = 0; lval && lval[count]; count++) ; if(!ccs_var_insert(ps, raw_ctxt, var, lval, count)){ fs_give((void **)&raw_ctxt); q_status_message(SM_ORDER|SM_DING, 3, 3, _("Error adding new collection")); return(0); } fs_give((void **)&raw_ctxt); (*cl)->d.c.cs->starting_var = var; (*cl)->d.c.cs->starting_varmem = count; q_status_message(SM_ORDER, 0, 3, _("New collection added. Use \"$\" to adjust order.")); return(15); } ps->mangled_screen = 1; return(0); }
long dummy_ping (MAILSTREAM *stream) { MAILSTREAM *test; /* time to do another test? */ if (time (0) >= ((time_t) (stream->gensym + 30))) { /* has mailbox format changed? */ if ((test = mail_open (NIL,stream->mailbox,OP_PROTOTYPE)) && (test->dtb != stream->dtb) && (test = mail_open (NIL,stream->mailbox,NIL))) { /* preserve some resources */ test->original_mailbox = stream->original_mailbox; stream->original_mailbox = NIL; test->sparep = stream->sparep; stream->sparep = NIL; test->sequence = stream->sequence; mail_close ((MAILSTREAM *) /* flush resources used by dummy stream */ memcpy (fs_get (sizeof (MAILSTREAM)),stream, sizeof (MAILSTREAM))); /* swap the streams */ memcpy (stream,test,sizeof (MAILSTREAM)); fs_give ((void **) &test);/* flush test now that copied */ /* make sure application knows */ mail_exists (stream,stream->recent = stream->nmsgs); } /* still hasn't changed */ else stream->gensym = time (0); } return T; }
long dummy_listed (MAILSTREAM *stream,char delimiter,char *name, long attributes,char *contents) { struct stat sbuf; int fd; long csiz,ssiz,bsiz; char *s,*buf,tmp[MAILTMPLEN]; if (contents) { /* want to search contents? */ /* forget it if can't select or open */ if ((attributes & LATT_NOSELECT) || !(csiz = strlen (contents)) || !(s = dummy_file (tmp,name)) || stat (s,&sbuf) || (csiz > sbuf.st_size) || ((fd = open (tmp,O_RDONLY,NIL)) < 0)) return T; /* get buffer including slop */ buf = (char *) fs_get (BUFSIZE + (ssiz = 4 * ((csiz / 4) + 1)) + 1); memset (buf,'\0',ssiz); /* no slop area the first time */ while (sbuf.st_size) { /* until end of file */ read (fd,buf+ssiz,bsiz = min (sbuf.st_size,BUFSIZE)); if (search ((unsigned char *) buf,bsiz+ssiz, (unsigned char *) contents,csiz)) break; memcpy (buf,buf+BUFSIZE,ssiz); sbuf.st_size -= bsiz; /* note that we read that much */ } fs_give ((void **) &buf); /* flush buffer */ close (fd); /* finished with file */ if (!sbuf.st_size) return T;/* not found */ } /* notify main program */ mm_list (stream,delimiter,name,attributes); return T; }
int our_link(char *oldpath, char *newpath) { #ifdef _WINDOWS assert(0); /* link not used in Windows */ return(-1); #else /* UNIX */ char *p, *pold; size_t len; int ret = -1; p = fname_to_locale(oldpath); if(p){ len = strlen(p); pold = (char *) fs_get((len+1) * sizeof(char)); strncpy(pold, p, len+1); pold[len] = '\0'; ret = link(pold, fname_to_locale(newpath)); fs_give((void **) &pold); } return ret; #endif /* UNIX */ }
int our_open(char *path, int flags, mode_t mode) { #ifdef _WINDOWS LPTSTR p = NULL; int ret = -1; /* * Setting the _O_WTEXT flag when opening a file for reading * will cause us to read the first few bytes to check for * a BOM and to translate from that encoding if we find it. * This only works with stream I/O, not low-level read/write. * * When opening for writing the flag _O_U8TEXT will cause * us to put a UTF-8 BOM at the start of the file. * * O_TEXT will cause LF -> CRLF on output, opposite on input * O_BINARY suppresses that. * _O_U8TEXT implies O_TEXT. */ p = utf8_to_lptstr((LPSTR) path); if(p){ ret = _topen(p, flags, mode); fs_give((void **) &p); } return ret; #else /* UNIX */ return(open(fname_to_locale(path), flags, mode)); #endif /* UNIX */ }
int our_stat(char *filename, struct stat *sbuf) { #ifdef _WINDOWS LPTSTR f = NULL; int ret = -1; struct _stat s; f = utf8_to_lptstr((LPSTR) filename); if(f){ ret = _tstat(f, &s); sbuf->st_dev = s.st_dev; sbuf->st_ino = s.st_ino; sbuf->st_mode = s.st_mode; sbuf->st_nlink = s.st_nlink; sbuf->st_uid = s.st_uid; sbuf->st_gid = s.st_gid; sbuf->st_rdev = s.st_rdev; sbuf->st_size = s.st_size; sbuf->st_atime = (time_t) s.st_atime; sbuf->st_mtime = (time_t) s.st_mtime; sbuf->st_ctime = (time_t) s.st_ctime; fs_give((void **) &f); } return ret; #else /* UNIX */ return(stat(fname_to_locale(filename), sbuf)); #endif /* UNIX */ }
char *tcp_clienthost () { if (!myClientHost) { size_t sadrlen; struct sockaddr *sadr = ip_newsockaddr (&sadrlen); if (getpeername (0,sadr,(void *) &sadrlen)) { char *s,*t,*v,tmp[MAILTMPLEN]; if ((s = getenv (t = "SSH_CLIENT")) || (s = getenv (t = "KRB5REMOTEADDR")) || (s = getenv (t = "SSH2_CLIENT"))) { if (v = strchr (s,' ')) *v = '\0'; sprintf (v = tmp,"%.80s=%.80s",t,s); } else v = "UNKNOWN"; myClientHost = cpystr (v); } else { /* get stdin's peer name */ myClientHost = tcp_name (sadr,T); if (!myClientAddr) myClientAddr = cpystr (ip_sockaddrtostring (sadr)); if (myClientPort < 0) myClientPort = ip_sockaddrtoport (sadr); } fs_give ((void **) &sadr); } return myClientHost; }
void free_keyword_list(KEYWORD_S **kl) { if(kl && *kl){ if((*kl)->next) free_keyword_list(&(*kl)->next); if((*kl)->kw) fs_give((void **) &(*kl)->kw); if((*kl)->nick) fs_give((void **) &(*kl)->nick); fs_give((void **) kl); } }
void free_color_table(struct color_table **ctbl) { struct color_table *t; if(ctbl && *ctbl){ for(t = *ctbl; t->names; t++){ free_color_name_list(&t->names); if(t->rgb) fs_give((void **) &t->rgb); } fs_give((void **) ctbl); } }
unsigned long unix_crlfcpy (char **dst,unsigned long *dstl,char *src, unsigned long srcl) { unsigned long i,j; char *d = src; /* count number of LF's in source string(s) */ for (i = srcl,j = 0; j < srcl; j++) if (*d++ == '\012') i++; /* flush destination buffer if too small */ if (*dst && (i > *dstl)) fs_give ((void **) dst); if (!*dst) { /* make a new buffer if needed */ *dst = (char *) fs_get ((*dstl = i) + 1); if (dstl) *dstl = i; /* return new buffer length to main program */ } d = *dst; /* destination string */ /* copy strings, inserting CR's before LF's */ while (srcl--) switch (*src) { case '\015': /* unlikely carriage return */ *d++ = *src++; /* copy it and any succeeding linefeed */ if (srcl && *src == '\012') { *d++ = *src++; srcl--; } break; case '\012': /* line feed? */ *d++ ='\015'; /* yes, prepend a CR, drop into default case */ default: /* ordinary chararacter */ *d++ = *src++; /* just copy character */ break; } *d = '\0'; /* tie off destination */ return d - *dst; /* return length */ }
static char *tcp_getline_work (TCPSTREAM *stream,unsigned long *size, long *contd) { unsigned long n; char *s,*ret,c,d; *contd = NIL; /* assume no continuation */ /* make sure have data */ if (!tcp_getdata (stream)) return NIL; for (s = stream->iptr, n = 0, c = '\0'; stream->ictr--; n++, c = d) { d = *stream->iptr++; /* slurp another character */ if ((c == '\015') && (d == '\012')) { ret = (char *) fs_get (n--); memcpy (ret,s,*size = n); /* copy into a free storage string */ ret[n] = '\0'; /* tie off string with null */ return ret; } } /* copy partial string from buffer */ memcpy ((ret = (char *) fs_get (n)),s,*size = n); /* get more data from the net */ if (!tcp_getdata (stream)) fs_give ((void **) &ret); /* special case of newline broken by buffer */ else if ((c == '\015') && (*stream->iptr == '\012')) { stream->iptr++; /* eat the line feed */ stream->ictr--; ret[*size = --n] = '\0'; /* tie off string with null */ } else *contd = LONGT; /* continuation needed */ return ret; }
/* * This is a line-at-a-time filter that replaces incoming UTF-8 text with * ISO-2022-JP text. */ int translate_utf8_to_2022_jp(long int linenum, char *line, LT_INS_S **ins, void *local) { LOC_2022_JP *lpj; int ret = 0; lpj = (LOC_2022_JP *) local; if(line && line[0]){ char *converted; size_t len; converted = utf8_to_charset(line, "ISO-2022-JP", lpj ? lpj->report_err : 0); if(!converted) ret = -1; if(converted && converted != line){ /* delete the old line and replace it with the translation */ len = strlen(line); ins = gf_line_test_new_ins(ins, line, "", -((int) len)); ins = gf_line_test_new_ins(ins, line+len, converted, strlen(converted)); fs_give((void **) &converted); } } return ret; }
/*---------------------------------------------------------------------- Paint the screen with the radio buttons prompt ----*/ void draw_radio_prompt(int line, unsigned start_c, unsigned max_c, char *q) { size_t len; unsigned x, width, got_width; char *tmpq = NULL, *useq; width = utf8_width(q); if(width > max_c - start_c + 1){ tmpq = (char *) fs_get((len=(strlen(q)+1)) * sizeof(char)); (void) utf8_to_width(tmpq, q, len, max_c - start_c + 1, &got_width); useq = tmpq; width = got_width; } else useq = q; PutLine0(line, start_c, useq); x = start_c + width; MoveCursor(line, x); while(x++ < ps_global->ttyo->screen_cols) Writechar(' ', 0); MoveCursor(line, start_c + width); fflush(stdout); if(tmpq) fs_give((void **) &tmpq); }
static int checkpw_conv (int num_msg,const struct pam_message **msg, struct pam_response **resp,void *appdata_ptr) { int i; struct checkpw_cred *cred = (struct checkpw_cred *) appdata_ptr; struct pam_response *reply = fs_get (sizeof (struct pam_response) * num_msg); for (i = 0; i < num_msg; i++) switch (msg[i]->msg_style) { case PAM_PROMPT_ECHO_ON: /* assume want user name */ reply[i].resp_retcode = PAM_SUCCESS; reply[i].resp = cpystr (cred->uname); break; case PAM_PROMPT_ECHO_OFF: /* assume want password */ reply[i].resp_retcode = PAM_SUCCESS; reply[i].resp = cpystr (cred->pass); break; case PAM_TEXT_INFO: case PAM_ERROR_MSG: reply[i].resp_retcode = PAM_SUCCESS; reply[i].resp = NULL; break; default: /* unknown message style */ fs_give ((void **) &reply); return PAM_CONV_ERR; } *resp = reply; return PAM_SUCCESS; }
int scandir (char *dirname,struct _finddata_t ***namelist,select_t select, compar_t compar) { struct _finddata_t *p, d, **names; int nitems; long nlmax; long hDir; char *filemask = (char *)fs_get((strlen(dirname) + 5) * sizeof(char)); strcpy(filemask, dirname); strcat(filemask, "/*.*"); hDir = _findfirst(filemask, &d);/* open directory */ fs_give((void **)&filemask); if (hDir == -1) return -1; nlmax = 100; /* FIXME how to get number of files in dir? */ names = (struct _finddata_t **) fs_get (nlmax * sizeof (struct _finddata_t *)); nitems = 0; /* initially none found */ do { /* loop over all files */ /* matches select criterion? */ if (select && !(*select) (&d)) continue; p = (struct _finddata_t *)fs_get(sizeof(d)); strcpy (p->name,d.name); if (++nitems >= nlmax) { /* if out of space, try bigger guesstimate */ nlmax *= 2; /* double it */ fs_resize ((void **) &names,nlmax * sizeof (struct _finddata_t *)); } names[nitems - 1] = p; /* store this file there */ } while (_findnext(hDir, &d) == 0); _findclose(hDir); /* done with directory */ /* sort if necessary */ if (nitems && compar) qsort (names,nitems,sizeof (struct _finddata_t *),compar); *namelist = names; /* return directory */ return nitems; /* and size */ }
/*---------------------------------------------------------------------- Release resources of a message manipulation structure Accepts: msgs - pointer to message manipulation struct n - number to test Returns: with specified structure and its members free'd ----*/ void msgno_give(MSGNO_S **msgs) { if(msgs && *msgs){ if((*msgs)->sort) fs_give((void **) &((*msgs)->sort)); if((*msgs)->isort) fs_give((void **) &((*msgs)->isort)); if((*msgs)->select) fs_give((void **) &((*msgs)->select)); fs_give((void **) msgs); } }