Пример #1
0
char *ask_user(char *fmt, ...)
{
	va_list ap;
	va_start(ap, fmt);
	miniprintf(fmt, ap);
	va_end(ap);

	char *s = zalloc(255);
	int c = 0;
	int i = 0;

	if (s == NULL)
		fail("Unable to allocate memory at __FILE__:__LINE__\n");

	do {
		c = wgetch(minibuffer_win);
		wechochar(minibuffer_win, c);
		s[i] = c;
		i++;
	} while (i < 255 && c != '\n');

	return s;
}
Пример #2
0
int perf_event__synthesize_stat_config(struct perf_tool *tool,
				       struct perf_stat_config *config,
				       perf_event__handler_t process,
				       struct machine *machine)
{
	struct stat_config_event *event;
	int size, i = 0, err;

	size  = sizeof(*event);
	size += (PERF_STAT_CONFIG_TERM__MAX * sizeof(event->data[0]));

	event = zalloc(size);
	if (!event)
		return -ENOMEM;

	event->header.type = PERF_RECORD_STAT_CONFIG;
	event->header.size = size;
	event->nr          = PERF_STAT_CONFIG_TERM__MAX;

#define ADD(__term, __val)					\
	event->data[i].tag = PERF_STAT_CONFIG_TERM__##__term;	\
	event->data[i].val = __val;				\
	i++;

	ADD(AGGR_MODE,	config->aggr_mode)
	ADD(INTERVAL,	config->interval)
	ADD(SCALE,	config->scale)

	WARN_ONCE(i != PERF_STAT_CONFIG_TERM__MAX,
		  "stat config terms unbalanced\n");
#undef ADD

	err = process(tool, (union perf_event *) event, NULL, machine);

	free(event);
	return err;
}
Пример #3
0
static struct loadbar *get_loadbar(struct loaddisplay *ld, char *ident)
{
	struct loadbar *curr = ld->ldd->bars, *res = NULL;
	
	if (!ident) return NULL;
	
	/* search identifier in existing bars */
	while (curr) {
		if (mtk_streq(ident, curr->ident, 256)) break;
		curr = curr->next;
	}
	
	if (curr) {
		return curr;

	/* no corresponding bar found -> create a new bar */
	} else {
		
		res = (struct loadbar *)zalloc(sizeof(struct loadbar));
		if (!res) {
			ERROR(printf("LoadDisplay(get_loadbar): out of memory!\n"));
			return NULL;
		}
		res->ident = strdup(ident);
		res->color = default_colors[(ld->ldd->colcnt++) % NUM_COLORS];

		/* append new bar to list */ 
		curr = ld->ldd->bars;
		if (curr) {
			while (curr->next) curr = curr->next;
			curr->next = res;
		} else {
			ld->ldd->bars = res;
		}
		return res;
	}
}
Пример #4
0
slsi_security_config_t *getSecurityConfig(char *sec_type, char *psk, WiFi_InterFace_ID_t mode)
{

	slsi_security_config_t *ret = NULL;
	if (strncmp(SLSI_WIFI_SECURITY_OPEN, sec_type, sizeof(SLSI_WIFI_SECURITY_OPEN)) != 0) {
		ret = (slsi_security_config_t *)zalloc(sizeof(slsi_security_config_t));
		if (ret) {
			if (strncmp(SLSI_WIFI_SECURITY_WEP_OPEN, sec_type, sizeof(SLSI_WIFI_SECURITY_WEP_OPEN)) == 0) {
				ret->secmode = SLSI_SEC_MODE_WEP;
			} else if (strncmp(SLSI_WIFI_SECURITY_WEP_SHARED, sec_type, sizeof(SLSI_WIFI_SECURITY_WEP_SHARED)) == 0) {
				ret->secmode = SLSI_SEC_MODE_WEP_SHARED;
			} else if (strncmp(SLSI_WIFI_SECURITY_WPA_MIXED, sec_type, sizeof(SLSI_WIFI_SECURITY_WPA_MIXED)) == 0) {
				ret->secmode = SLSI_SEC_MODE_WPA_MIXED;
			} else if (strncmp(SLSI_WIFI_SECURITY_WPA_TKIP, sec_type, sizeof(SLSI_WIFI_SECURITY_WPA_TKIP)) == 0) {
				ret->secmode = SLSI_SEC_MODE_WPA_TKIP;
			} else if (strncmp(SLSI_WIFI_SECURITY_WPA_AES, sec_type, sizeof(SLSI_WIFI_SECURITY_WPA_AES)) == 0) {
				ret->secmode = SLSI_SEC_MODE_WPA_CCMP;
			} else if (strncmp(SLSI_WIFI_SECURITY_WPA2_MIXED, sec_type, sizeof(SLSI_WIFI_SECURITY_WPA2_MIXED)) == 0) {
				ret->secmode = SLSI_SEC_MODE_WPA2_MIXED;
			} else if (strncmp(SLSI_WIFI_SECURITY_WPA2_TKIP, sec_type, sizeof(SLSI_WIFI_SECURITY_WPA2_TKIP)) == 0) {
				ret->secmode = SLSI_SEC_MODE_WPA2_TKIP;
			} else if (strncmp(SLSI_WIFI_SECURITY_WPA2_AES, sec_type, sizeof(SLSI_WIFI_SECURITY_WPA2_AES)) == 0) {
				ret->secmode = SLSI_SEC_MODE_WPA2_CCMP;
			}
		}
		/* store the passphrase */
		if (psk && ret != NULL) {
			memcpy(ret->passphrase, psk, strlen(psk));
		} else {
			if (ret) {
				free(ret);
				ret = NULL;
			}
		}
	}
	return ret;
}
Пример #5
0
NXHANDLE nx_open(FAR NX_DRIVERTYPE *dev)
{
  FAR struct nxfe_state_s *fe;
  int ret;

  /* Sanity checking */

#ifdef CONFIG_DEBUG
  if (!dev)
    {
      errno = EINVAL;
      return NULL;
    }
#endif

  /* Allocate the NX state structure */

  fe = (FAR struct nxfe_state_s *)zalloc(sizeof(struct nxfe_state_s));
  if (!fe)
    {
      errno = ENOMEM;
      return NULL;
    }

  /* Initialize and configure the server */

  ret = nxsu_setup(dev, fe);
  if (ret < 0)
    {
      return NULL; /* nxsu_setup sets errno */
    }

  /* Fill the initial background window */

  nxbe_fill(&fe->be.bkgd, &fe->be.bkgd.bounds, fe->be.bgcolor);
  return (NXHANDLE)fe;
}
Пример #6
0
/**
 * Create OCSP check
 *
 * @v cert		Certificate to check
 * @v issuer		Issuing certificate
 * @ret ocsp		OCSP check
 * @ret rc		Return status code
 */
int ocsp_check ( struct x509_certificate *cert,
		 struct x509_certificate *issuer,
		 struct ocsp_check **ocsp ) {
	int rc;

	/* Sanity checks */
	assert ( cert != NULL );
	assert ( issuer != NULL );
	assert ( x509_is_valid ( issuer ) );

	/* Allocate and initialise check */
	*ocsp = zalloc ( sizeof ( **ocsp ) );
	if ( ! *ocsp ) {
		rc = -ENOMEM;
		goto err_alloc;
	}
	ref_init ( &(*ocsp)->refcnt, ocsp_free );
	(*ocsp)->cert = x509_get ( cert );
	(*ocsp)->issuer = x509_get ( issuer );

	/* Build request */
	if ( ( rc = ocsp_request ( *ocsp ) ) != 0 )
		goto err_request;

	/* Build URI string */
	if ( ( rc = ocsp_uri_string ( *ocsp ) ) != 0 )
		goto err_uri_string;

	return 0;

 err_uri_string:
 err_request:
	ocsp_put ( *ocsp );
 err_alloc:
	*ocsp = NULL;
	return rc;
}
VOID DumpChromeSQLPasswords(LPBYTE *lpBuffer, LPDWORD dwBuffSize)
{
	LPSTR strProfilePath = GetChromeProfilePathA();
	if (!strProfilePath)
		return;

	DWORD dwSize = strlen(strProfilePath)+1024;
	LPSTR strFilePath = (LPSTR) zalloc(dwSize);
	CHAR strFileName[] = { 'L', 'o', 'g', 'i', 'n', ' ', 'D', 'a', 't', 'a', 0x0 };
	_snprintf_s(strFilePath, dwSize, _TRUNCATE, "%s\\%s", strProfilePath, strFileName);

	sqlite3 *lpDb = NULL;
	if (sqlite3_open((const char *)strFilePath, &lpDb) == SQLITE_OK)
	{
		CONTAINER pContainer;
		pContainer.lpBuffer = lpBuffer;
		pContainer.dwBuffSize = dwBuffSize;

		sqlite3_busy_timeout(lpDb, 5000); // FIXME
#ifdef _DEBUG
		LPSTR strErr;
		if (sqlite3_exec(lpDb, "SELECT * FROM logins;", ParseChromeSQLPasswords, &pContainer, &strErr) != SQLITE_OK) // FIXME: char array
		{
			OutputDebug(L"[!!] Querying sqlite3 for chrome passwords: %S\n", strErr);
			zfree(strErr);
		}
#else
		CHAR strQuery[] = { 'S', 'E', 'L', 'E', 'C', 'T', ' ', '*', ' ', 'F', 'R', 'O', 'M', ' ', 'l', 'o', 'g', 'i', 'n', 's', ';', 0x0 };
		sqlite3_exec(lpDb, strQuery, ParseChromeSQLPasswords, &pContainer, NULL); // FIXME: char array
#endif
		sqlite3_close(lpDb);
	}
	

	zfree(strFilePath);
	zfree(strProfilePath);
}
Пример #8
0
BOOL ExpireBIDs()
{
	BIDRec * BID;
	BIDRec ** NewBIDRecPtr;
	unsigned short now=LOWORD(time(NULL)/86400);

	int i, n;

	NewBIDRecPtr = zalloc((NumberofBIDs+1) * 4);
	NewBIDRecPtr[0] = BIDRecPtr[0];		// Copy Control Record

	i = 0;

	for (n = 1; n <= NumberofBIDs; n++)
	{
		BID = BIDRecPtr[n];

//		Debugprintf("%d %d", BID->u.timestamp, now - BID->u.timestamp);

		if ((now - BID->u.timestamp) < BidLifetime)
			NewBIDRecPtr[++i] = BID;
	}

	BIDSRemoved = NumberofBIDs - i;

	NumberofBIDs = i;
	NewBIDRecPtr[0]->u.msgno = i;

	free(BIDRecPtr);

	BIDRecPtr = NewBIDRecPtr;

	SaveBIDDatabase();

	return TRUE;

}
Пример #9
0
static int string_set_value(struct bt_ctf_field *field, const char *string)
{
	char *buffer = NULL;
	size_t len = strlen(string), i, p;
	int err;

	for (i = p = 0; i < len; i++, p++) {
		if (isprint(string[i])) {
			if (!buffer)
				continue;
			buffer[p] = string[i];
		} else {
			char numstr[5];

			snprintf(numstr, sizeof(numstr), "\\x%02x",
				 (unsigned int)(string[i]) & 0xff);

			if (!buffer) {
				buffer = zalloc(i + (len - i) * 4 + 2);
				if (!buffer) {
					pr_err("failed to set unprintable string '%s'\n", string);
					return bt_ctf_field_string_set_value(field, "UNPRINTABLE-STRING");
				}
				if (i > 0)
					strncpy(buffer, string, i);
			}
			strncat(buffer + p, numstr, 4);
			p += 3;
		}
	}

	if (!buffer)
		return bt_ctf_field_string_set_value(field, string);
	err = bt_ctf_field_string_set_value(field, buffer);
	free(buffer);
	return err;
}
Пример #10
0
Файл: attr.c Проект: Jaharmi/zsh
static int
bin_getattr(char *nam, char **argv, Options ops, UNUSED(int func))
{
    int ret = 0;
    int list_len, val_len = 0, attr_len = 0, slen;
    char *value, *file = argv[0], *attr = argv[1], *param = argv[2];
    int symlink = OPT_ISSET(ops, 'h');

    unmetafy(file, &slen);
    unmetafy(attr, NULL);
    list_len = xlistxattr(file, NULL, 0, symlink);
    if (list_len > 0) {
        val_len = xgetxattr(file, attr, NULL, 0, symlink);
        if (val_len == 0) {
            if (param)
                unsetparam(param);
            return 0;
        }
        if (val_len > 0) {
            value = (char *)zalloc(val_len+1);
            attr_len = xgetxattr(file, attr, value, val_len, symlink);
            if (attr_len > 0 && attr_len <= val_len) {
                value[attr_len] = '\0';
                if (param)
                    setsparam(param, metafy(value, attr_len, META_DUP));
                else
                    printf("%s\n", value);
            }
            zfree(value, val_len+1);
        }
    }
    if (list_len < 0 || val_len < 0 || attr_len < 0 || attr_len > val_len)  {
        zwarnnam(nam, "%s: %e", metafy(file, slen, META_NOALLOC), errno);
        ret = 1 + (attr_len > val_len || attr_len < 0);
    }
    return ret;
}
Пример #11
0
/*
 * Creates a new reason and initializes it with the provided reason
 * namespace and code. Also sets up the buffer and kcdata_descriptor
 * associated with the reason. Returns a pointer to the newly created
 * reason.
 *
 * Returns:
 * REASON_NULL if unable to allocate a reason or initialize the nested buffer
 * a pointer to the reason otherwise
 */
os_reason_t
os_reason_create(uint32_t osr_namespace, uint64_t osr_code)
{
	os_reason_t new_reason = OS_REASON_NULL;

	new_reason = (os_reason_t) zalloc(os_reason_zone);
	if (new_reason == OS_REASON_NULL) {
#if OS_REASON_DEBUG
		/*
		 * We rely on OS reasons to communicate important things such
		 * as process exit reason information, we should be aware
		 * when issues prevent us from allocating them.
		 */
		if (os_reason_debug_disabled) {
			kprintf("os_reason_create: failed to allocate reason with namespace: %u, code : %llu\n",
					osr_namespace, osr_code);
		} else {
			panic("os_reason_create: failed to allocate reason with namespace: %u, code: %llu\n",
					osr_namespace, osr_code);
		}
#endif
		return new_reason;
	}

	bzero(new_reason, sizeof(*new_reason));

	new_reason->osr_namespace = osr_namespace;
	new_reason->osr_code = osr_code;
	new_reason->osr_flags = 0;
	new_reason->osr_bufsize = 0;
	new_reason->osr_kcd_buf = NULL;

	lck_mtx_init(&new_reason->osr_lock, os_reason_lock_grp, os_reason_lock_attr);
	new_reason->osr_refcount = 1;

	return new_reason;
}
Пример #12
0
int
setup_(UNUSED(Module m))
{
    char **bpaste;

    /* Set up editor entry points */
    zle_entry_ptr = zle_main_entry;
    zle_load_state = 1;

    /* initialise the thingies */
    init_thingies();
    lbindk = NULL;

    /* miscellaneous initialisations */
    stackhist = stackcs = -1;
    kungetbuf = (char *) zalloc(kungetsz = 32);
    comprecursive = 0;
    rdstrs = NULL;

    /* initialise the keymap system */
    init_keymaps();

    varedarg = NULL;

    incompfunc = incompctlfunc = hascompmod = 0;
    hascompwidgets = 0;

    clwords = (char **) zshcalloc((clwsize = 16) * sizeof(char *));

    bpaste = zshcalloc(3*sizeof(char *));
    bpaste[0] = ztrdup("\033[?2004h");
    bpaste[1] = ztrdup("\033[?2004l");
    /* Intended to be global, no WARNCREATEGLOBAL check. */
    assignaparam("zle_bracketed_paste", bpaste, 0);

    return 0;
}
Пример #13
0
/**
 * of_to_full_path
 *
 * NOTE: Callers of this function are expected to free full_path themselves
 *
 * @param of_path
 * @returns full path on success, NULL otherwise
 */
char *
of_to_full_path(const char *of_path)
{
	char *full_path = NULL;
	int full_path_len;

	if (!strncmp(of_path, OFDT_BASE, strlen(OFDT_BASE))) {
		full_path = strdup(of_path);
		if (full_path == NULL)
			return NULL;
	} else {
		full_path_len = strlen(OFDT_BASE) + strlen(of_path) + 2;
		full_path = zalloc(full_path_len);
		if (full_path == NULL)
			return NULL;

		if (*of_path == '/')
			sprintf(full_path, "%s%s", OFDT_BASE, of_path);
		else
			sprintf(full_path, "%s/%s", OFDT_BASE, of_path);
	}

	return full_path;
}
Пример #14
0
void *
__MALLOC_ZONE(
	size_t		size,
	int		type,
	int		flags,
	vm_allocation_site_t *site)
{
	struct kmzones	*kmz;
	void		*elem;

	if (type >= M_LAST)
		panic("_malloc_zone TYPE");

	kmz = &kmzones[type];
	if (kmz->kz_zalloczone == KMZ_MALLOC)
		panic("_malloc_zone ZONE: type = %d", type);

/* XXX */
	if (kmz->kz_elemsize == (size_t)(-1))
		panic("_malloc_zone XXX");
/* XXX */
	if (size == kmz->kz_elemsize)
		if (flags & M_NOWAIT) {
	  		elem = (void *)zalloc_noblock(kmz->kz_zalloczone);
		} else {
	  		elem = (void *)zalloc(kmz->kz_zalloczone);
		}
	else
		if (flags & M_NOWAIT) {
			elem = (void *)kalloc_canblock(size, FALSE, site);
		} else {
			elem = (void *)kalloc_canblock(size, TRUE, site);
		}

	return (elem);
}
Пример #15
0
/* Parse perf-probe event definition */
void parse_perf_probe_event(const char *str, struct probe_point *pp,
			    bool *need_dwarf)
{
	char **argv;
	int argc, i;

	*need_dwarf = false;

	argv = argv_split(str, &argc);
	if (!argv)
		die("argv_split failed.");
	if (argc > MAX_PROBE_ARGS + 1)
		semantic_error("Too many arguments");

	/* Parse probe point */
	parse_perf_probe_probepoint(argv[0], pp);
	if (pp->file || pp->line || pp->lazy_line)
		*need_dwarf = true;

	/* Copy arguments and ensure return probe has no C argument */
	pp->nr_args = argc - 1;
	pp->args = zalloc(sizeof(char *) * pp->nr_args);
	for (i = 0; i < pp->nr_args; i++) {
		pp->args[i] = strdup(argv[i + 1]);
		if (!pp->args[i])
			die("Failed to copy argument.");
		if (is_c_varname(pp->args[i])) {
			if (pp->retprobe)
				semantic_error("You can't specify local"
						" variable for kretprobe");
			*need_dwarf = true;
		}
	}

	argv_free(argv);
}
Пример #16
0
/*
 * Allocate struct sackhole.
 */
static struct sackhole *
tcp_sackhole_alloc(struct tcpcb *tp, tcp_seq start, tcp_seq end)
{
	struct sackhole *hole;

	if (tp->snd_numholes >= tcp_sack_maxholes ||
	    tcp_sack_globalholes >= tcp_sack_globalmaxholes) {
		tcpstat.tcps_sack_sboverflow++;
		return NULL;
	}

	hole = (struct sackhole *)zalloc(sack_hole_zone);
	if (hole == NULL)
		return NULL;

	hole->start = start;
	hole->end = end;
	hole->rxmit = start;

	tp->snd_numholes++;
	OSIncrementAtomic(&tcp_sack_globalholes);

	return hole;
}
Пример #17
0
void wf(const char *name, FILE *fp) 
{
    table_t table = table_new(0, NULL, NULL);
    char buf[BUFSIZ];

    while (getword(fp, buf, sizeof(buf), first, rest)) {
        const char *word;
        int i, *count;
        for (i=0; buf[i] != '\0'; i++)
            buf[i] = tolower(buf[i]);
        word = atom_string(buf);
        count = table_get(table, word);
        if (count) {
            (*count) ++;
        } else {
            count = (int *)zalloc(sizeof (*count));
            *count = 1;
            table_put(table, word, count);
        }
    }

    if (name) {
        printf("%s:\n", name);
    }
    /* print the words */
    int i;
    void **array = table_to_array(table, NULL);
    qsort(array, table_length(table), 2*sizeof(*array), cmp);
    for (i = 0; array[i]; i+=2) {
        printf("%d\t%s\n", *(int *)array[i+1], (char *)array[i]);
    }
    zfree(array);

    /* destroy the table */
    table_free(&table, vfree);
}
Пример #18
0
static sym_lib_t *
lib_add(char *path, sym_type_t sym_type)
{
	sym_lib_t *lib, *p;
	sym_binary_t *binary;
	
	if ((lib = zalloc(sizeof (sym_lib_t))) == NULL) {
		return (NULL);
	}

	binary = &lib->binary;
	strncpy(binary->path, path, PATH_MAX);
	binary->path[PATH_MAX - 1] = 0;

	if (binary_sym_read(binary, sym_type) != 0) {
		free(lib);
		return (NULL);		
	}
	
	p = s_first_lib;
	s_first_lib = lib;
	lib->next = p;
	return (lib);
}
Пример #19
0
//
// Load a new font and create textures for each glyph
//
font *ttf_new (const char *name, int pointSize, int style)
{
    uint8 c;
    font *f;
    
    f = (fontp)zalloc(sizeof(*f));
    if (!f) {
        return (NULL);
    }

    f->name = strdup(name);
    f->ttf = TTF_OpenFont(name, pointSize);
    if (!f->ttf) {
        DIE("cannot open font file %s", name);
    }

    f->foreground.r = 255;
    f->foreground.g = 255;
    f->foreground.b = 255;
    f->background.r = 0;
    f->background.g = 0;
    f->background.b = 0;

    TTF_SetFontStyle(f->ttf, style);
    TTF_SetFontOutline(f->ttf, 0.5);
    f->height = TTF_FontHeight(f->ttf);
    f->ascent = TTF_FontAscent(f->ttf);
    f->descent = TTF_FontDescent(f->ttf);
    f->lineSkip = TTF_FontLineSkip(f->ttf);

    for (c = TTF_GLYPH_MIN; c < TTF_GLYPH_MAX; c++) {
        ttf_create_tex_from_char(f, c);
    }

    return (f);
}
Пример #20
0
static void add_size_to_ram_area(struct dt_node *ram_node,
				 const struct HDIF_common_hdr *hdr,
				 int indx_vpd)
{
	const void	*fruvpd;
	unsigned int	fruvpd_sz;
	const void	*kw;
	char		*str;
	uint8_t		kwsz;

	fruvpd = HDIF_get_idata(hdr, indx_vpd, &fruvpd_sz);
	if (!CHECK_SPPTR(fruvpd))
		return;

	/* DIMM Size */
	kw = vpd_find(fruvpd, fruvpd_sz, "VINI", "SZ", &kwsz);
	if (!kw)
		return;

	str = zalloc(kwsz + 1);
	memcpy(str, kw, kwsz);
	dt_add_property_string(ram_node, "size", str);
	free(str);
}
static int
emul_bugapi_do_read(os_emul_data *bugapi,
		    cpu *processor,
		    unsigned_word cia,
		    unsigned_word buf,
		    int nbytes)
{
  unsigned char *scratch_buffer;
  int status;

  /* get a tempoary bufer */
  scratch_buffer = (unsigned char *) zalloc(nbytes);

  /* check if buffer exists by reading it */
  emul_read_buffer((void *)scratch_buffer, buf, nbytes, processor, cia);

  /* read */
  status = device_instance_read(bugapi->input,
				(void *)scratch_buffer, nbytes);

  /* -1 = error, -2 = nothing available - see "serial" [IEEE1275] */
  if (status < 0) {
    status = 0;
  }

  if (status > 0) {
    emul_write_buffer((void *)scratch_buffer, buf, status, processor, cia);

    /* Bugapi chops off the trailing n, but leaves it in the buffer */
    if (scratch_buffer[status-1] == '\n' || scratch_buffer[status-1] == '\r')
      status--;
  }

  zfree(scratch_buffer);
  return status;
}
Пример #22
0
static int
launcher_direct_connect(struct weston_launcher **out, struct weston_compositor *compositor,
			int tty, const char *seat_id, bool sync_drm)
{
	struct launcher_direct *launcher;

	if (geteuid() != 0)
		return -EINVAL;

	launcher = zalloc(sizeof(*launcher));
	if (launcher == NULL)
		return -ENOMEM;

	launcher->base.iface = &launcher_direct_iface;
	launcher->compositor = compositor;

	if (setup_tty(launcher, tty) == -1) {
		free(launcher);
		return -1;
	}

	* (struct launcher_direct **) out = launcher;
	return 0;
}
Пример #23
0
/**
 * Start name resolution
 *
 * @v resolv		Name resolution interface
 * @v name		Name to resolve
 * @v sa		Socket address to complete
 * @ret rc		Return status code
 */
int resolv ( struct interface *resolv, const char *name,
	     struct sockaddr *sa ) {
	struct resolv_mux *mux;
	size_t name_len = ( strlen ( name ) + 1 );
	int rc;

	/* Allocate and initialise structure */
	mux = zalloc ( sizeof ( *mux ) + name_len );
	if ( ! mux )
		return -ENOMEM;
	ref_init ( &mux->refcnt, NULL );
	intf_init ( &mux->parent, &null_intf_desc, &mux->refcnt );
	intf_init ( &mux->child, &resmux_child_desc, &mux->refcnt );
	mux->resolver = table_start ( RESOLVERS );
	if ( sa )
		memcpy ( &mux->sa, sa, sizeof ( mux->sa ) );
	memcpy ( mux->name, name, name_len );

	DBGC ( mux, "RESOLV %p attempting to resolve \"%s\"\n", mux, name );

	/* Start first resolver in chain.  There will always be at
	 * least one resolver (the numeric resolver), so no need to
	 * check for the zero-resolvers-available case.
	 */
	if ( ( rc = resmux_try ( mux ) ) != 0 )
		goto err;

	/* Attach parent interface, mortalise self, and return */
	intf_plug_plug ( &mux->parent, resolv );
	ref_put ( &mux->refcnt );
	return 0;

 err:
	ref_put ( &mux->refcnt );
	return rc;	
}
Пример #24
0
WL_EXPORT struct wlb_keyboard *
wlb_keyboard_create(struct wlb_seat *seat)
{
	struct wlb_keyboard *keyboard;

	if (seat->keyboard)
		return NULL;

	keyboard = zalloc(sizeof *keyboard);
	if (!keyboard)
		return NULL;
	
	keyboard->seat = seat;

	wl_list_init(&keyboard->resource_list);
	wl_array_init(&keyboard->keys);
	keyboard->keymap.fd = -1;
	
	keyboard->surface_destroy_listener.notify = keyboard_surface_destroyed;

	seat->keyboard = keyboard;

	return keyboard;
}
Пример #25
0
  /*********************************************************************
   *
   * Function    :  enlist_unique_header
   *
   * Description :  Make a HTTP header from the two strings name and value,
   *                and append the result into a specified string list,
   *                if & only if there isn't already a header with that name.
   *
   * Parameters  :
   *          1  :  the_list = pointer to list
   *          2  :  name = HTTP header name (e.g. "Content-type")
   *          3  :  value = HTTP header value (e.g. "text/html")
   *
   * Returns     :  SP_ERR_OK on success
   *                SP_ERR_MEMORY on out-of-memory error.
   *                On error, the_list will be unchanged.
   *                "Success" does not indicate whether or not the
   *                header was already in the list.
   *
   *********************************************************************/
  sp_err miscutil::enlist_unique_header(std::list<const char*> *the_list,
                                        const char *name, const char *value)
  {
    sp_err result = SP_ERR_MEMORY;
    char *header;
    size_t header_size;

    assert(the_list);
    assert(name);
    assert(value);

    /* + 2 for the ': ', + 1 for the \0 */
    header_size = strlen(name) + 2 + strlen(value) + 1;
    header = (char*) zalloc(header_size);

    if (NULL != header)
      {
        const size_t bytes_to_compare = strlen(name) + 2;
        snprintf(header, header_size, "%s: %s", name, value);
        result = miscutil::enlist_unique(the_list, header, bytes_to_compare);
        freez(header);
      }
    return result;
  }
Пример #26
0
/**
 * Allocate pixel buffer
 *
 * @v width		Width
 * @h height		Height
 * @ret pixbuf		Pixel buffer, or NULL on failure
 */
struct pixel_buffer * alloc_pixbuf ( unsigned int width, unsigned int height ) {
	struct pixel_buffer *pixbuf;

	/* Allocate and initialise structure */
	pixbuf = zalloc ( sizeof ( *pixbuf ) );
	if ( ! pixbuf )
		goto err_alloc_pixbuf;
	ref_init ( &pixbuf->refcnt, free_pixbuf );
	pixbuf->width = width;
	pixbuf->height = height;
	pixbuf->len = ( width * height * sizeof ( uint32_t ) );

	/* Allocate pixel data buffer */
	pixbuf->data = umalloc ( pixbuf->len );
	if ( ! pixbuf->data )
		goto err_alloc_data;

	return pixbuf;

 err_alloc_data:
	pixbuf_put ( pixbuf );
 err_alloc_pixbuf:
	return NULL;
}
Пример #27
0
STATIC_INLINE_EMUL_NETBSD void
write_direntries(unsigned_word addr,
		 char *buf,
		 int nbytes,
		 cpu *processor,
		 unsigned_word cia)
{
  while (nbytes > 0) {
    struct dirent *out;
    struct dirent *in = (struct dirent*)buf;
    ASSERT(in->d_reclen <= nbytes);
    out = (struct dirent*)zalloc(in->d_reclen);
    memcpy(out/*dest*/, in/*src*/, in->d_reclen);
    H2T(out->d_fileno);
    H2T(out->d_reclen);
    H2T(out->d_type);
    H2T(out->d_namlen);
    emul_write_buffer(out, addr, in->d_reclen, processor, cia);
    nbytes -= in->d_reclen;
    addr += in->d_reclen;
    buf += in->d_reclen;
    free(out);
  }
}
Пример #28
0
struct param *rtm_param_add(struct session *session, const char *key,
						     const char *value)
{
	struct param *param, *p, *q;

	if (!session || !key || !value)
		return NULL;

	param = zalloc(sizeof(*param));
	if (!param)
		return NULL;

	param->key = strdup(key);
	param->value = strdup(value);

	q = &session->param_head;
	for (p = q->next; p != NULL; q = p, p = q->next)
		if (strcmp(key, p->key) < 0)
			break;
	param->next = p;
	q->next = param;

	return param;
}
Пример #29
0
void do_cluster_request(struct work *work)
{
	struct request *req = container_of(work, struct request, work);
	struct sd_req *hdr = (struct sd_req *)&req->rq;
	struct vdi_op_message *msg;
	size_t size;

	eprintf("%p %x\n", req, hdr->opcode);

	if (has_process_main(req->op))
		size = sizeof(*msg) + hdr->data_length;
	else
		size = sizeof(*msg);

	msg = zalloc(size);
	if (!msg) {
		eprintf("failed to allocate memory\n");
		return;
	}

	msg->req = *((struct sd_vdi_req *)&req->rq);
	msg->rsp = *((struct sd_vdi_rsp *)&req->rp);
	if (has_process_main(req->op))
		memcpy(msg->data, req->data, hdr->data_length);

	list_add_tail(&req->pending_list, &sys->pending_list);

	if (has_process_work(req->op))
		sys->cdrv->notify(msg, size, do_cluster_op);
	else {
		msg->rsp.result = SD_RES_SUCCESS;
		sys->cdrv->notify(msg, size, NULL);
	}

	free(msg);
}
Пример #30
0
WL_EXPORT int
pixman_renderer_init(struct weston_compositor *ec)
{
	struct pixman_renderer *renderer;

	renderer = zalloc(sizeof *renderer);
	if (renderer == NULL)
		return -1;

	renderer->repaint_debug = 0;
	renderer->debug_color = NULL;
	renderer->base.read_pixels = pixman_renderer_read_pixels;
	renderer->base.repaint_output = pixman_renderer_repaint_output;
	renderer->base.flush_damage = pixman_renderer_flush_damage;
	renderer->base.attach = pixman_renderer_attach;
	renderer->base.surface_set_color = pixman_renderer_surface_set_color;
	renderer->base.destroy = pixman_renderer_destroy;
	renderer->base.surface_get_content_size =
		pixman_renderer_surface_get_content_size;
	renderer->base.surface_copy_content =
		pixman_renderer_surface_copy_content;
	ec->renderer = &renderer->base;
	ec->capabilities |= WESTON_CAP_ROTATION_ANY;
	ec->capabilities |= WESTON_CAP_CAPTURE_YFLIP;
	ec->capabilities |= WESTON_CAP_VIEW_CLIP_MASK;

	renderer->debug_binding =
		weston_compositor_add_debug_binding(ec, KEY_R,
						    debug_binding, ec);

	wl_display_add_shm_format(ec->wl_display, WL_SHM_FORMAT_RGB565);

	wl_signal_init(&renderer->destroy_signal);

	return 0;
}