int cookie_set_path(cookie c, const char* s) { assert(NULL != c); assert(NULL != s); return cstring_copy(c->path, s); }
/*@only@*/ cstring cstringList_unparseAbbrev (cstringList s) { cstring st = cstring_undefined; if (cstringList_isDefined (s)) { int i; for (i = 0; i < s->nelements; i++) { if (i == 0) { st = cstring_copy (s->elements[i]); } else if (i > 3 && s->nelements > 5) { st = message ("%q, ...", st); break; } else { st = message ("%q, %s", st, s->elements[i]); } } } return st; }
int cookie_set_value(cookie c, const char* s) { assert(NULL != c); assert(NULL != s); return cstring_copy(c->value, s); }
int cookie_set_comment(cookie c, const char* s) { assert(NULL != c); assert(NULL != s); return cstring_copy(c->comment, s); }
int cookie_set_domain(cookie c, const char* s) { assert(NULL != c); assert(NULL != s); return cstring_copy(c->domain, s); }
int dynamic_set_uri(dynamic_page p, const char* value) { assert(NULL != p); assert(NULL != value); return cstring_copy(p->uri, value); }
cstringList cstringList_copy (cstringList s) { cstringList res = cstringList_newPredict (cstringList_size (s)); cstringList_elements (s, el) { res = cstringList_add (res, cstring_copy (el)); } end_cstringList_elements ;
Answer::Answer(bool value, const char * format, ...) { char buffer[1024]; buffer[sizeof(buffer) - 1] = 0; va_list args; va_start(args, format); vsnprintf(buffer, sizeof(buffer) - 1, format, args); va_end(args); _what = cstring_copy(buffer); _value = value; }
int entity_header_set_allow(entity_header eh, const char* value) { assert(NULL != eh); assert(NULL != value); if(!cstring_copy(eh->allow, value)) return 0; entity_header_set_flag(eh, ENTITY_HEADER_ALLOW_SET); return 1; }
int entity_header_set_cache_control(entity_header eh, const char* value) { assert(NULL != eh); assert(NULL != value); if(!cstring_copy(eh->cache_control, value)) return 0; entity_header_set_flag(eh, ENTITY_HEADER_CACHE_CONTROL_SET); return 1; }
int entity_header_set_content_encoding(entity_header eh, const char* value) { assert(NULL != eh); assert(NULL != value); if(!cstring_copy(eh->content_encoding, value)) return 0; entity_header_set_flag(eh, ENTITY_HEADER_CONTENT_ENCODING_SET); return 1; }
int entity_header_set_content_location(entity_header eh, const char* value) { assert(NULL != eh); assert(NULL != value); if(!cstring_copy(eh->content_location, value)) return 0; entity_header_set_flag(eh, ENTITY_HEADER_CONTENT_LOCATION_SET); return 1; }
int entity_header_set_content_range(entity_header eh, const char* value) { assert(NULL != eh); assert(NULL != value); if(!cstring_copy(eh->content_range, value)) return 0; entity_header_set_flag(eh, ENTITY_HEADER_CONTENT_RANGE_SET); return 1; }
cstring cstring_dup(const char* src) { cstring dest = NULL; assert(src != NULL); if( (dest = cstring_new()) != NULL) { if(!cstring_copy(dest, src)) { cstring_free(dest); dest = NULL; } } return dest; }
extern cstring mtTransferAction_unparse (mtTransferAction node) { switch (node->kind) { case MTAK_VALUE: return cstring_copy (node->value); case MTAK_ERROR: if (cstring_isDefined (node->message)) { return message ("error \"%s\"", node->message); } else { return cstring_makeLiteral ("<error>"); } BADDEFAULT; } BADBRANCH; }
/* * The old cookie format is (hopefully) name=value * where value may be quoted. */ int parse_old_cookie(http_request req, const char* input, meta_error e) { cookie c = NULL; cstring name = NULL, value = NULL; if( (name = cstring_new()) == NULL || (value = cstring_new()) == NULL) goto memerr; while(*input != '\0' && *input != '=') { if(!cstring_charcat(name, *input++)) goto memerr; } if(*input != '=') { cstring_free(name); cstring_free(value); return set_http_error(e, HTTP_400_BAD_REQUEST); } input++; /* Skip '=' */ if(!cstring_copy(value, input)) goto memerr; if( (c = cookie_new()) == NULL) goto memerr; if(!cookie_set_name(c, c_str(name)) || !cookie_set_value(c, c_str(value))) goto memerr; cstring_free(name); cstring_free(value); cookie_set_version(c, 0); if(!request_add_cookie(req, c)) { set_os_error(e, errno); cookie_free(c); return 0; } return 1; memerr: cstring_free(name); cstring_free(value); cookie_free(c); return set_os_error(e, ENOMEM); }
void proc_stat_update(proc_stat_t *self, char *data) { char *pos = data; self->pid = strtol(pos,&pos,10); cstring_copy(self->comm, sizeof self->comm, cstring_split_quoted(pos,&pos)); self->state = *cstring_split_at_white(pos,&pos); self->ppid = strtol(pos,&pos,10); self->pgrp = strtol(pos,&pos,10); self->session = strtol(pos,&pos,10); self->tty_nr = strtol(pos,&pos,10); self->tpgid = strtol(pos,&pos,10); self->flags = strtoul(pos,&pos,10); self->minflt = strtoul(pos,&pos,10); self->cminflt = strtoul(pos,&pos,10); self->majflt = strtoul(pos,&pos,10); self->cmajflt = strtoul(pos,&pos,10); self->utime = strtoul(pos,&pos,10); self->stime = strtoul(pos,&pos,10); self->cutime = strtol(pos,&pos,10); self->cstime = strtol(pos,&pos,10); self->priority = strtol(pos,&pos,10); self->nice = strtol(pos,&pos,10); self->unused0 = strtol(pos,&pos,10); self->itrealvalue = strtol(pos,&pos,10); self->starttime = strtoul(pos,&pos,10); self->vsize = strtoul(pos,&pos,10); self->rss = strtol(pos,&pos,10); self->rlim = strtoul(pos,&pos,10); self->startcode = strtoul(pos,&pos,10); self->endcode = strtoul(pos,&pos,10); self->startstack = strtoul(pos,&pos,10); self->kstkesp = strtoul(pos,&pos,10); self->kstkeip = strtoul(pos,&pos,10); self->signal = strtoul(pos,&pos,10); self->blocked = strtoul(pos,&pos,10); self->sigignore = strtoul(pos,&pos,10); self->sigcatch = strtoul(pos,&pos,10); self->wchan = strtoul(pos,&pos,10); self->nswap = strtoul(pos,&pos,10); self->cnswap = strtoul(pos,&pos,10); self->exit_signal = strtol(pos,&pos,10); self->processor = strtol(pos,&pos,10); }
cstring cstring_right(cstring src, size_t n) { cstring dest; /* Get mem */ if( (dest = cstring_new()) == NULL || !cstring_extend(dest, n)) { cstring_free(dest); dest = NULL; } else { const char* s = src->data; size_t cb = strlen(s); /* Copy string */ if(cb > n) s += cb - n; cstring_copy(dest, s); } return dest; }
cstring osd_fixDefine (cstring x) { /*@access cstring@*/ llassert (cstring_isDefined (x)); # ifdef UNIX if (strchr (x, '\'') != NULL) { /* ** If there is a single quote, check for <ident>='<string>' and ** produce <ident>=<string> */ char *eqs = strchr (x, '='); if (eqs != NULL) { if (eqs[1] == '\'') { char *endqu = strrchr (x, '\''); if (endqu != NULL) { if (*(endqu - 1) != '\\') { if (*(endqu + 1) == '\0') { cstring res; cstring def; *endqu = '\0'; def = cstring_fromChars (eqs + 2); eqs[1] = '\0'; res = cstring_concat (cstring_fromChars (x), def); return res; } } } } } } # endif return cstring_copy (x); /*@noaccess cstring@*/ }
cstring cstringList_unparseSep (cstringList s, cstring sep) { cstring st = cstring_undefined; if (cstringList_isDefined (s)) { int i; for (i = 0; i < s->nelements; i++) { if (i == 0) { st = cstring_copy (s->elements[i]); } else st = message ("%q%s%s", st, sep, s->elements[i]); } } return st; }
static /*@only@*/ cstring printTypeName2 (typeNameNode n) { cstring s = cstring_undefined; sortNode sn; lsymbol lclSort; ltoken err; if (n != (typeNameNode) 0) { if (n->isTypeName) { /* does not process opForm renaming, pass on to LSL and hope that it works for now. */ typeNamePack p = n->typename; llassert (p != NULL); /* get the LCL type, assume LCL type has already been mentioned. */ lclSort = lclTypeSpecNode2sort (p->type); lclSort = sort_getUnderlying (lclSort); /* lclsource = LCLSLScanSource (); */ if (!sort_isValidSort (lclSort)) { err = lclTypeSpecNode_errorToken (p->type); /* errorShowPoint (inputStream_thisLine (lclsource), ltoken_getCol (err)); */ lclerror (err, message ("Unrecognized type in uses: %q", typeNameNode_unparse (n))); } else { /* ** Below is necessary because this is one place where an LCL mutable ** type name is mapped directly into its value sort, not obj sort. ** Allows us to support only one qualifying "obj", rather ** than "val" as well. */ lclSort = typeExpr2ptrSort (lclSort, p->abst); lclSort = sort_makeVal (lclSort); /* ** Check that lclSort is not a HOFSort ... ** Propagation of HOFSort should stop here. */ if (sort_isHOFSortKind (lclSort)) { err = lclTypeSpecNode_errorToken (p->type); lclfatalerror (err, cstring_makeLiteral ("LCL uses cannot handle higher-order types")); } if (p->isObj) lclSort = sort_makeObj (lclSort); /* if (!p->isObj) { lclSort = sort_makeVal (lclSort); } */ sn = sort_lookup (lclSort); s = cstring_copy (cstring_fromChars (lsymbol_toChars (sn->name))); /* s = string_paste (s, AbstDeclaratorNode_unparse (p->abst)); */ } } else { /* s = OpFormNode_unparse (n->opform); */ if (n->opform != 0)
int main(void) { cstring s, dest, *pstr; int rc; const char* start = "This is a string"; const char* end = start + strlen(start); char longstring[10000]; size_t i, nelem = 100; memset(longstring, 'A', sizeof(longstring)); longstring[sizeof(longstring) - 1] = '\0'; for(i = 0; i < nelem; i++) { s = cstring_new(); assert(s != NULL); rc = cstring_copy(s, "Hello"); assert(rc == 1); rc = cstring_compare(s, "Hello"); assert(rc == 0); rc = cstring_compare(s, "hello"); assert(rc != 0); rc = cstring_concat(s, ", world"); assert(rc == 1); rc = cstring_compare(s, "Hello, world"); assert(rc == 0); rc = cstring_concat(s, longstring); assert(rc == 1); rc = cstring_charcat(s, 'A'); assert(rc == 1); cstring_recycle(s); rc = cstring_concat(s, longstring); assert(rc == 1); rc = cstring_concat2(s, longstring, longstring); assert(rc == 1); rc = cstring_concat3(s, longstring, longstring, longstring); assert(rc == 1); /* Test strpcat */ cstring_recycle(s); rc = cstring_pcat(s, start, end); assert(rc == 1); rc = cstring_compare(s, start); assert(rc == 0); /* Test cstring_left() */ cstring_copy(s, "hello, world"); dest = cstring_left(s, 5); rc = cstring_compare(dest, "hello"); assert(rc == 0); cstring_free(dest); /* Test cstring_left() with short strings */ dest = cstring_left(s, 5000); rc = cstring_compare(dest, "hello, world"); assert(rc == 0); cstring_free(dest); /* cstring_right() */ cstring_copy(s, "hello, world"); dest = cstring_right(s, 5); rc = cstring_compare(dest, "world"); assert(rc == 0); cstring_free(dest); dest = cstring_right(s, 5000); rc = cstring_compare(dest, "hello, world"); assert(rc == 0); cstring_free(dest); /* cstring_substring */ cstring_copy(s, "hello, world"); dest = cstring_substring(s, 0, 5); rc = cstring_compare(dest, "hello"); assert(rc == 0); cstring_free(dest); dest = cstring_substring(s, 1, 5); rc = cstring_compare(dest, "ello"); assert(rc == 0); cstring_free(dest); dest = cstring_substring(s, 7, 12); rc = cstring_compare(dest, "world"); assert(rc == 0); cstring_free(dest); /* cstring_reverse */ cstring_copy(s, "hello, world"); cstring_reverse(s); rc = cstring_compare(s, "dlrow ,olleh"); assert(rc == 0); /* cstring_strip */ cstring_copy(s, " a b c d e f "); cstring_strip(s); rc = cstring_compare(s, "a b c d e f"); assert(rc == 0); cstring_upper(s); rc = cstring_compare(s, "A B C D E F"); assert(rc == 0); cstring_lower(s); rc = cstring_compare(s, "a b c d e f"); assert(rc == 0); cstring_free(s); /* cstring_split() */ rc = cstring_split(&pstr, "foo bar baz", " "); assert(rc == 3); cstring_multifree(pstr, rc); mem_free(pstr); rc = cstring_split(&pstr, " foo bar baz", " "); assert(rc == 3); cstring_multifree(pstr, rc); mem_free(pstr); rc = cstring_split(&pstr, " foo bar baz ", " "); assert(rc == 3); cstring_multifree(pstr, rc); mem_free(pstr); rc = cstring_split(&pstr, " foo ", " "); assert(rc == 1); cstring_multifree(pstr, rc); mem_free(pstr); } return 0; }
cstring osd_outputPath (cstring filename) { # if defined (UNIX) || defined (OS2) char *rel_buffer; char *rel_buf_p; cstring cwd_p = osd_cwd; char *path_p; int unmatched_slash_count = 0; size_t filename_len = cstring_length (filename); llassertretval (filename_len > 0, filename); /*@access cstring@*/ path_p = filename; rel_buffer = (char *) dmalloc (filename_len); rel_buf_p = rel_buffer; *rel_buf_p = '\0'; if (cwd_p == NULL) { /* Need to prevent recursive assertion failures */ return cstring_copy (filename); } llassert (cwd_p != NULL); llassert (path_p != NULL); while ((*cwd_p != '\0') && (*cwd_p == *path_p)) { cwd_p++; path_p++; } if ((*cwd_p == '\0') && (*path_p == '\0' || osd_isConnectChar (*path_p))) /* whole pwd matched */ { if (*path_p == '\0') /* input *is* the current path! */ { cstring_free (rel_buffer); return cstring_makeLiteral ("."); } else { cstring_free (rel_buffer); return cstring_fromCharsNew (path_p + 1); } } else { /* drl 2002-10/14 I had to put this code back*/ /* the case that needs it is when splint is given an absolute path name of a file outside of the current directory and the subdirectories below the current directory. e.g. cd /home/; splint /tmp/prog.c */ /* evans 2002-02-05 This is horrible code, which I've removed. I couldn't find any ** test cases that need it, so I hope I'm not breaking anything. */ /*#if 0*/ if (*path_p != '\0') { --cwd_p; --path_p; while (cwd_p >= osd_cwd && !osd_isConnectChar (*cwd_p)) /* backup to last slash */ { --cwd_p; --path_p; } cwd_p++; path_p++; unmatched_slash_count++; } /* Find out how many directory levels in cwd were *not* matched. */ while (*cwd_p != '\0') { if (osd_isConnectChar (*cwd_p++)) unmatched_slash_count++; } /* Now we know how long the "short name" will be. Reject it if longer than the input. */ if (unmatched_slash_count * 3 + strlen (path_p) >= filename_len) { cstring_free (rel_buffer); /* fprintf (stderr, "Returning filename: %s [%p]\n", filename); */ return cstring_copy (filename); } /*drl 10-14-2002 end previously removed code */ /*#endif*/ /* For each of them, put a `../' at the beginning of the short name. */ while (unmatched_slash_count-- > 0) { /* Give up if the result gets to be longer than the absolute path name. */ char * temp_rel_buf_p; /*drl This comment is necessary because for some reason Splint does not realize that the pasts where rel_buf_p is released do not reach here*/ /*@-usereleased@*/ temp_rel_buf_p = rel_buf_p; /*@-usereleased@*/ if (rel_buffer + filename_len <= temp_rel_buf_p + 3) { sfree (rel_buffer); return cstring_copy (filename); } *rel_buf_p++ = '.'; *rel_buf_p++ = '.'; *rel_buf_p++ = CONNECTCHAR; } /* Then tack on the unmatched part of the desired file's name. */ do { if (rel_buffer + filename_len <= rel_buf_p) { cstring_free (rel_buffer); return cstring_copy (filename); } } /*@-usereleased@*/ while ((*rel_buf_p++ = *path_p++) != '\0') ; /*@=usereleased@*/ /* Splint limitation: shouldn't need these */ --rel_buf_p; if (osd_isConnectChar (*(rel_buf_p-1))) *--rel_buf_p = '\0'; /* fprintf (stderr, "Returning buffer: %s [%p]\n", rel_buffer, rel_buffer); */ return rel_buffer; } /*@noaccess cstring@*/ # else return cstring_copy (filename); # endif }
cstring osd_absolutePath (cstring cwd, cstring filename) { # if defined (UNIX) || defined (OS2) /* Setup the current working directory as needed. */ cstring cwd2 = cstring_isDefined (cwd) ? cwd : osd_cwd; char *abs_buffer; char *endp, *outp, *inp; /*@access cstring@*/ llassert (cstring_isDefined (cwd2)); llassert (cstring_isDefined (filename)); abs_buffer = (char *) dmalloc (cstring_length (cwd2) + cstring_length (filename) + 2); endp = abs_buffer; /* ** Copy the filename (possibly preceded by the current working ** directory name) into the absolutization buffer. */ { const char *src_p; if (!osd_isConnectChar (filename[0]) # ifdef OS2 && !(isalpha (filename[0]) && filename[1] == ':') # endif ) { src_p = cwd2; while ((*endp++ = *src_p++) != '\0') { continue; } *(endp-1) = CONNECTCHAR; /* overwrite null */ } src_p = filename; while ((*endp++ = *src_p++) != '\0') { continue; } } /* Now make a copy of abs_buffer into abs_buffer, shortening the filename (by taking out slashes and dots) as we go. */ outp = inp = abs_buffer; *outp++ = *inp++; /* copy first slash */ #ifdef apollo if (inp[0] == '/') *outp++ = *inp++; /* copy second slash */ #endif for (;;) { if (inp[0] == '\0') { break; } else if (osd_isConnectChar (inp[0]) && osd_isConnectChar (outp[-1])) { inp++; continue; } else if (inp[0] == '.' && osd_isConnectChar (outp[-1])) { if (inp[1] == '\0') { break; } else if (osd_isConnectChar (inp[1])) { inp += 2; continue; } else if ((inp[1] == '.') && (inp[2] == '\0' || osd_isConnectChar (inp[2]))) { inp += (osd_isConnectChar (inp[2])) ? 3 : 2; outp -= 2; while (outp >= abs_buffer && !osd_isConnectChar (*outp)) { outp--; } if (outp < abs_buffer) { /* Catch cases like /.. where we try to backup to a point above the absolute root of the logical file system. */ llfatalbug (message ("Invalid file name: %s", filename)); } *++outp = '\0'; continue; } else { ; } } else { ; } *outp++ = *inp++; } /* On exit, make sure that there is a trailing null, and make sure that the last character of the returned string is *not* a slash. */ *outp = '\0'; if (osd_isConnectChar (outp[-1])) *--outp = '\0'; /*@noaccess cstring@*/ return cstring_fromChars (abs_buffer); # else DPRINTF (("Here: %s", filename)); return cstring_copy (filename); # endif }
extern void cppReader_pedwarnLit (cppReader *pfile, /*@observer@*/ cstring msg) { cppReader_pedwarn (pfile, cstring_copy (msg)); }
void cppReader_warningLit (cppReader *pfile, cstring msg) { cppReader_warning (pfile, cstring_copy (msg)); }
void cppReader_errorLit (cppReader *pfile, /*@observer@*/ cstring msg) { cppReader_error (pfile, cstring_copy (msg)); }