Ejemplo n.º 1
0
/**
 * Prints the ``port'' followed by host address ``ha'' to ``dst''. The string
 * written to ``dst'' is always NUL-terminated unless ``size'' is zero. If
 * ``size'' is too small, the string will be truncated.
 *
 * @param dst the destination buffer; may be NULL iff ``size'' is zero.
 * @param port the port number.
 * @param ha the host address.
 * @param size the size of ``dst'' in bytes.
 *
 * @return The length of the resulting string assuming ``size'' is sufficient.
 */
size_t
host_port_addr_to_string_buf(uint16 port, const host_addr_t ha,
	char *dst, size_t size)
{
	char port_buf[UINT32_DEC_BUFLEN];
	char host_buf[HOST_ADDR_BUFLEN];
	size_t n;

	uint32_to_string_buf(port, port_buf, sizeof port_buf);
	host_addr_to_string_buf(ha, host_buf, sizeof host_buf);

	switch (host_addr_net(ha)) {
	case NET_TYPE_IPV6:
		n = concat_strings(dst, size, port_buf, ":[", host_buf, "]",
			(void *) 0);
		break;
	case NET_TYPE_IPV4:
		n = concat_strings(dst, size, port_buf, ":", host_buf, (void *) 0);
		break;
	default:
		n = g_strlcpy(dst, host_buf, size);
	}

	return n;
}
Ejemplo n.º 2
0
/* check if directory is writable */
boolean_t
directory_is_writable (char *path)
{
	FILE *f;
	char *s;
	int fd;
#if defined(_WIN32)
	s = concat_strings(path, "\\ctm.XXXXXX");
	/* mingw doesn't have mkstemp */
	s = mktemp(s);
	f = fopen(s, "w");
#else
	s = concat_strings(path, "/ctm.XXXXXX");
	fd = mkstemp(s);
	if (fd == -1)
		return FALSE;
	f = fdopen(fd, "w");
#endif
	if (f == NULL) {
		return FALSE;
	} else {
		fclose (f);
		unlink(s);
		return TRUE;
	}
}
Ejemplo n.º 3
0
static struct dns_entry * add_dns_entry (struct instance *o, const char *type, const char *value, int priority)
{
    // allocate entry
    struct dns_entry *entry = malloc(sizeof(*entry));
    if (!entry) {
        goto fail0;
    }
    
    // generate line
    entry->line = concat_strings(4, type, " ", value, "\n");
    if (!entry->line) {
        goto fail1;
    }
    
    // set info
    entry->priority = priority;
    
    // add to list
    LinkedList1_Append(&o->entries, &entry->list_node);
    
    return entry;
    
fail1:
    free(entry);
fail0:
    return NULL;
}
Ejemplo n.º 4
0
/* get object file corresponding to src file */
char *
get_object_file (char *src)
{
	// bug 2025
	// Create .o files in /tmp in case the src dir is not writable.
	if (!(keep_flag || (ipa == TRUE) || remember_last_phase == P_any_as)) {
	  char *tmp_file = NULL;
	  char *obj_name = change_suffix(src, "o");
	  string_pair_item_t *p;
	  FOREACH_STRING_PAIR (p, temp_obj_files) {
	    if (strcmp (STRING_PAIR_KEY(p), obj_name) == 0)
	      return STRING_PAIR_VAL(p);
	  }
	  // Create temp file name as in create_temp_file_name.
	  tmp_file = concat_strings(tmpdir, "/cco.XXXXXX");
	  int fd = mkstemp(tmp_file);
      if(fd == -1) {
		error("mkstemp failed for template: %s", tmp_file);
        return NULL;
      }

	  close(fd);
	  add_string_pair (temp_obj_files, obj_name, tmp_file);
	  return tmp_file;
	}
Ejemplo n.º 5
0
static size_t
thex_upload_prepare_xml(char **data_ptr, const struct tth *tth,
	filesize_t filesize)
{
	struct dime_record *dime;
	char buf[512];
	size_t len, size;
	unsigned depth;

	depth = tt_good_depth(filesize);
	len = concat_strings(buf, sizeof buf,
		"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
		"<!DOCTYPE hashtree S"	/* NOTE: HIDE FROM METACONFIG */
			"YSTEM \""			THEX_DOCTYPE "\">\r\n"
		"<hashtree>\r\n"
		"<file"
			" size=\"",			filesize_to_string(filesize), "\""
			" segmentsize=\""	THEX_SEGMENT_SIZE "\"/>\r\n"
		"<digest"
			" algorithm=\""		THEX_HASH_ALGO "\""
			" outputsize=\""	THEX_HASH_SIZE "\"/>\r\n"
		"<serializedtree"
			" depth=\"",		uint32_to_string(depth), "\""
			" type=\""			THEX_TREE_TYPE "\""
			" uri=\"",			thex_upload_uuid(tth), "\"/>\r\n"
		"</hashtree>\r\n",
		(void *) 0);

	dime = dime_record_alloc();
	dime_record_set_data(dime, buf, len);
	dime_record_set_type_mime(dime, "text/xml");
	size = dime_create_record(dime, data_ptr, TRUE, FALSE);
	dime_record_free(&dime);
	return size;
}
Ejemplo n.º 6
0
/* return path and name of phase */
char *
get_full_phase_name (phases_t index)
{
	buffer_t tmp;
	strcpy(tmp, get_phase_dir(index));
	if (strlen(tmp) > 0) {
	    strcat(tmp, "/");
	}
	if (sizeof(EXT_EXE) > 1) {
	    strcat(tmp, get_phase_name(index));
	    return concat_strings (tmp, EXT_EXE);
	}
	else {
	    return concat_strings (tmp, get_phase_name(index));
	}
}
Ejemplo n.º 7
0
/**
 * Record a new leak of `size' bytes allocated at `file', line `line'.
 */
void
leak_add(leak_set_t *ls, size_t size, const char *file, int line)
{
	char key[1024];
	struct leak_record *lr;
	bool found;
	void *v;

	leak_set_check(ls);
	g_assert(file);
	g_assert(line >= 0);

	concat_strings(key, sizeof key,
		file, ":", uint64_to_string(line), (void *) 0);
	found = htable_lookup_extended(ls->places, key, NULL, &v);

	if (found) {
		lr = v;
		lr->size += size;
		lr->count++;
	} else {
		XPMALLOC(lr);
		lr->size = size;
		lr->count = 1;
		htable_insert(ls->places, xstrdup(key), lr);
	}
}
Ejemplo n.º 8
0
/**
 * Get the full program path.
 *
 * @return a newly allocated string (through halloc()) that points to the
 * path of the program being run, NULL if we can't compute a suitable path.
 */
char *
file_program_path(const char *argv0)
{
	filestat_t buf;
	char *file = deconstify_char(argv0);
	char filepath[MAX_PATH_LEN + 1];

	if (is_running_on_mingw() && !is_strsuffix(argv0, (size_t) -1, ".exe")) {
		concat_strings(filepath, sizeof filepath, argv0, ".exe", NULL_PTR);
	} else {
		clamp_strcpy(filepath, sizeof filepath, argv0);
	}

	if (-1 == stat(filepath, &buf)) {
		int saved_errno = errno;
		file = file_locate_from_path(argv0);
		if (NULL == file) {
			errno = saved_errno;
			s_warning("%s(): could not stat() \"%s\": %m", G_STRFUNC, filepath);
			return NULL;
		}
	}

	if (file != NULL && file != argv0)
		return file;		/* Allocated by file_locate_from_path() */

	return h_strdup(filepath);
}
Ejemplo n.º 9
0
/* Turn list 'excludes' into list of " --excludes=..." strings, all
 * properly quoted.  Caller must free the returned string.
 */
static char *
make_excludes_args (char *const *excludes)
{
  DECLARE_STRINGSBUF (strings);
  size_t i;
  char *s, *ret;

  for (i = 0; excludes[i] != NULL; ++i) {
    if (asprintf_nowarn (&s, " --exclude=%Q", excludes[i]) == -1) {
      reply_with_perror ("asprintf");
      free_stringslen (strings.argv, strings.size);
      return NULL;
    }
    if (add_string_nodup (&strings, s) == -1) {
      free (s);
      return NULL;
    }
  }

  if (end_stringsbuf (&strings) == -1)
    return NULL;

  ret = concat_strings (strings.argv);
  if (!ret) {
    reply_with_perror ("concat");
    free_stringslen (strings.argv, strings.size);
    return NULL;
  }

  free_stringslen (strings.argv, strings.size);

  return ret;
}
Ejemplo n.º 10
0
Archivo: objects.c Proyecto: qiyao/xcc
extern void
append_libraries_to_list (string_list_t *list)
{
        string_item_t *p;
        for (p = library_dirs->head; p != NULL; p = p->next) {
		add_string(list, concat_strings("-L", p->name));
        }
        /*
         * get_phase_dir(P_library) is not in library_dirs because
         * library_dirs is also used as the search path for the crt file
         */
        if (!option_was_seen(O_L)) {
                add_string(list,
                           concat_strings("-L", get_phase_dir(P_library)));
        }
}
Ejemplo n.º 11
0
/**
 * Search executable within the user's PATH.
 *
 * @return full path if found, NULL otherwise.
 * The returned string is allocated with halloc().
 */
char *
file_locate_from_path(const char *argv0)
{
	static bool already_done;
	char *path;
	char *tok;
	char filepath[MAX_PATH_LEN + 1];
	char *result = NULL;
	char *ext = "";

	if (is_running_on_mingw() && !is_strsuffix(argv0, (size_t) -1, ".exe")) {
		ext = ".exe";
	}

	if (filepath_basename(argv0) != argv0) {
		if (!already_done) {
			s_warning("can't locate \"%s\" in PATH: name contains '%c' already",
				argv0,
				strchr(argv0, G_DIR_SEPARATOR) != NULL ? G_DIR_SEPARATOR : '/');
		}
		goto done;
	}

	path = getenv("PATH");
	if (NULL == path) {
		if (!already_done) {
			s_warning("can't locate \"%s\" in PATH: "
				"no such environment variable", argv0);
		}
		goto done;
	}

	path = h_strdup(path);

	tok = strtok(path, G_SEARCHPATH_SEPARATOR_S);
	while (NULL != tok) {
		const char *dir = tok;
		filestat_t buf;

		if ('\0' == *dir)
			dir = ".";
		concat_strings(filepath, sizeof filepath,
			dir, G_DIR_SEPARATOR_S, argv0, ext, NULL);

		if (-1 != stat(filepath, &buf)) {
			if (S_ISREG(buf.st_mode) && -1 != access(filepath, X_OK)) {
				result = h_strdup(filepath);
				break;
			}
		}
		tok = strtok(NULL, G_SEARCHPATH_SEPARATOR_S);
	}

	hfree(path);

done:
	already_done = TRUE;	/* No warning on subsequent invocation */
	return result;
}
Ejemplo n.º 12
0
/**
 * 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;
}
Ejemplo n.º 13
0
/* return path and name of phase */
char *
get_full_phase_name (phases_t index)
{
	buffer_t tmp;
	strcpy(tmp, get_phase_dir(index));
	strcat(tmp, "/");
	return concat_strings (tmp, get_phase_name(index));
}
Ejemplo n.º 14
0
/* return language name */
char *
get_lang_name (languages_t index)
{
#if defined(_WIN32)
	return concat_strings(language_info[index].name[0], ".exe");
#else
	return language_info[index].name[0];
#endif
}
Ejemplo n.º 15
0
/* return phase name */
char *
get_phase_name (phases_t index)
{
#if defined(_WIN32)
	return concat_strings(phase_info[index].name, ".exe");
#else
	return phase_info[index].name;
#endif
}
Ejemplo n.º 16
0
/* prefix all phase names with prefix */
void
prefix_all_phase_names (mask_t mask, const char *prefix)
{
  phases_t i;
  for (i = P_NONE; i < P_LAST; i++) {
    if ((phase_info[i].mask & mask) != 0)
      phase_info[i].name = concat_strings(prefix, phase_info[i].name);
  }
}
Ejemplo n.º 17
0
static int EditStringCB(char **value, int *length, void *data)
{
    fonttool_ui *ui = (fonttool_ui *) data;
    unsigned char c;
    static int column = 0, row = 0;
    char *text;
    int len = *length;

    text = *value;
    
    TableDeselectCell(ui->font_table, row, column);
    
    if (len == 1) {
        /* */
        c = text[0];
        row = c/16;
        column = c % 16;

        if (ui->valid_chars[c]) {
            TableSelectCell(ui->font_table, row, column);
        } else {
            return FALSE;
        }
    }
    
    if (ui->new_font) {
        char *buf;
        
        buf = copy_string(NULL, "\\f{");
        buf = concat_strings(buf,
            project_get_font_name_by_id(gproject_get_top(gapp->gp), ui->font_id));
        buf = concat_strings(buf, "}");
        buf = concat_strings(buf, text);
        xfree(text);
        text = copy_string(NULL, buf);
        *value = text;
        *length = strlen(buf);
        xfree(buf);

        ui->new_font = FALSE;
    }

    return TRUE;
}
Ejemplo n.º 18
0
/* prefix all phase dirs with path */
void
prefix_all_phase_dirs (mask_t mask, char *path)
{
	phases_t i;
	for (i = P_NONE; i < P_LAST; i++) {
		if ((phase_info[i].mask & mask) != 0)
			phase_info[i].dir = 
				concat_strings(path, phase_info[i].dir);
	}
}
Ejemplo n.º 19
0
void ui_set_streaming_title(const char *title)
{
	lock_ui();
	char *buf = concat_strings(title, " - " APP_NAME);
	if (buf) {
		gtk_window_set_title(GTK_WINDOW(main_window), buf);
		free(buf);
	}
	unlock_ui();
}
Ejemplo n.º 20
0
/**
 * Convert magnet source to a string representation.
 *
 * @return A newly allocated string.
 */
char *
magnet_source_to_string(const struct magnet_source *s)
{
	char *url;

	g_return_val_if_fail(s, NULL);

	if (s->url) {
		url = g_strdup(s->url);
	} else {
		char *proxies = NULL;
		const char *host, *prefix;
		char prefix_buf[256];
		char port_buf[16];

		if (s->guid) {
			char guid_buf[GUID_HEX_SIZE + 1];
			
			guid_to_string_buf(s->guid, guid_buf, sizeof guid_buf);
			concat_strings(prefix_buf, sizeof prefix_buf,
				"push://", guid_buf, (void *) 0);
			prefix = prefix_buf;
		} else {
			prefix = "http://";
		}
		
		port_buf[0] = '\0';
		if (s->hostname) {
			host = s->hostname;
			if (80 != s->port) {
				str_bprintf(port_buf, sizeof port_buf, ":%u",
					(unsigned) s->port);
			}
		} else if (s->guid) {
			proxies = proxies_to_string(s->proxies);
			host = proxies;
		} else {
			host = host_addr_port_to_string(s->addr, s->port);
		}
		if (s->path) {
			url = g_strconcat(prefix, host, port_buf, s->path, (void *) 0);
		} else if (s->sha1) {
			url = g_strconcat(prefix, host, port_buf,
					"/uri-res/N2R?", bitprint_to_urn_string(s->sha1, s->tth),
					(void *) 0);
		} else {
			url = g_strconcat(prefix, host, port_buf, "/", (void *) 0);
		}

		HFREE_NULL(proxies);
	}

	return url;
}
Ejemplo n.º 21
0
Archivo: c_gz.c Proyecto: amnh/poy5
value mlgz_gzopen_gen(value name, value mode)
{
  gzFile str;
  str = gzopen(String_val(name), String_val(mode)) ;
  if(str==NULL){
    if(errno==0)
      raise_out_of_memory();
    else 
      raise_sys_error(concat_strings(String_val(name), strerror(errno)));
  }
  return Val_ptr(str);
}
Ejemplo n.º 22
0
/**
 * Create a Bitzi lookup URL based on the SHA1.
 *
 * @return pointer to static data containing the bitzi URL, NULL on error.
 */
const char *
url_for_bitzi_lookup(const struct sha1 *sha1)
{
	static const char base_url[] = "http://bitzi.com/lookup/";
	static char buf[sizeof base_url + SHA1_BASE32_SIZE];

	g_return_val_if_fail(sha1, NULL);

	concat_strings(buf, sizeof buf, base_url, sha1_base32(sha1), (void *) 0);

	return buf;
}
Ejemplo n.º 23
0
static void
nodes_gui_update_node_flags(struct node_data *data, gnet_node_flags_t *flags)
{
	gboolean ultra;
	
	g_assert(NULL != data);

	concat_strings(data->flags, sizeof data->flags,
		"<tt>", guc_node_flags_to_string(flags), "</tt>", (void *) 0);

	ultra = NODE_P_ULTRA == flags->peermode || NODE_P_G2HUB == flags->peermode;
    data->fg = &(gtk_widget_get_style(GTK_WIDGET(treeview_nodes))
					->fg[ultra ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE]);
}
int main(void)
{
   char s1[98] = "Hello ";
   char s2[] = "World!\n";
   char *p;

   printf("%s\n", s1);
   printf("%s", s2);
   p = concat_strings(s1, s2);
   printf("%s", s1);
   printf("%s", s2);
   printf("%s", p);
   return (0);
}
Ejemplo n.º 25
0
const char *
host_port_to_string(const char *hostname, host_addr_t addr, uint16 port)
{
	static char buf[MAX_HOSTLEN + 32];

	if (hostname) {
		char port_buf[UINT32_DEC_BUFLEN];

		uint32_to_string_buf(port, port_buf, sizeof port_buf);
		concat_strings(buf, sizeof buf, hostname, ":", port_buf, (void *) 0);
	} else {
		host_addr_port_to_string_buf(addr, port, buf, sizeof buf);
	}
	return buf;
}
Ejemplo n.º 26
0
/* check if directory is writable */
extern boolean
directory_is_writable (string path)
{
	FILE *f;
	string s;
	s = concat_strings(path, "/ctm.XXXXXX");
	s = mktemp(s);
	f = fopen(s, "w");
	if (f == NULL) {
		return FALSE;
	} else {
		fclose (f);
		unlink(s);
		return TRUE;
	}
}
Ejemplo n.º 27
0
/* append all phase dirs with path */
void
append_all_phase_dirs (mask_t mask, char *path)
{
	phases_t i;
	for (i = P_NONE; i < P_LAST; i++) {
		if ((phase_info[i].mask & mask) != 0) {
			/* only append if end with preset PHASEPATH */
			if (strcmp(phase_info[i].dir + strlen(phase_info[i].dir) -
				   strlen(PHASEPATH), PHASEPATH) == 0)
			{
				phase_info[i].dir = 
					concat_strings(phase_info[i].dir, path);
			}
		}
	}
}
Ejemplo n.º 28
0
const char *
host_port_to_string(const char *hostname, host_addr_t addr, uint16 port)
{
	buf_t *b = buf_private(G_STRFUNC, MAX_HOSTLEN + HOST_ADDR_PORT_BUFLEN);
	char *p = buf_data(b);

	if (hostname != NULL) {
		char port_buf[UINT32_DEC_BUFLEN];

		uint32_to_string_buf(port, port_buf, sizeof port_buf);
		concat_strings(p, buf_size(b), hostname, ":", port_buf, NULL_PTR);
	} else {
		host_addr_port_to_string_buf(addr, port, p, buf_size(b));
	}
	return p;
}
Ejemplo n.º 29
0
char *
concat_path (char *d, char *f)
{
	if ((d == NULL) || (strlen (d) == 0) || strcmp(d, "/") == 0) {
		/* Directory is root, don't return //f */
		return concat_strings ("/", f);
	} else if ((f == NULL) || (strlen (f) == 0)) {
		/* file is null, return directory portion only */
		return d;
	} else {
		char *path = (char *) malloc(strlen(d) + strlen(f) + 2);
		strcpy (path, d);
		strcat (path, "/");
		strcat (path, f);
		return path;
	}
}
Ejemplo n.º 30
0
/**
 * Verifies "data" against "signature".
 *
 * @return TRUE if the signature matches.
 */
bool
svn_release_notification_verify(uint32 revision, time_t date,
                                const struct array *signature)
{
    char rev[12], data[64];
    struct array input;

    uint32_to_string_buf(revision, rev, sizeof rev);
    input.data = (void *) data;
    input.size = concat_strings(data, sizeof data,
                                "r", rev,
                                "@", uint32_to_string(date),
                                (void *) 0);

    return verify_signature(svn_release_notify_certificate(),
                            &input, signature);
}