void SpoolName(const char *const sdir, char *sp, size_t size, int flag, int serial, time_t when) { char sname[64]; char dstr[32]; struct tm *ltp; if ((when == (time_t) 0) || (when == (time_t) -1)) (void) time(&when); ltp = localtime(&when); if (ltp == NULL) { /* impossible */ (void) Strncpy(dstr, "19700101-000000", size); } else { (void) strftime(dstr, sizeof(dstr), "%Y%m%d-%H%M%S", ltp); } (void) Strncpy(sp, sdir, size); (void) sprintf(sname, "/%c-%010u-%04x-%s", flag, (unsigned int) getpid(), (serial % (16 * 16 * 16 * 16)), dstr ); (void) Strncat(sp, sname, size); } /* SpoolName */
/* Converts a timestamp into a recent date string ("May 27 06:33"), or an * old (or future) date string (i.e. "Oct 27 1996"). */ void LsDate(char *dstr, size_t dsiz, time_t ts) { struct tm t; if (ts == kModTimeUnknown) { (void) Strncpy(dstr, " ", dsiz); return; } if (Localtime(ts, &t) == NULL) { (void) Strncpy(dstr, "Jan 0 1900", dsiz); return; } if ((ts > gNowPlus1Hr) || (ts < gNowMinus6Mon)) { #ifdef HAVE_SNPRINTF (void) snprintf(dstr, dsiz, #else (void) sprintf(dstr, #endif "%s %2d %4d", gLsMon[t.tm_mon], t.tm_mday, t.tm_year + 1900 ); } else {
/* * Convert the options structure to a string. */ void opt_options_to_string(struct tftp_opt *options, char *string, int len) { int i, index = 0; for (i = 2; i < OPT_NUMBER; i++) { if (options[i].specified && options[i].enabled) { if ((index + strlen(options[i].option) + 2) < len) { Strncpy(string + index, options[i].option, len - index); index += strlen(options[i].option); Strncpy(string + index, ": ", len - index); index += 2; } if ((index + strlen(options[i].value) + 2) < len) { Strncpy(string + index, options[i].value, len - index); index += strlen(options[i].value); Strncpy(string + index, ", ", len - index); index += 2; } } } if (index > 0) string[index - 2] = 0; else string[0] = 0; }
// 编程 : 陈永华 2005-9-6 11:16:09 int CSvrLink::UpdateRegFunction(unsigned int reqtype, char *rtname, char *programmer, int priority, bool bstop) { RP_REGFUNC prf; prf.reqtype = htonl(reqtype); Strncpy(prf.rtname,rtname,sizeof(prf.rtname)); Strncpy(prf.programmer,programmer,sizeof(prf.programmer)); if (priority>PRIORITIES) priority = PRIORITIES; else if (priority<1) priority = 1; prf.priority = htonl(priority); prf.bStop = bstop; return(SendMsg(MT_REGFUNC,sizeof(RP_REGFUNC),&prf)); }
static int MakeLiteral(Char *str, int len, Char addlit) { int i, addlitlen = 0; Char *addlitptr = 0; if (addlit) { if ((addlit & LITERAL) != 0) { addlitptr = litptr + (addlit & ~LITERAL) * LIT_FACTOR; addlitlen = Strlen(addlitptr); } else { addlitptr = &addlit; addlitlen = 1; } for (i = 0; i < litlen; i += LIT_FACTOR) if (!Strncmp(addlitptr, litptr + i, addlitlen) && !Strncmp(str, litptr + i + addlitlen, len) && litptr[i + addlitlen + len] == 0) return (i / LIT_FACTOR) | LITERAL; } else { addlitlen = 0; for (i = 0; i < litlen; i += LIT_FACTOR) if (!Strncmp(str, litptr + i, len) && litptr[i + len] == 0) return (i / LIT_FACTOR) | LITERAL; } if (litlen + addlitlen + len + 1 + (LIT_FACTOR - 1) > litalloc) { Char *newlitptr; int add = 256; while (len + addlitlen + 1 + (LIT_FACTOR - 1) > add) add *= 2; newlitptr = xrealloc(litptr, (litalloc + add) * sizeof(Char)); if (!newlitptr) return '?'; litptr = newlitptr; litalloc += add; if (addlitptr && addlitptr != &addlit) addlitptr = litptr + (addlit & ~LITERAL) * LIT_FACTOR; } i = litlen / LIT_FACTOR; if (i >= LITERAL || i == CHAR_DBWIDTH) return '?'; if (addlitptr) { Strncpy(litptr + litlen, addlitptr, addlitlen); litlen += addlitlen; } Strncpy(litptr + litlen, str, len); litlen += len; do litptr[litlen++] = 0; while (litlen % LIT_FACTOR); return i | LITERAL; }
/* Tries to generate a bookmark abbreviation based off of the hostname. */ void DefaultBookmarkName(char *dst, size_t siz, char *src) { char str[128]; const char *token; const char *cp; (void) STRNCPY(str, src); /* Pick the first "significant" part of the hostname. Usually * this is the first word in the name, but if it's something like * ftp.unl.edu, we would want to choose "unl" and not "ftp." */ token = str; if ((token = strtok(str, ".")) == NULL) token = str; else if ((ISTRNEQ(token, "ftp", 3)) || (ISTRNEQ(token, "www", 3))) { if ((token = strtok(NULL, ".")) == NULL) token = ""; } for (cp = token; ; cp++) { if (*cp == '\0') { /* Token was all digits, like an IP address perhaps. */ token = ""; } if (!isdigit((int) *cp)) break; } (void) Strncpy(dst, token, siz); } /* DefaultBookmarkName */
/* Converts a pre-loaded Bookmark structure into a RFC 1738 * Uniform Resource Locator. */ void BookmarkToURL(BookmarkPtr bmp, char *url, size_t urlsize) { char pbuf[32]; /* //<user>:<password>@<host>:<port>/<url-path> */ /* Note that if an absolute path is given, * you need to escape the first entry, i.e. /pub -> %2Fpub */ (void) Strncpy(url, "ftp://", urlsize); if (bmp->user[0] != '\0') { (void) Strncat(url, bmp->user, urlsize); if (bmp->pass[0] != '\0') { (void) Strncat(url, ":", urlsize); (void) Strncat(url, "PASSWORD", urlsize); } (void) Strncat(url, "@", urlsize); } (void) Strncat(url, bmp->name, urlsize); if (bmp->port != 21) { (void) sprintf(pbuf, ":%u", (unsigned int) bmp->port); (void) Strncat(url, pbuf, urlsize); } if (bmp->dir[0] == '/') { /* Absolute URL path, must escape first slash. */ (void) Strncat(url, "/%2F", urlsize); (void) Strncat(url, bmp->dir + 1, urlsize); (void) Strncat(url, "/", urlsize); } else if (bmp->dir[0] != '\0') { (void) Strncat(url, "/", urlsize); (void) Strncat(url, bmp->dir, urlsize); (void) Strncat(url, "/", urlsize); } } /* BookmarkToURL */
static int GetSymLinkInfo(char *dst, size_t siz, char *rLink) { LineList fileList; char *cp; int result; result = -1; *dst = '\0'; InitLineList(&fileList); ListToMemory(&fileList, "LIST", kListDirNamesOnlyMode, rLink); if (fileList.first != NULL) { cp = fileList.first->line; *cp++ = '\0'; for (cp += strlen(cp) - 1; ; cp--) { if (*cp == '\0') goto done; if ((cp[0] == '>') && (cp[-1] == '-')) break; } (void) Strncpy(dst, cp + 2, siz); result = 0; } done: DisposeLineListContents(&fileList); return (result); } /* GetSymLinkInfo */
/* Print the command shell's prompt. */ void MakePrompt(char *dst, size_t dsize) { char acwd[64]; # ifdef HAVE_SNPRINTF if (gConn.loggedIn != 0) { AbbrevStr(acwd, gRemoteCWD, 25, 0); snprintf(dst, dsize, "%sncftp%s %s %s>%s ", tcap_boldface, tcap_normal, acwd, tcap_boldface, tcap_normal); } else { snprintf(dst, dsize, "%sncftp%s> ", tcap_boldface, tcap_normal); } # else /* HAVE_SNPRINTF */ (void) Strncpy(dst, tcap_boldface, dsize); (void) Strncat(dst, "ncftp", dsize); (void) Strncat(dst, tcap_normal, dsize); if (gConn.loggedIn != 0) { AbbrevStr(acwd, gRemoteCWD, 25, 0); (void) Strncat(dst, " ", dsize); (void) Strncat(dst, acwd, dsize); (void) Strncat(dst, " ", dsize); } (void) Strncat(dst, tcap_boldface, dsize); (void) Strncat(dst, ">", dsize); (void) Strncat(dst, tcap_normal, dsize); (void) Strncat(dst, " ", dsize); # endif /* HAVE_SNPRINTF */ } /* MakePrompt */
/* This does "tilde-expansion." Examples: * ~/pub --> /usr/gleason/pub * ~pdietz/junk --> /usr/pdietz/junk */ void ExpandTilde(char *pattern, size_t siz) { string pat; char *cp, *rest, *firstent; struct passwd *pw; if ((pattern[0] == '~') && (isalnum(pattern[1]) || (pattern[1] == '/') || (pattern[1] == '\0'))) { STRNCPY(pat, pattern); if ((cp = strchr(pat, '/')) != NULL) { *cp = 0; rest = cp + 1; /* Remember stuff after the ~/ part. */ } else { rest = NULL; /* Was just a ~ or ~username. */ } if (pat[1] == '\0') { /* Was just a ~ or ~/rest type. */ firstent = gUserInfo.home; } else { /* Was just a ~username or ~username/rest type. */ pw = getpwnam(pat + 1); if (pw != NULL) firstent = pw->pw_dir; else return; /* Bad user -- leave it alone. */ } Strncpy(pattern, firstent, siz); if (rest != NULL) { Strncat(pattern, "/", siz); Strncat(pattern, rest, siz); } } } /* ExpandTilde */
int router_set_dup_flow(void * message,void * policy) { int ret; MSG_HEAD * msg_head; DISPATCH_POLICY * msg_policy=(DISPATCH_POLICY *)policy; ROUTE_RULE * rule; char * target; if(policy==NULL) return -EINVAL; if(message==NULL) return -EINVAL; msg_head=message_get_head(message); Memset(msg_head->route,0,DIGEST_SIZE); if(msg_policy->newname!=NULL) Strncpy(msg_head->route,msg_policy->newname,DIGEST_SIZE); msg_head->ljump=1; msg_head->rjump=0; msg_head->flow=MSG_FLOW_DELIVER; // msg_head->flag=msg_policy->flag; Memset(msg_head->receiver_uuid,0,DIGEST_SIZE); message_set_policy(message,policy); return 1; }
/* int match_message_record(void * match_rule,void * message) { int ret; MSG_HEAD * msg_head=get_message_head(message); if(msg_head==NULL) return -EINVAL; void * record_template = load_record_template(msg_head->record_type); if(record_template==NULL) return -EINVAL; MATCH_RULE * rule=(MATCH_RULE *)match_rule; char buffer[1024]; void * record; ret=message_comp_elem_text(message,rule->seg,0,rule->value); return ret; } */ int router_set_aspect_flow(void * message,void * policy) { int ret; MSG_HEAD * msg_head; DISPATCH_POLICY * msg_policy=(DISPATCH_POLICY *)policy; ROUTE_RULE * rule; char * target; if(policy==NULL) return -EINVAL; if(message==NULL) return -EINVAL; msg_head=message_get_head(message); if(!(msg_head->flow&MSG_FLOW_ASPECT)) { Memset(msg_head->route,0,DIGEST_SIZE); Strncpy(msg_head->route,msg_policy->newname,DIGEST_SIZE); msg_head->ljump=1; msg_head->rjump=1; msg_head->flow=msg_policy->type; } Memset(msg_head->receiver_uuid,0,DIGEST_SIZE); message_set_policy(message,policy); return 1; }
void wipdecode(const char *string, char *outstr, size_t maxout) { char *ptr, *tmptr, *savptr; char ch; char tempstr[BUFSIZ], variable[BUFSIZ]; int nsig, nopen; double arg; LOGICAL error; ptr = (char *)string; if (Strchr(string, ESC) != (char *)NULL) { arg = wipgetvar("nsig", &error); nsig = NINT(arg); /* Tells how to format a user variable. */ tmptr = tempstr; while (*ptr) { if (*ptr != ESC) { *tmptr++ = *ptr++; /* Just copy the character. */ continue; /* Get the next character. */ } /* At this point an ESC character has been found. */ ch = *ptr++; /* save the ESC character. */ if (*ptr != '[') { /* No user variable here, so just store... */ *tmptr++ = ch; /* ...the two characters and continue. */ *tmptr++ = *ptr++; /* This is so "\\" gets passed. */ continue; /* Get the next character. */ } /* At this point a user variable flag has been found. */ ptr++; /* Increment ptr past the '['. */ savptr = variable; /* Set up user variable name pointer. */ nopen = 1; /* Initialize the number of open '['s. */ while ((*ptr) && (nopen)) { /* Get user variable name. */ if (*ptr == '[') nopen++; if (*ptr == ']') nopen--; if (nopen) *savptr++ = *ptr++; } if (*ptr != Null) ptr++; /* Skip over last ']' */ *savptr = Null; /* Skip last ']'; add terminating Null. */ if (wipisstring(variable)) { /* User string variable. */ savptr = wipgetstring(variable); /* Find string variable. */ if (savptr == (char *)NULL) savptr = ""; /* Error check. */ } else { /* Standard user variable. */ arg = wipevaluate(variable, &error); /* Find user variable. */ savptr = wipfpfmt(arg, nsig); /* Format the value. */ } while ((*savptr != Null) && (isspace(*savptr))) savptr++; /* Strip off leading blanks. */ while (*savptr) *tmptr++ = *savptr++; /* Include the value. */ } /* End of "while (*ptr)" loop. */ *tmptr = Null; /* Terminate the string with a Null. */ ptr = tempstr; /* Assign the work pointer to this string. */ } /* End of "(domacs == TRUE)" if block. */ if (Strlen(ptr) >= maxout) wipoutput(stderr, "Decoded string overflows output string size.\n"); (void)Strncpy(outstr, ptr, maxout); outstr[maxout-1] = Null; /* Make sure it is Null terminated. */ return; }
int main() { char p[10]="*********"; char q[10]="*********"; Strncpy(p,"12345",3); printf("%s\n",p); Strncpy(q,"12345",7); printf("%s\n",q); printf("q[5]=%d\n",q[5]); printf("q[6]=%d\n",q[6]); printf("q[7]=%d\n",q[7]); printf("q[8]=%d\n",q[8]); printf("q[9]=%d\n",q[9]); return 0; }
/* * Set an option by name in the structure. * name is the name of the option as in tftp_def.c. * name is it's new value, that must comply with the rfc's. * When setting an option, it is marked as specified. * */ int opt_set_options(struct tftp_opt *options, char *name, char *value) { int i; for (i = 0; i < OPT_NUMBER; i++) { if (strncasecmp(name, options[i].option, OPT_SIZE) == 0) { options[i].specified = 1; if (value) Strncpy(options[i].value, value, VAL_SIZE); else Strncpy(options[i].value, tftp_default_options[i].value, VAL_SIZE); return OK; } } return ERR; }
int symm_crypt_init(void * sub_proc,void * para) { int ret; // add youself's plugin init func here struct init_struct * init_para=para; if(para==NULL) return -EINVAL; Memset(passwd,0,DIGEST_SIZE); Strncpy(passwd,init_para->passwd,DIGEST_SIZE); return 0; }
int arg_parse(const char *command, char ***argv) { char **myargv = NULL; int argc = 0; char mycommand[4096]; char *start, *end; char oldend; *argv = NULL; if (Strncpy(mycommand, command, 4096) == -1) return -1; myargv = (char **) safe_malloc((MAX_PARSE_ARGS + 2) * sizeof(char *)); memset(myargv, 0, (MAX_PARSE_ARGS + 2) * sizeof(char *)); myargv[0] = (char *) 0x123456; /* Integrity checker */ myargv++; start = mycommand; while (start && *start) { while (*start && isspace((int) (unsigned char) *start)) start++; if (*start == '"') { start++; end = strchr(start, '"'); } else if (*start == '\'') { start++; end = strchr(start, '\''); } else if (!*start) { continue; } else { end = start + 1; while (*end && !isspace((int) (unsigned char) *end)) { end++; } } if (!end) { arg_parse_free(myargv); return -1; } if (argc >= MAX_PARSE_ARGS) { arg_parse_free(myargv); return -1; } oldend = *end; *end = '\0'; myargv[argc++] = strdup(start); if (oldend) start = end + 1; else start = end; } myargv[argc + 1] = 0; *argv = myargv; return argc; }
int CSvrLink::SetBUError(int errcode, char *szErrMsg) { unsigned char sbuf[MAXMSG]; RP_SETERROR *pse = (RP_SETERROR *)sbuf; unsigned short len; len = strlen(szErrMsg); pse->iErrorCode = htonl(errcode); if (len>255) len = 255; Strncpy(pse->szmsg,szErrMsg,len+1); return(SendMsg(MT_SETERROR,sizeof(RP_SETERROR)+len,sbuf)); }
int opt_get_multicast(struct tftp_opt *options, char *addr, int *port, int *mc) { char *token = NULL; char *string = NULL; char *temp = NULL; if (options[OPT_MULTICAST].enabled && options[OPT_MULTICAST].specified) { string = strdup(options[OPT_MULTICAST].value); /* get first argument */ if ((token = strtok_r(string, ",", &temp)) == NULL) { free(string); return ERR; } else Strncpy(addr, token, IPADDRLEN); /* get second argument */ if ((token = strtok_r(NULL, ",", &temp)) == NULL) { free(string); return ERR; } else { *port = atoi(token); if ((*port < 0) || (*port > 65536)) { free(string); return ERR; } } /* get third (last) argument */ if ((token = strtok_r(NULL, ",", &temp)) == NULL) { free(string); return ERR; } else { *mc = atoi(token); if ((*mc != 0) && (*mc != 1)) { free(string); return ERR; } } free(string); return *mc; } return ERR; }
static siteptr FindNetrcSite(char *host, int exact) { register siteptr s, s2; string str, host2; (void) Strncpy(host2, host); StrLCase(host2); /* see if 'host' is in our list of favorite sites (in NETRC). */ for (s = firstsite; s != NULL; s2=s->next, s=s2) { (void) Strncpy(str, s->name); StrLCase(str); if (exact) { if (strcmp(str, host2) == 0) return s; } else { if (strstr(str, host2) != NULL) return s; } } return NULL; } /* FindNetrcSite */
int _routine_dispatch_init() { int ret; ret=Galloc0(&dispatch_proc,sizeof(ROUTINE)); if(ret<0) return ret; Strncpy(dispatch_proc->name,"dispatch_proc",DIGEST_SIZE); ret=comp_proc_uuid(myproc_context->uuid,dispatch_proc->name,dispatch_proc->uuid); if(ret<0) return -EINVAL; return 0; }
int _routine_manage_init() { int ret; ret=Galloc0(&manage_proc,sizeof(ROUTINE)); if(ret<0) return ret; Strncpy(manage_proc->name,"manage_proc",DIGEST_SIZE); ret=comp_proc_uuid(myproc_context->uuid,manage_proc->name,manage_proc->uuid); if(ret<0) return -EINVAL; return 0; }
/* * Format the content of the options structure (this is the content of a * read or write request) to a string. */ void opt_request_to_string(struct tftp_opt *options, char *string, int len) { int i, index = 0; for (i = 0; i < 2; i++) { if ((index + strlen(options[i].option) + 2) < len) { Strncpy(string + index, options[i].option, len - index); index += strlen(options[i].option); Strncpy(string + index, ": ", len - index); index += 2; } if ((index + strlen(options[i].value) + 2) < len) { Strncpy(string + index, options[i].value, len - index); index += strlen(options[i].value); Strncpy(string + index, ", ", len - index); index += 2; } } opt_options_to_string(options, string + index, len - index); }
int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) { struct sockaddr_in *sin = (struct sockaddr_in *)sa; struct hostent *he; if (sin->sin_family != AF_INET || salen != sizeof(struct sockaddr_in)) return EAI_FAMILY; if (serv != NULL) { Snprintf(serv, servlen, "%d", ntohs(sin->sin_port)); return 0; } if (host) { if (flags & NI_NUMERICHOST) { Strncpy(host, inet_ntoa(sin->sin_addr), hostlen); return 0; } else { he = gethostbyaddr((char *)&sin->sin_addr, sizeof(struct in_addr), AF_INET); if (he == NULL) { if (flags & NI_NAMEREQD) return EAI_NONAME; Strncpy(host, inet_ntoa(sin->sin_addr), hostlen); return 0; } assert(he->h_name); Strncpy(host, he->h_name, hostlen); return 0; } } return 0; }
static recentsite *FindRecentSite(char *host, int exact) { register recentsite *r; register int i; string str, host2; (void) Strncpy(host2, host); StrLCase(host2); /* see if 'host' is in our list of favorite sites (in recent-log). */ for (i=0; i<nRecents; i++) { r = &recents[i]; (void) Strncpy(str, r->name); StrLCase(str); if (exact) { if (strcmp(str, host2) == 0) return r; } else { if (strstr(str, host2) != NULL) return r; } } return NULL; } /* FindRecentSite */
/* From the pathname given in remoteName, get a local filename for * the current local directory. Then open the actual file for writing. */ static void GetLocalName(GetOptionsPtr gopt, string localName) { char *cp; if ((cp = gopt->lName) == NULL) { /* We're supposed to pick it. */ cp = strrchr(gopt->rName, '/'); if (cp == NULL) cp = gopt->rName; else cp++; } gopt->lName = Strncpy(localName, cp, sizeof(string)); } /* GetLocalName */
/* * Return "value" for a given option name in the given option * structure. */ int opt_get_options(struct tftp_opt *options, char *name, char *value) { int i; for (i = 0; i < OPT_NUMBER; i++) { if (strncasecmp(name, options[i].option, OPT_SIZE) == 0) { if (options[i].enabled) Strncpy(value, options[i].value, VAL_SIZE); else return ERR; return OK; } } return ERR; }
int route_push_site_str(void * message,char * name) { int len; int ret; BYTE buffer[DIGEST_SIZE]; Memset(buffer,0,DIGEST_SIZE); len=Strnlen(name,DIGEST_SIZE*2); if(len==DIGEST_SIZE*2) { ret=digest_to_uuid(name,buffer); if(ret<0) return ret; } else { if(len>DIGEST_SIZE/4*3) return -EINVAL; Strncpy(buffer,name,DIGEST_SIZE/4*3); } return route_push_site(message,buffer); }
int router_set_local_route(void * message,void * policy) { int ret; MSG_HEAD * msg_head; DISPATCH_POLICY * msg_policy=(DISPATCH_POLICY *)policy; ROUTE_RULE * rule; char * target; if(policy==NULL) return -EINVAL; if(message==NULL) return -EINVAL; msg_head=message_get_head(message); Memset(msg_head->route,0,DIGEST_SIZE); Strncpy(msg_head->route,msg_policy->name,DIGEST_SIZE); msg_head->ljump=1; msg_head->flow=msg_policy->type; message_set_policy(message,policy); return 1; }
int user_addr_store(void * sub_proc,void * message) { int ret; struct user_address * user_addr; MSG_EXPAND * expand; struct expand_flow_trace * flow_trace; struct login_info * login_data; DB_RECORD * db_record; int trace_offset; ret=message_get_record(message,&login_data,0); if(ret<0) return ret; ret=message_get_define_expand(message,&expand,DTYPE_MSG_EXPAND,SUBTYPE_FLOW_TRACE); if(ret<0) return ret; if(expand==NULL) return -EINVAL; flow_trace=expand->expand; if(flow_trace->record_num<=0) return -EINVAL; trace_offset=DIGEST_SIZE*(flow_trace->record_num-1); db_record=memdb_find_byname(login_data->user,DTYPE_CRYPTO_DEMO,SUBTYPE_USER_ADDR); if(db_record!=NULL) { user_addr=(struct user_address *)db_record->record; if(Memcmp(user_addr->addr,flow_trace->trace_record+trace_offset,DIGEST_SIZE)==0) return 0; memdb_remove_record(db_record); } user_addr=Talloc0(sizeof(struct user_address)); if(user_addr==NULL) return -ENOMEM; Strncpy(user_addr->user,login_data->user,DIGEST_SIZE); Memcpy(user_addr->addr,flow_trace->trace_record+trace_offset,DIGEST_SIZE); memdb_store(user_addr,DTYPE_CRYPTO_DEMO,SUBTYPE_USER_ADDR,login_data->user); return 1; }