static OFILE * find_config_file (OlyStatus *status) { char *path = strcat(strcpy( omalloc((strlen(getenv("HOME")) + strlen(DOT_CONFIG_NAME)+1)), getenv("HOME")), DOT_CONFIG_NAME), result[BUFSIZ], *token, *watch; const char *basename = ETC_CONFIG_NAME, *sysconf_path = SYSCONFDIR; const char *the_colon = ":"; size_t name_size = ( strlen(basename) + 1 ), result_len = BUFSIZ; OFILE *return_file = NULL; void *free_me; if (*status != OLY_OKAY) HANDLE_OLY_STATUS(*status); { return NULL; } if ( path != NULL ) { return_file = u_fopen( path , "rb", NULL, NULL ); free_me = (void *)path; OFREE(free_me); } if (return_file == NULL) { path = omalloc( (strlen(sysconf_path) + 1) ); strcpy(path, sysconf_path); for ( token = strtok_r(path, the_colon, &watch); ( token != NULL ); token = strtok_r(NULL, the_colon, &watch) ) { if ((token != NULL) && ((strlen(token) + name_size) < result_len)) { strcpy( result, token ); strcat( result, basename ); return_file = u_fopen( result, "rb", char_default_locale(), char_default_encoding() ); } else { *status = OLY_ERR_FILE_NOT_FOUND; *result = '\0'; } } free_me = (void *)path; OFREE(free_me); } return return_file; }
static struct hthead *parseresp(FILE *in) { struct hthead *resp; char *st, *p; omalloc(resp); resp->ver = sstrdup("HTTP/1.1"); if(parseheaders(resp, in)) { freehthead(resp); return(NULL); } if((st = getheader(resp, "Status")) != NULL) { if((p = strchr(st, ' ')) != NULL) { *(p++) = 0; resp->code = atoi(st); resp->msg = sstrdup(p); } else { resp->code = atoi(st); resp->msg = sstrdup(httpdefstatus(resp->code)); } headrmheader(resp, "Status"); } else if(getheader(resp, "Location")) { resp->code = 303; resp->msg = sstrdup("See Other"); } else { resp->code = 200; resp->msg = sstrdup("OK"); } return(resp); }
/** * Get special folder path. * * @return pointer to static string, NULL if folder does not exist. */ static const char * get_folder_basepath(enum special_folder which_folder) { char *special_path = NULL; switch (which_folder) { case PRIVLIB_PATH: { static char *pathname; static bool fetched_xdg_data_dirs; if (NULL == pathname && !fetched_xdg_data_dirs) { special_path = getenv("XDG_DATA_DIRS"); fetched_xdg_data_dirs = TRUE; if (special_path != NULL) { if (is_absolute_path(special_path)) { pathname = omalloc(MAX_PATH_LEN); concat_strings(pathname, MAX_PATH_LEN, special_path, G_DIR_SEPARATOR_S, PACKAGE, (void *) 0); } else { s_warning("ignoring environment XDG_DATA_DIRS: " "holds non-absolute path \"%s\"", special_path); } } } special_path = pathname; } break; case NLS_PATH: { static char *pathname; static bool fetched_nlspath; if (NULL == pathname && !fetched_nlspath) { pathname = getenv("NLSPATH"); fetched_nlspath = TRUE; if (pathname != NULL && !is_absolute_path(pathname)) { s_warning("ignoring environment NLSPATH: " "holds non-absolute path \"%s\"", pathname); pathname = NULL; } else { pathname = ostrdup(pathname); } } if (NULL == pathname) pathname = LOCALE_EXP; special_path = pathname; } break; } return special_path; }
struct hthead *mkresp(int code, char *msg, char *ver) { struct hthead *resp; omalloc(resp); resp->code = code; resp->msg = sstrdup(msg); resp->ver = sstrdup(ver); return(resp); }
struct hthead *mkreq(char *method, char *url, char *ver) { struct hthead *req; omalloc(req); req->method = sstrdup(method); req->url = sstrdup(url); req->ver = sstrdup(ver); req->rest = sstrdup(url); return(req); }
int recvreq(int sock, struct hthead **reqp) { int fd; struct charbuf buf; char *p; size_t l; char *name, *val; struct hthead *req; if((fd = recvfd(sock, &buf.b, &buf.d)) < 0) { return(-1); } fcntl(fd, F_SETFD, FD_CLOEXEC); buf.s = buf.d; p = buf.b; l = buf.d; *reqp = omalloc(req); if((req->method = sstrdup(decstr(&p, &l))) == NULL) goto fail; if((req->url = sstrdup(decstr(&p, &l))) == NULL) goto fail; if((req->ver = sstrdup(decstr(&p, &l))) == NULL) goto fail; if((req->rest = sstrdup(decstr(&p, &l))) == NULL) goto fail; while(1) { if(!*(name = decstr(&p, &l))) break; val = decstr(&p, &l); headappheader(req, name, val); } buffree(buf); return(fd); fail: close(fd); freehthead(req); errno = EPROTO; return(-1); }
OlyState * new_state( OlyResource *master ) { #ifdef HAVE_UNICODE_URES_H UErrorCode u_status = U_ZERO_ERROR; OlyState *state = (OlyState *)omalloc(sizeof(OlyState)); #endif /* HAVE_UNICODE_URES_H */ assert( master != NULL ); state->msgbuf_start = (OChar *)ocalloc(BUFSIZ, sizeof(OChar)); state->msgbuf_end = state->msgbuf_start; state->status = OLY_OKAY; #ifdef HAVE_UNICODE_URES_H state->lib_status = u_status ; if (U_FAILURE(u_status)) { printf("New state error. Status: %s.\n", u_errorName(u_status)); state->status = OLY_ERR_LIB; } #endif /* HAVE_UNICODE_URES_H */ return state; }
OlyStatus new_oly_node( OlyNode **new_node ) { OlyStatus status = OLY_OKAY; OlyNode *new_node_local = NULL; HANDLE_STATUS_AND_RETURN(status); new_node_local = omalloc(sizeof(OlyNode)); if ( new_node_local == NULL ) { status = OLY_ERR_NOMEM; HANDLE_STATUS_AND_RETURN(status); } new_node_local->depth = 0; new_node_local->value.type = OLY_TAG_TYPE_UNSET; new_node_local->node_id = 0; new_node_local->key = NULL; new_node_local->parent_node = NULL; new_node_local->collection_end = false; new_node_local->has_key = false; new_node_local->value.value.string_value = NULL; (*new_node) = new_node_local; return status; }
UBreakIterator* get_rules(const char *ruleFileName, UErrorCode status) { /* Read in the rule source file */ long result; long ruleFileSize; FILE *file; OFILE *ufile; UBreakIterator *return_me; file = fopen(ruleFileName, "rb"); if( file == 0 ) { fprintf(stderr, "Could not open file \"%s\"\n", ruleFileName); exit(-1); } fseek(file, 0, SEEK_END); ruleFileSize = ftell(file); fseek(file, 0, SEEK_SET); char *ruleBufferC = (char *) omalloc (ruleFileSize + 1); ruleBufferC[ruleFileSize] = '\0'; result = (long)fread(ruleBufferC, 1, ruleFileSize, file); if (result != ruleFileSize) { fprintf(stderr, "Error reading file \"%s\"\n", ruleFileName); exit (-1); } /* Look for a Unicode Signature (BOM) on the rule file */ int32_t signatureLength; const char * ruleSourceC = ruleBufferC; const char* encoding = ucnv_detectUnicodeSignature( ruleSourceC, ruleFileSize, &signatureLength, &status); /* fprintf(stderr, "DetectUnicodeSig: \"%s\"\n", encoding); */ if (U_FAILURE(status)) { fprintf(stderr, "\nCan not initialize ICU. status = %s\n", u_errorName(status)); exit(1); } if(encoding!=NULL ) { ruleSourceC += signatureLength; ruleFileSize -= signatureLength; } /* fprintf(stderr, "encoding: \"%s\"\n", encoding); */ /* Open a converter to take the rule file to UTF-16 */ UConverter* conv; conv = ucnv_open(encoding, &status); if (U_FAILURE(status)) { fprintf(stderr, "ucnv_open: ICU Error \"%s\"\n", u_errorName(status)); exit(1); } ufile = u_finit(file, NULL, NULL); u_frewind(ufile); UChar *ruleSourceU = (UChar *) omalloc ((ruleFileSize*sizeof(UChar))+1); long charsRead = u_file_read(ruleSourceU, ruleFileSize, ufile); /* u_fprintf(u_stderr, "Chars read: \"%i\", File size: \"%i\"\n", charsRead, ruleFileSize); */ ruleSourceU[charsRead] = 0; /* u_fprintf(u_stderr, "RulesourceU POST: \"%S\"\n", ruleSourceU); */ ucnv_close(conv); u_fclose(ufile); /* Create the break iterator from the rules */ /* This will compile the rules. */ UParseError parseError; parseError.line = 0; parseError.offset = 0; return_me = ubrk_openRules(ruleSourceU, ruleFileSize, NULL, 0, &parseError, &status); if (U_FAILURE(status)) { fprintf(stderr, "createRuleBasedBreakIterator: ICU Error \"%s\" at line %d, column %d\n", u_errorName(status), (int)parseError.line, (int)parseError.offset); exit(1); }; return return_me; }
node *node_malloc() { nodemem += sizeof(node); nnodes += 1; return (node *)omalloc(); }
void omtTestAlloc(omMemCell cell, unsigned long spec) { size_t size = GET_SIZE(spec); void* addr; omBin bin = NULL; omBin orig_bin = NULL; if (IS_BIN(spec) && (size <= OM_MAX_BLOCK_SIZE || IS_SPEC_BIN(spec))) { if (IS_SPEC_BIN(spec)) { if (IS_ALIGNED(spec)) bin = omGetAlignedSpecBin(size); else bin = omGetSpecBin(size); } else { if (IS_ALIGNED(spec)) bin = omSmallSize2AlignedBin(size); else bin = omSmallSize2Bin(size); } if (IS_STICKY_BIN(spec)) { orig_bin = bin; bin = omtGetStickyBin(bin); } if (IS_INLINE(spec)) { if (IS_ZERO(spec)) addr = omAlloc0Bin(bin); else addr = omAllocBin(bin); } else { if (IS_ZERO(spec)) omTypeAlloc0Bin(void*, addr, bin); else omTypeAllocBin(void*, addr, bin); } } else { if (IS_INLINE(spec)) { if (IS_ZERO(spec)) { if (IS_ALIGNED(spec)) { if (IS_SLOPPY(spec)) addr = omalloc0(size); else addr = omAlloc0Aligned(size); } else addr = omAlloc0(size); } else { if (IS_ALIGNED(spec)) { if (IS_SLOPPY(spec)) addr = omalloc(size); else addr = omAllocAligned(size); } else addr = omAlloc(size); } } else { if (IS_ZERO(spec)) { if (IS_ALIGNED(spec)) omTypeAlloc0Aligned(void*, addr, size); else omTypeAlloc0(void*, addr, size); } else { if (IS_ALIGNED(spec)) omTypeAllocAligned(void*, addr, size); else omTypeAlloc(void*, addr, size); } } } cell->addr = addr; cell->bin = bin; cell->orig_bin = orig_bin; cell->spec = spec; InitCellAddrContent(cell); omtTestDebug(cell); }