boolean OCI_HashAdd ( OCI_HashTable *table, const otext *key, OCI_Variant value, unsigned int type ) { OCI_HashEntry * e = NULL; OCI_HashValue * v = NULL, *v1 = NULL, *v2 = NULL; boolean res = FALSE; OCI_CHECK(NULL == table, FALSE) OCI_CHECK(NULL == key, FALSE) OCI_CHECK(table->type != type, FALSE) e = OCI_HashLookup(table, key, TRUE); if (e) { v = (OCI_HashValue *)OCI_MemAlloc(OCI_IPC_HASHVALUE, sizeof(*v), (size_t)1, TRUE); if (v) { if (OCI_HASH_STRING == table->type && value.p_text) { v->value.p_text = ostrdup(value.p_text); } else if (OCI_HASH_INTEGER == table->type) { v->value.num = value.num; } else { v->value.p_void = value.p_void; } v1 = v2 = e->values; while (v1) { v2 = v1; v1 = v1->next; } if (v2) { v2->next = v; } else { e->values = v; } res = TRUE; } } return res; }
OCI_HashEntry * OCI_API OCI_HashLookup ( OCI_HashTable *table, const otext *key, boolean create ) { OCI_HashEntry *e = NULL, *e1 = NULL, *e2 = NULL; unsigned int i; OCI_LIB_CALL_ENTER(OCI_HashEntry*, NULL) OCI_CHECK_PTR(OCI_IPC_HASHTABLE, table) OCI_CHECK_PTR(OCI_IPC_STRING, key) i = OCI_HashCompute(table, key); if (i < table->size) { for(e = table->items[i]; e; e = e->next) { if (ostrcasecmp(e->key, key) == 0) { break; } } if (!e && create) { e = (OCI_HashEntry *) OCI_MemAlloc(OCI_IPC_HASHENTRY, sizeof(*e), (size_t) 1, TRUE); if (e) { e->key = ostrdup(key); e1 = e2 = table->items[i]; while (e1) { e2 = e1; e1 = e1->next; } if (e2) { e2->next = e; } else { table->items[i] = e; } } } } call_retval = e; call_status = TRUE; OCI_LIB_CALL_EXIT() }
/** * 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; }
OCI_Dequeue * OCI_API OCI_DequeueCreate ( OCI_TypeInfo *typinf, const otext *name ) { OCI_Dequeue *dequeue = NULL; OCI_LIB_CALL_ENTER(OCI_Dequeue*, dequeue) OCI_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf) OCI_CHECK_PTR(OCI_IPC_STRING, name) /* allocate dequeue structure */ dequeue = (OCI_Dequeue *)OCI_MemAlloc(OCI_IPC_DEQUEUE, sizeof(*dequeue), (size_t)1, TRUE); if (dequeue) { dequeue->typinf = typinf; dequeue->name = ostrdup(name); /* allocate dequeue options descriptor */ call_status = OCI_SUCCESSFUL(OCI_DescriptorAlloc((dvoid *)dequeue->typinf->con->env, (dvoid **) &dequeue->opth, OCI_DTYPE_AQDEQ_OPTIONS, (size_t) 0, (dvoid **) NULL)); /* create local message for OCI_DequeueGet() */ if (call_status) { dequeue->msg = OCI_MsgCreate(dequeue->typinf); } call_status = (NULL != dequeue->msg); } /* check for failure */ if (call_status) { call_retval = dequeue; } else if (dequeue) { OCI_DequeueFree(dequeue); } OCI_LIB_CALL_EXIT() }
int find_conv_to_ind(char *lab) { int i, label; char *tmp; /* no string == empty label */ if (lab == NULL) return LABEL_EMPTY; /* empty string == empty label */ if (lab[0] == '\0') return LABEL_EMPTY; /* check if the label is already in the table */ label = -1; for (i = 0; i < num_labs; i++) if (strcmp(labels[i], lab) == 0) { label = i; break; } if (label < 0) { /* label not found in array. Add it. */ label = num_labs; if (label >= lab_array_size) if (enlarge_array()) return -1; if ((tmp = ostrdup(lab)) == NULL) return -1; labels[label] = tmp; num_labs++; } return(label + 1); }
char *get_str(char *ch) { int len = 100; char *tstr, *tmp; char str[100]; printf("%s: ", ch); tstr = fgets(str, len, stdin); if (tstr == NULL) { printf("Can't read required data\n"); exit(1); } tstr = ostrdup(str); tmp = strchr(tstr, ' '); if (tmp != (char) NULL) tmp[0] = '\0'; tmp = strchr(tstr, '\n'); if (tmp != (char) NULL) tmp[0] = '\0'; return(tstr); }
/* Use this function to set the directory containing installed pixmaps. */ void add_pixmap_directory(const gchar *dir) { pixmaps_directories = g_list_prepend (pixmaps_directories, ostrdup(dir)); }
static G_GNUC_COLD void load_faq(void) { static const gchar faq_file[] = "FAQ"; static file_path_t fp[6]; static int initialized; GtkWidget *textview; const gchar *lang; guint i = 0; FILE *f; html_view_free(&faq_html_view); textview = gui_dlg_faq_lookup("textview_faq"); lang = locale_get_language(); if (initialized != 0) { i = initialized; } else { char *tmp; char *path; tmp = get_folder_path(PRIVLIB_PATH, NULL); if (tmp != NULL) { path = make_pathname(tmp, lang); file_path_set(&fp[i++], ostrdup(path), faq_file); HFREE_NULL(path); path = make_pathname(tmp, "en"); file_path_set(&fp[i++], ostrdup(path), faq_file); HFREE_NULL(path); } HFREE_NULL(tmp); path = make_pathname(PRIVLIB_EXP, lang); file_path_set(&fp[i++], ostrdup(path), faq_file); HFREE_NULL(path); file_path_set(&fp[i++], PRIVLIB_EXP G_DIR_SEPARATOR_S "en", faq_file); #ifndef OFFICIAL_BUILD path = make_pathname(PACKAGE_EXTRA_SOURCE_DIR, lang); file_path_set(&fp[i++], ostrdup(path), faq_file); HFREE_NULL(path); file_path_set(&fp[i++], PACKAGE_EXTRA_SOURCE_DIR G_DIR_SEPARATOR_S "en", faq_file); #endif /* !OFFICIAL_BUILD */ initialized = i; } g_assert(i <= G_N_ELEMENTS(fp)); f = file_config_open_read_norename("FAQ", fp, i); if (f) { faq_html_view = html_view_load_file(textview, fileno(f)); fclose(f); } else { static const gchar msg[] = N_( "<html>" "<head>" "<title>Frequently Asked Questions</title>" "</head>" "<body>" "<p>" "The FAQ document could not be loaded. Please read the " "<a href=\"http://gtk-gnutella.sourceforge.net/?page=faq\">" "FAQ online</a> instead." "</p>" "</body>" "</html>" ); faq_html_view = html_view_load_memory(textview, array_from_string(msg)); } }