/* process command line arguments */ static void parse_args(int argc, char **argv) { extern char *optarg; extern int optopt; int c; while((c = getopt(argc, argv, ":hi:o:")) != -1) { switch(c) { case 'h': usage(EXIT_SUCCESS); break; case 'i': opt.in_file = Strdup((const char *) optarg); break; case 'o': opt.out_dir = Strdup((const char *) optarg); opt.out_dir_len = (int) strlen(opt.out_dir); break; case ':': fprintf(stderr, "%s: Missing argument for -%c.\n", prog, (char) optopt); usage(EXIT_FAILURE); break; case '?': fprintf(stderr, "%s: Unrecognized option -%c.\n", prog, (char) optopt); usage(EXIT_FAILURE); } } if (opt.out_dir == NULL) { fprintf(stderr, "%s: -o argument required\n", prog); usage(EXIT_FAILURE); } }
/* * parser_read_replica -- (internal) read line and validate remote replica * from a pool set file */ static enum parser_codes parser_read_replica(char *line, char **node_addr, char **pool_desc) { char *addr_str; char *desc_str; char *saveptr; addr_str = strtok_r(line, " \t", &saveptr); desc_str = strtok_r(NULL, " \t", &saveptr); if (!addr_str || !desc_str) return PARSER_REMOTE_REPLICA_EXPECTED; LOG(10, "node address '%s' pool set descriptor '%s'", addr_str, desc_str); /* check if the descriptor is a relative path */ if (util_is_absolute_path(desc_str)) return PARSER_RELATIVE_PATH_EXPECTED; *node_addr = Strdup(addr_str); *pool_desc = Strdup(desc_str); if (!(*node_addr) || !(*pool_desc)) { ERR("!Strdup"); if (*node_addr) Free(*node_addr); if (*pool_desc) Free(*pool_desc); return PARSER_OUT_OF_MEMORY; } return PARSER_CONTINUE; }
/* Function: RegisterHit() * * Purpose: Add a new hit to a list of top hits. * * "ali", if provided, is a pointer to allocated memory * for an alignment output structure. * Management is turned over to the top hits structure. * Caller should not free them; they will be free'd by * the FreeTophits() call. * * In contrast, "name" and "desc" are copied, so caller * is still responsible for these. * * Number of args is unwieldy. * * Args: h - active top hit list * key - value to sort by: bigger is better * pvalue - P-value of this hit * score - score of this hit * motherp - P-value of parent whole sequence * mothersc - score of parent whole sequence * name - name of target sequence * desc - description of target sequence * sqfrom - 1..L pos in target seq of start * sqto - 1..L pos; sqfrom > sqto if rev comp * sqlen - length of sequence, L * hmmfrom - 0..M+1 pos in HMM of start * hmmto - 0..M+1 pos in HMM of end * hmmlen - length of HMM, M * domidx - number of this domain * ndom - total # of domains in sequence * ali - optional printable alignment info * * Return: (void) * hitlist is modified and possibly reallocated internally. */ void RegisterHit(struct tophit_s *h, double key, double pvalue, float score, double motherp, float mothersc, char *name, char *desc, int sqfrom, int sqto, int sqlen, int hmmfrom, int hmmto, int hmmlen, int domidx, int ndom, struct fancyali_s *ali) { /* Check to see if list is full and we must realloc. */ if (h->num == h->alloc) GrowTophits(h); h->unsrt[h->num].name = Strdup(name); h->unsrt[h->num].desc = Strdup(desc); h->unsrt[h->num].sortkey = key; h->unsrt[h->num].pvalue = pvalue; h->unsrt[h->num].score = score; h->unsrt[h->num].motherp = motherp; h->unsrt[h->num].mothersc= mothersc; h->unsrt[h->num].sqfrom = sqfrom; h->unsrt[h->num].sqto = sqto; h->unsrt[h->num].sqlen = sqlen; h->unsrt[h->num].hmmfrom = hmmfrom; h->unsrt[h->num].hmmto = hmmto; h->unsrt[h->num].hmmlen = hmmlen; h->unsrt[h->num].domidx = domidx; h->unsrt[h->num].ndom = ndom; h->unsrt[h->num].ali = ali; h->num++; return; }
static void add_one_ISBN_range(const char *the_begin, const char *the_end, const char *the_countries, size_t where) { /* add an entry at slot where, without bounds checking, but with valid-value checking */ if ( (the_begin != (const char*)NULL) && (is_valid_ISBN_prefix(the_begin) == NO) || (the_end != (const char*)NULL) && (is_valid_ISBN_prefix(the_end) == NO) ) { fprintf(stdlog, "Invalid country/language-publisher ISBN prefix [%s] in ISBN file [%s]\n", the_begin, ISBN_file); return; } else if ((the_begin != (const char*)NULL) && (the_end != (const char*)NULL) && STRGREATER(the_begin,the_end)) { fprintf(stdlog, "Non-increasing country/language-publisher ISBN range [%s .. %s] in ISBN file [%s]\n", the_begin, the_end, ISBN_file); return; } ISBN_range[where].begin = (the_begin == (const char *)NULL) ? the_begin : Strdup(the_begin); ISBN_range[where].end = (the_end == (const char *)NULL) ? the_end : Strdup(the_end); ISBN_range[where].countries = (the_countries == (const char *)NULL) ? "" : Strdup(the_countries); }
void elog_start(const char *file, const char *func, int line) { fname = Strdup(file); funcname = Strdup(func); lineno = line; }
static char * reqpath(char *file, char **idnumber) { char *path; char *cp; char *cp2; /* * /var/spool/lp/tmp/machine/123-0 * /var/spool/lp/temp/123-0 * /usr/spool/lp/temp/123-0 * /usr/spool/lp/tmp/machine/123-0 * 123-0 * machine/123-0 * * /var/spool/lp/tmp/machine/123-0 + 123 */ if (*file == '/') { /*CONSTCOND*/ if (STRNEQU(file, Lp_Spooldir, strlen(Lp_Spooldir))) cp = file + strlen(Lp_Spooldir) + 1; else { if (STRNEQU(file, "/usr/spool/lp", 13)) cp = file + strlen("/usr/spool/lp") + 1; else { *idnumber = NULL; return (NULL); } } if (STRNEQU(cp, "temp", 4)) { cp += 5; path = makepath(Local_System, cp, NULL); } else path = Strdup(cp); } else { if (strchr(file, '/')) path = makepath(file, NULL); else path = makepath(Local_System, file, NULL); } cp = strrchr(path, '/'); cp++; if ((cp2 = strrchr(cp, '-')) == NULL) *idnumber = Strdup(cp); else { *cp2 = '\0'; *idnumber = Strdup(cp); *cp2 = '-'; } return (path); }
/* * Add gtm slave: to be used after all the configuration is done. * * This function only maintains internal configuration, updte configuration file, * and make backup if configured. You should run init_gtm_slave and stat_gtm_slave * separately. */ int add_gtmSlave(char *name, char *host, int port, char *dir) { char port_s[MAXTOKEN+1]; char date[MAXTOKEN+1]; FILE *f; int rc; if (isVarYes(VAR_gtmSlave)) { elog(ERROR, "ERROR: GTM slave is already configured.\n"); return 1; } if (is_none(host)) { elog(ERROR, "ERROR: Cannot add gtm slave with the name \"none\".\n"); return 1; } if (is_none(dir)) { elog(ERROR, "ERROR: Cannot add gtm slave with the directory \"none\".\n"); return 1; } if (checkSpecificResourceConflict(name, host, port, dir, TRUE)) { elog(ERROR, "ERROR: New specified name:%s, host:%s, port:%d and dir:\"%s\" conflicts with existing node.\n", name, host, port, dir); return 1; } assign_sval(VAR_gtmSlave, Strdup("y")); assign_sval(VAR_gtmSlaveServer, Strdup(host)); snprintf(port_s, MAXTOKEN, "%d", port); assign_sval(VAR_gtmSlavePort, Strdup(port_s)); assign_sval(VAR_gtmSlaveDir, Strdup(dir)); makeServerList(); if ((f = fopen(pgxc_ctl_config_path, "a")) == NULL) { /* Should it be panic? */ elog(ERROR, "ERROR: cannot open configuration file \"%s\", %s\n", pgxc_ctl_config_path, strerror(errno)); return 1; } fprintf(f, "#===================================================\n" "# pgxc configuration file updated due to GTM slave addition\n" "# %s\n", timeStampString(date, MAXTOKEN+1)); fprintSval(f, VAR_gtmSlave); fprintSval(f, VAR_gtmSlaveServer); fprintSval(f, VAR_gtmSlavePort); fprintSval(f, VAR_gtmSlaveDir); fprintf(f, "%s","#----End of reconfiguration -------------------------\n"); fclose(f); backup_configuration(); if ((rc = init_gtm_slave()) != 0) return rc; return(start_gtm_slave()); }
/* * Create log info structure: */ LogInfo log_create( LOG_FLAGS flags, const char *file, const char *prefix, size_t buf_size ) { LogInfo log = Calloc( sizeof( struct _LogInfo ), 1 ); if( !log ) { return NULL; } log->ibuf_size = LOG_IBUF_MIN_SIZE; log->ibuf = Malloc( LOG_IBUF_MIN_SIZE + 1 ); if( !log->ibuf ) { Free( log ); return 0; } if( buf_size ) { log->buf_size = buf_size < LOG_BUF_MIN_SIZE ? LOG_BUF_MIN_SIZE : buf_size; log->buf = Malloc( log->buf_size ); if( !log->buf ) { Free( log->ibuf ); Free( log ); return NULL; } } log->prefix = ( prefix ? ( *prefix ? Strdup( prefix ) : NULL ) : Strdup( LOG_DEFAULT_PREFIX ) ); if( ( ( prefix && *prefix ) || !prefix ) && !log->prefix ) { Free( log->ibuf ); Free( log->buf ); Free( log ); return NULL; } if( file ) { log->file = Strdup( file ); if( !log->file ) { Free( log->ibuf ); Free( log->prefix ); Free( log->buf ); Free( log ); return NULL; } } log->flags = flags; log->timefunc = ( flags & LOG_USE_GMTIME ) ? gmtime : localtime; __initlock( log->lock ); return log; }
int remove_gtmSlave(bool clean_opt) { FILE *f; /* Check if gtm_slave is configured */ if (!isVarYes(VAR_gtmSlave) || !sval(VAR_gtmSlaveServer) || is_none(sval(VAR_gtmSlaveServer))) { elog(ERROR, "ERROR: GTM slave is not configured.\n"); return 1; } /* Check if gtm_slave is not running */ if (!do_gtm_ping(sval(VAR_gtmSlaveServer), atoi(sval(VAR_gtmSlavePort)))) { elog(ERROR, "ERROR: GTM slave is now running. Cannot remove it.\n"); return 1; } elog(NOTICE, "Removing gtm slave.\n"); /* Clean */ if (clean_opt) clean_gtm_slave(); /* Reconfigure */ reset_var(VAR_gtmSlave); assign_sval(VAR_gtmSlave, Strdup("n")); reset_var(VAR_gtmSlaveServer); assign_sval(VAR_gtmSlaveServer, Strdup("none")); reset_var(VAR_gtmSlavePort); assign_sval(VAR_gtmSlavePort, Strdup("-1")); reset_var(VAR_gtmSlaveDir); assign_sval(VAR_gtmSlaveDir, Strdup("none")); /* Write the configuration file and bakup it */ if ((f = fopen(pgxc_ctl_config_path, "a")) == NULL) { /* Should it be panic? */ elog(ERROR, "ERROR: cannot open configuration file \"%s\", %s\n", pgxc_ctl_config_path, strerror(errno)); return 1; } fprintf(f, "#===================================================\n" "# pgxc configuration file updated due to GTM slave removal\n" "# %s\n", timeStampString(date, MAXTOKEN+1)); fprintSval(f, VAR_gtmSlave); fprintSval(f, VAR_gtmSlaveServer); fprintSval(f, VAR_gtmSlavePort); fprintSval(f, VAR_gtmSlaveDir); fprintf(f, "%s", "#----End of reconfiguration -------------------------\n"); fclose(f); backup_configuration(); elog(NOTICE, "Done.\n"); return 0; }
static Errorclass onelong(void) { char **nwordv; if (cur_wordc == 1 && language != INLD) { /* * We have either: * a) file name from cc * b) Assembler telling world that it is complaining * c) Noise from make ("Stop.") * c) Random noise */ cur_wordc = 0; if (strcmp(cur_wordv[1], "Stop.") == 0) { language = INMAKE; return (C_SYNC); } if (strcmp(cur_wordv[1], "Assembler:") == 0) { /* assembler always alerts us to what happened*/ language = INAS; return (C_SYNC); } else if (strcmp(cur_wordv[1], "Undefined:") == 0) { /* loader complains about unknown symbols*/ language = INLD; return (C_SYNC); } if (lastchar(cur_wordv[1]) == ':') { /* cc tells us what file we are in */ currentfilename = cur_wordv[1]; (void)substitute(currentfilename, ':', '\0'); language = INCC; return (C_SYNC); } } else if (cur_wordc == 1 && language == INLD) { nwordv = Calloc(4, sizeof(char *)); nwordv[0] = Strdup("ld:"); /* XXX leaked */ nwordv[1] = cur_wordv[1]; nwordv[2] = Strdup("is"); /* XXX leaked */ nwordv[3] = Strdup("undefined.");/* XXX leaked */ cur_wordc = 4; cur_wordv = nwordv - 1; return (C_NONSPEC); } else if (cur_wordc == 1) { return (C_SYNC); } return (C_UNKNOWN); } /* end of one long */
void list_target_new_target(char *name) // create a new target node on the target linked list { struct target *t = Malloc(sizeof(struct target)); struct list_recipe *r = list_recipe_init(); struct list_source *s = list_source_init(); if(targl->head == NULL) { targl->head = t; targl->tail = t; } else { (targl->tail)->next = t; targl->tail = t; } t->name = Strdup(name); t->source = s; t->recipe = r; t->is_last_targ = true; t->next = NULL; }
unsigned char *kernelversion() { FILE *ver; char version[16], sub[3], month[6], string[40], tmp[10]; int day=0, year=0; unsigned char *ret=NULL; if ( ( ver = fopen("/proc/version", "r")) == NULL ) return "???"; #ifdef DEBUG extern char debug_buf[600]; // for debugging output snprintf(debug_buf, sizeof(debug_buf)-1, "[%s/%d] open '/proc/version' o.k.\n",__FUNCTION__,__LINE__); debug_info(debug_buf); #endif // Linux version 2.4.35.3-mct (carsten@C2D6600) (gcc version 3.3.6) #2 Sa 29. Mär 13:47:52 CET 2008 fscanf(ver, "%s %s %s %s %s %s %s %s %s %d. %s %s %s %d\n" ,tmp, tmp, version, tmp, tmp,tmp, tmp, sub,tmp,&day, month, tmp, tmp, &year); #ifdef DEBUG snprintf(debug_buf, sizeof(debug_buf)-1, "[%s/%d] read: %s %s %d. %s %d\n",__FUNCTION__,__LINE__,version, sub, day, month, year); debug_info(debug_buf); #endif fclose(ver); // disabled for now, because the 'ä' 'ü' 'ö' need some special work //snprintf(string, sizeof(string)-1, "%s %s %d. %s %d",version, sub, day, month, year); snprintf(string, sizeof(string)-1, "%s %s (%d)",version, sub, year); ret=Strdup(string); return ret; }
cmd_t *initCmd(char *host) { cmd_t *rv = (cmd_t *)Malloc0(sizeof(cmd_t)); if (host) rv->host = Strdup(host); return rv; }
/*-------------------------------------------------------------------------* * PL_FOREIGN_RD_IO_ARG * * * *-------------------------------------------------------------------------*/ PlFIOArg * Pl_Foreign_Rd_IO_Arg(int arg_long, WamWord start_word, PlLong (*rd_fct) (), int fio_arg_index) { WamWord word, tag_mask; PlFIOArg *fa = fio_arg_array + fio_arg_index; DEREF(start_word, word, tag_mask); fa->is_var = fa->unify = (tag_mask == TAG_REF_MASK); if (rd_fct == NULL) fa->value.l = (PlLong) word; else if (!fa->is_var) { if (arg_long) { fa->value.l = (*rd_fct) (word); if (arg_long == 2) /* strdup needed */ fa->value.s = Strdup(fa->value.s); } else fa->value.d = (*(double (*)()) rd_fct) (word); } return fa; }
/* Function: Plan7SetName() * * Purpose: Change the name of a Plan7 HMM. Convenience function. * * Note: Trailing whitespace and \n's are chopped. */ void Plan7SetName(struct plan7_s *hmm, char *name) { if (hmm->name != NULL) free(hmm->name); hmm->name = Strdup(name); StringChop(hmm->name); }
void SeqinfoCopy(SQINFO *sq1, SQINFO *sq2) { sq1->flags = sq2->flags; if (sq2->flags & SQINFO_NAME) strcpy(sq1->name, sq2->name); if (sq2->flags & SQINFO_ID) strcpy(sq1->id, sq2->id); if (sq2->flags & SQINFO_ACC) strcpy(sq1->acc, sq2->acc); if (sq2->flags & SQINFO_DESC) strcpy(sq1->desc, sq2->desc); if (sq2->flags & SQINFO_LEN) sq1->len = sq2->len; if (sq2->flags & SQINFO_START) sq1->start = sq2->start; if (sq2->flags & SQINFO_STOP) sq1->stop = sq2->stop; if (sq2->flags & SQINFO_OLEN) sq1->olen = sq2->olen; if (sq2->flags & SQINFO_TYPE) sq1->type = sq2->type; if (sq2->flags & SQINFO_SS) sq1->ss = Strdup(sq2->ss); if (sq2->flags & SQINFO_SA) sq1->sa = Strdup(sq2->sa); }
static int nodeattr_process_opt(opt_t *pdsh_opts, int opt, char *arg) { switch (opt) { #if !GENDERS_G_ONLY case 'a': excllist = list_split_append (excllist, ",", "pdsh_all_skip"); case 'A': allnodes = true; break; case 'i': altnames = true; break; #endif /* !GENDERS_G_ONLY */ case 'g': attrlist = list_split_append (attrlist, ",", arg); break; case 'X': excllist = list_split_append (excllist, ",", arg); break; case 'F': gfile = Strdup (arg); break; default: err("%p: genders_process_opt: invalid option `%c'\n", opt); return -1; break; } return 0; }
/* function: read the hostname from /etc/hostname * return: pointer with the name * on error: default string * */ unsigned char *read_hostname() { FILE *hostname = NULL; char buf[50]; char *ret=NULL; if ((hostname=fopen("/etc/hostname", "r")) != NULL) { #ifdef DEBUG extern char debug_buf[600]; // for debugging output snprintf(debug_buf, sizeof(debug_buf)-1, "[%s/%d] open '/etc/hostname' o.k.\n",__FUNCTION__,__LINE__); debug_info(debug_buf); #endif if (fgets (buf, sizeof(buf), hostname) == NULL) { fclose(hostname); return "???"; } buf[strlen(buf)-1]='\0'; #ifdef DEBUG //extern char debug_buf[600]; // for debugging output snprintf(debug_buf, sizeof(debug_buf)-1, "[%s/%d] readed hostname: '%s' \n",__FUNCTION__,__LINE__,buf); debug_info(debug_buf); #endif ret=Strdup(buf); fclose(hostname); return ret; } else return "???"; }
/* * open RPC connection to rpc.metamhd */ static mhd_handle_t * open_metamhd( char *hostname, md_error_t *ep ) { CLIENT *clientp; mhd_handle_t *hp; /* default to local host */ if ((hostname == NULL) || (*hostname == '\0')) hostname = mynode(); /* open RPC connection */ assert(hostname != NULL); if ((clientp = meta_client_create(hostname, METAMHD, METAMHD_VERSION, "tcp")) == NULL) { clnt_pcreateerror(hostname); (void) mdrpccreateerror(ep, hostname, "metamhd clnt_create"); return (NULL); } else { auth_destroy(clientp->cl_auth); clientp->cl_auth = authsys_create_default(); assert(clientp->cl_auth != NULL); } /* return connection */ hp = Zalloc(sizeof (*hp)); hp->hostname = Strdup(hostname); hp->clientp = clientp; return (hp); }
char *http_response_to_string(const struct http_response *response, size_t *n) { char *buf = NULL; size_t size = 0, offset = 0; if (response->version == HTTP_09) { /* HTTP/0.9 doesn't have a Status-Line or headers. See http://www.w3.org/Protocols/HTTP/AsImplemented.html. */ return Strdup(""); } else { const char *version; char *header_str; if (response->version == HTTP_10) version = "HTTP/1.0"; else version = "HTTP/1.1"; header_str = http_header_to_string(response->header, NULL); strbuf_sprintf(&buf, &size, &offset, "%s %d %s\r\n%s\r\n", version, response->code, response->phrase, header_str); free(header_str); } if (n != NULL) *n = offset; return buf; }
unsigned char *get_cpuinfo() { // this functions gives only an average over the whole time since last start! // this here is better // http://www.koders.com/c/fidA14AFC28AEACAFE6E6BDB02F0A8D7F2345C642DC.aspx?s=%2fproc%2fstat#L2 FILE *cpuinfo; char vendor[10], model[8], string [30], tmp[10]; float clock=0; unsigned char *ret=NULL; if ( ( cpuinfo = fopen("/proc/cpuinfo", "r")) == NULL ) return "???"; #ifdef DEBUG extern char debug_buf[600]; // for debugging output snprintf(debug_buf, sizeof(debug_buf)-1, "[%s/%d] open '/proc/cpuinfo' o.k.\n",__FUNCTION__,__LINE__); debug_info(debug_buf); #endif fscanf(cpuinfo, "system type : %s %s\n", vendor, tmp); fscanf(cpuinfo, "processor : %s\n", tmp); fscanf(cpuinfo, "cpu model : %s %s %s %s\n", model,tmp,tmp,tmp); fscanf(cpuinfo, "BogoMIPS : %f\n", &clock); #ifdef DEBUG snprintf(debug_buf, sizeof(debug_buf)-1, "[%s/%d] read: '%s' '%s' %.2fMHz\n",__FUNCTION__,__LINE__,vendor, model, clock); debug_info(debug_buf); #endif fclose(cpuinfo); snprintf(string, sizeof(string)-1, "%s %s %.2fMhz",vendor, model, clock); ret=Strdup(string); return ret; }
pgxc_ctl_var *new_var(char *name) { pgxc_ctl_var *newv; if (find_var(name)) { elog(ERROR, "ERROR: Variable %s already defined. Check your configuration.\n", name); return NULL; } newv = (pgxc_ctl_var *)Malloc(sizeof(pgxc_ctl_var)); if (var_head == NULL) { var_head = var_tail = newv; newv->prev = NULL; } else { newv->prev = var_tail; var_tail->next = newv; var_tail = newv; } newv->next = NULL; newv->varname = Strdup(name); newv->val_size = 1; newv->val_used = 0; newv->val = (char **)Malloc(sizeof(char *)); newv->val[0] = NULL; add_var_hash(newv); return(newv); }
int hdr_AddTextHeader( msg_Headers headers, const char * key, const char * value ) { msg_Header header = hdr_FindHeader( headers->text, key ); if( !header ) { header = Calloc( sizeof(struct _msg_Header), 1 ); if( !header ) return 0; header->name = Strdup( key ); if( !header->name ) { Free( header ); return 0; } header->values = slcreate(); if( !header->values ) { del_Header( header ); return 0; } if( !sladd( header->values, value ) ) { del_Header( header ); return 0; } } return ladd( headers->text, header ) != NULL; }
/********************************************************** // Function name : LBSC_Session::GeMaintBaseUserName // Description : // Return type : char* // Argument : const char *szBaseName **********************************************************/ char* LBSC_Session::GeMaintBaseUserName( const char *szBaseName ) { // a aplicacao DEVE deletar o buffer retornado. if( !szBaseName ){ NRETURN( LBSE_BADARG ); } // regiao critica para a lista de bases reservadas C_SessCritSect cCS3( this, CRITSECT3 ); if( _pclMaintBaseList ){ // verificar se a base esta' reservada para manutencao LBSC_MaintBase cMaintBaseAux( szBaseName, "", NULL ); if( _pclMaintBaseList->Find( &cMaintBaseAux, 0, TRUE ) ){ // a base esta' reservada. LBSC_MaintBase *pMaintBase = _pclMaintBaseList->Current(); char *szRet; szRet = Strdup( (char*) pMaintBase->strUserName ); if( szRet ){ SetError( LBS_OK ); return( szRet ); } } else { // a base nao esta' reservada NRETURN( LBSE_BASENOTRESERVED ); } } NRETURN( LBSE_NOMEMORY ); }
/*! * \brief if necessary libraries are present this function converts the input * to utf8 and normalizes it. * \param s The input string * \return Returns a newly allocated zero-terminated string. */ char *normalize( char *s ) { char *buf; #ifdef HAVE_LIBIDN int bufsize, rc; char *utf8; traceLog(LOG_INFO,"Doing stringprep on %s", s); /* stringprep_locale_charset(); */ utf8 = stringprep_locale_to_utf8(s); bufsize = strlen(utf8) * 2; buf = (char *) Malloc ( bufsize * sizeof( char ) ); strcpy(buf,utf8); rc = stringprep (buf, bufsize, 0, stringprep_nameprep); if (rc != STRINGPREP_OK) { traceLog(LOG_INFO,"Stringprep failed with rc %d", rc); Free(buf); buf = utf8; } else Free(utf8); traceLog(LOG_INFO,"result %s", buf); #else buf = Strdup(s); #endif return buf; }
static void process_altavista_cookie(const char *cookie, char **new_cookie) { CookieNodeType *cl; ustring ucookie = USTRING_INITIALIZER; *new_cookie = NULL; cl = parse_cookies(cookie); if(!cl) { nag("Error parsing cookies\n"); goto cleanup; } delete_cookie(&cl, "AV_ALL"); if(set_cookie_value(&cl, " AV_PG", "1")) { nag("Error setting new cookie value\n"); goto cleanup; } if(rebuild_cookie(cl, &ucookie)) { nag("Error rebuilding cookie\n"); goto cleanup; } *new_cookie = Strdup(ucookie.string); cleanup: delete_cookie_list(cl); reset_ustring(&ucookie); }
FMGUI_Dir * FMGUI_OpenDir(const char *path) { FMGUI_Dir *dir; dir = (FMGUI_Dir *) Malloc(sizeof(FMGUI_Dir)); dir->ents = NULL; dir->nents = 0; #ifdef _WIN32 { char dpath[FMGUI_PATHNAME_MAX]; HANDLE h; WIN32_FIND_DATA fdata; DWORD rv; Strlcpy(dpath, path, sizeof(dpath)); Strlcat(dpath, "\\*", sizeof(dpath)); if ((h = FindFirstFile(dpath, &fdata))==INVALID_HANDLE_VALUE) { ReportError1("Invalid file handle (%d)", (int)GetLastError()); goto fail; } while (FindNextFile(h, &fdata) != 0) { dir->ents = Realloc(dir->ents, (dir->nents+1)*sizeof(char *)); dir->ents[dir->nents++] = Strdup(fdata.cFileName); } rv = GetLastError(); FindClose(h); if (rv != ERROR_NO_MORE_FILES) { ReportError1("FindNextFileError (%lu)", rv); goto fail; } } #else /* !_WIN32 */ { DIR *dp; struct dirent *dent; if ((dp = opendir(path)) == NULL) { ReportError2("%s: Failed to open directory (%s)", path, strerror(errno)); goto fail; } while ((dent = readdir(dp)) != NULL) { dir->ents = (char **) Realloc(dir->ents, (dir->nents+1)*sizeof(char *)); dir->ents[dir->nents++] = strdup(dent->d_name); } closedir(dp); } #endif /* _WIN32 */ return (dir); fail: Free(dir); return (NULL); }
/* Function: Plan7SetDescription() * * Purpose: Change the description line of a Plan7 HMM. Convenience function. * * Note: Trailing whitespace and \n's are chopped. */ void Plan7SetDescription(struct plan7_s *hmm, char *desc) { if (hmm->desc != NULL) free(hmm->desc); hmm->desc = Strdup(desc); StringChop(hmm->desc); hmm->flags |= PLAN7_DESC; }
/* Function: Plan7SetCtime() * Date: SRE, Wed Oct 29 11:53:19 1997 [TWA 721 over the Atlantic] * * Purpose: Set the ctime field in a new HMM to the current time. */ void Plan7SetCtime(struct plan7_s *hmm) { time_t date = time(NULL); if (hmm->ctime != NULL) free(hmm->ctime); hmm->ctime = Strdup(ctime(&date)); StringChop(hmm->ctime); }
static Str make_cookie(struct cookie *cookie) { Str tmp = Strdup(cookie->name); Strcat_char(tmp, '='); Strcat(tmp, cookie->value); return tmp; }