Exemplo n.º 1
0
static void frame_callback(const char *frame_data, size_t len, void *userdata)
{
	size_t image_len;
	char *image;
	struct json_internal *json = userdata;

	if (!json)
		return;

	if (frame_data && len) {
		/* 'image' should be freed by the client */
		image_len = modp_b64_decode_len(len);
		image = ec_malloc(image_len);
		image_len = modp_b64_decode(image, frame_data, len);

		if (image_len != -1)
			json->frame_callback(image, image_len, json->userdata);
		else
			goto fail;

		/* Success! */
		return;
	}

fail:
	/*
	 * Failure
	 * If image decoding failed, call frame_callback() with a NULL argument,
	 * to let the client know about the error.
	 */
	json->frame_callback(NULL, 0, json->userdata);

}
Exemplo n.º 2
0
static ec_hash hash_alloc( void )
{
	ec_hash table;

	table = (ec_hash) ec_malloc( sizeof(struct ec_hash_struct) );
	return table;
}
Exemplo n.º 3
0
static EC_OBJ match_copy( EC_OBJ obj, EcCopyType type )
{
	ov_int *ovector;
	EcInt   ovecsize;
	EC_OBJ  regexp_copy, subject_copy;

	if (type == EcShallowCopyType)
	{
		regexp_copy  = EC_MATCH_REGEXP(obj);
		subject_copy = EC_MATCH_SUBJECT(obj);
	}
	else
	{
		regexp_copy = EcCopy( EC_MATCH_REGEXP(obj), EcDeepCopyType );
		if (EC_ERRORP(regexp_copy)) return regexp_copy;
		subject_copy = EcCopy( EC_MATCH_SUBJECT(obj), EcDeepCopyType );
		if (EC_ERRORP(subject_copy)) return subject_copy;
	}

	/* copy the ovector */
	ovecsize = EC_MATCH_OVECSIZE(obj);
	ovector = ec_malloc( sizeof(ov_int) * ovecsize );
	if (! ovector)
		return EcMemoryError();
	memcpy( ovector, EC_MATCH_OVECTOR(obj), sizeof(ov_int) * ovecsize );

	return make_match( regexp_copy, subject_copy, ovector, ovecsize, EC_MATCH_NSUB(obj) );
}
Exemplo n.º 4
0
EC_API EC_OBJ EcMakeUString( const Uchar *ustring, EcInt len , EcBool duplicate )
{
	EC_OBJ obj;
	EcInt l;

	obj = EcMakeUser( tc_ustring, NULL );
	if (EC_ERRORP(obj)) return obj;

	if (len > 0) l = len;
	else l = ustring ? uni_strlen( ustring ) : 0;

	EC_USTRLEN(obj) = 0;

	if (duplicate) {
		EC_USTRDATA(obj) = ec_malloc((l + 1) * sizeof(Uchar));
		if (! EC_USTRDATA(obj)) return Ec_ERROR;
		uni_strcpy(EC_USTRDATA(obj), ustring);
	} else {
		EC_USTRDATA(obj) = ustring;
	}

	EC_USTRLEN(obj) = l;

	return obj;
}
Exemplo n.º 5
0
static void sendpkg(avl_t *a, int sfd) {
    if (a != NULL) {
        int pkglen = 0;
        int nlen = 0;
        int vlen = 0;
        char *str = NULL;
        pkg *ptr = NULL;

        sendpkg(a->left, sfd);

        ptr = (pkg *)a->key;


        /* Make sure there is room for the \'0' */
        nlen = strlen(ptr->name) + 1;
        vlen = strlen(ptr->version) + 1;

        /* Include room for the '\n' */
        pkglen = nlen + vlen + 1;

        str = (char *)ec_malloc(sizeof(char) * pkglen, __FILE__, __LINE__);
        strncpy(str, ptr->name, nlen);
        strncat(str, "-", 1);
        strncat(str, ptr->version, vlen);
        strncat(str, "\n", 1);

        send(sfd, str, strlen(str), 0);

        free(str);
        sendpkg(a->right, sfd);
    }
}
Exemplo n.º 6
0
struct preconditioner *new_preconditioner(int n, int nlevels)
{
	struct preconditioner *precon = ec_malloc(sizeof(*precon));
	precon->level = 0;
	precon->nmg = new_int_array(nlevels);
	for (int i = 0; i < nlevels; ++i) {
		precon->nmg[i] = max(2, (n - 1) / int_pow(2, i) + 1);
		if (precon->nmg[i] == 2) {
			nlevels = i + 1;
			break;
		}
	}
	precon->nlevels = nlevels;
	precon->geom = new_ptr_array(nlevels, 0, NULL);
	precon->basis = new_ptr_array(2 * nlevels - 1, 0, NULL);
	precon->poisson_diag = new_ptr_array(nlevels, 0, NULL);
	precon->helmholtz_diag = new_ptr_array(nlevels, 0, NULL);
	precon->stiffsum_scale = new_ptr_array(nlevels, 0, NULL);
	precon->dirichlet_mask = new_ptr_array(nlevels, 0, NULL);
	precon->sendcounts = new_ptr_array(nlevels, 0, NULL);
	precon->senddispls = new_ptr_array(nlevels, 0, NULL);
	precon->poisson_eigen_max = new_1d_array(nlevels);
	precon->helmholtz_eigen_max = new_1d_array(nlevels);

	return precon;
}
Exemplo n.º 7
0
EC_API EC_OBJ EcMakeClass( EC_OBJ package, EC_OBJ superclass, const char *name )
{
	EC_OBJ obj;
	char *clscodename;
	ec_string ds;

	clscodename = alloca( strlen( name ) + strlen( CODE_SUFFIX ) + 1 );
	if (! clscodename) return Ec_ERROR;

	strcpy( clscodename, name );
	strcat( clscodename, CODE_SUFFIX );

	obj = EcMakeUser( tc_class, NULL );
	if (EC_ERRORP(obj)) return obj;

	EC_CLASS(obj) = ec_malloc( sizeof(EcClass) );
	if (! EC_CLASS(obj)) return Ec_ERROR;

	EC_CLASSSUPER(obj)     = superclass;

	EC_CLASSNMETHODS(obj)  = 0;
	EC_CLASSMTABLE(obj)    = NULL;

	EC_CLASSNCMETHODS(obj) = 0;
	EC_CLASSCMTABLE(obj)   = NULL;

	EC_CLASSIOFFSET(obj)   = EC_NNULLP(superclass) ? EC_CLASSNIVARS(superclass) : 0;
	EC_CLASSNIVARS(obj)    = EC_NNULLP(superclass) ? EC_CLASSNIVARS(superclass) : 0;
	EC_CLASSIVTABLE(obj)   = NULL;

	EC_CLASSNCVARS(obj)    = 0;
	EC_CLASSCVTABLE(obj)   = NULL;

	ec_string_init( &ds, NULL );
	ec_sprintf( &ds, "%w.%s", EC_PACKAGENAME(package), name );
	EC_CLASSPACKAGE(obj)   = package;
	EC_CLASSNAME(obj)      = EcMakeString( ec_strdata( &ds ), ec_strlen( &ds ) );
	EC_CLASSSHORTNAME(obj) = EcMakeString( name, 0 );
	EC_CLASSCODE(obj)      = EcMakeCompiled( package, clscodename,
											 0,					/* req. parameters      */
											 0,					/* params with defaults */
											 FALSE,				/* varags               */
											 FALSE, NULL );			/* is a method ?        */
	ec_string_cleanup( &ds );

	/* Set appropriately the various fields */

	if (EC_NNULLP(EC_CLASSSUPER(obj)))
	{
		EC_CLASSIOFFSET(obj) = EC_CLASSNIVARS(EC_CLASSSUPER(obj));
		EC_CLASSNIVARS(obj)  = EC_CLASSNIVARS(EC_CLASSSUPER(obj));
	}
	else
	{
		EC_CLASSIOFFSET(obj) = 0;
		EC_CLASSNIVARS(obj)  = 0;
	}

	return obj;
}
Exemplo n.º 8
0
//makeList() initalizes a LinkedList
//size : the size of the elements which will go in the list
//			this is user supplied and is assumed to be correct
//returns : a pointer to a LinkedList with 0 elements
//			fails fatally if it cannot allocate memory
LinkedList makeList(size_t size){
	LinkedList newList = ec_malloc(sizeof(LinkedList));
	newList->elementSize=size;
	newList->begining = NULL;
	newList->end = NULL;
	return newList;
}
Exemplo n.º 9
0
/*
 * libcurl keeps the socket open when possible
 */
struct appbase *appbase_open(const char *app_name,
		const char *username, const char *password,
		bool enable_streaming)
{
	struct appbase *ab =
			ec_malloc(sizeof(struct appbase));

 	/* Initialize libcurl, and set up our Appbase REST URL */
	ab->curl = curl_easy_init();
	if (!ab->curl)
		goto fatal;

	curl_easy_setopt(ab->curl, CURLOPT_VERBOSE, 0L);
	curl_easy_setopt(ab->curl, CURLOPT_NOPROGRESS, 1L);
	curl_easy_setopt(ab->curl, CURLOPT_WRITEFUNCTION, writer_cb);
	curl_easy_setopt(ab->curl, CURLOPT_WRITEDATA, NULL);

	ab->url = appbase_generate_url(app_name, username, password, enable_streaming);
	if (!ab->url)
		goto fatal;

	/* Create our base JSON object */
	ab->json = json_object_new_object();
	if (!ab->json)
		goto fatal;

	return ab;

fatal:
	appbase_close(ab);
	return NULL;
}
Exemplo n.º 10
0
Arquivo: dev.c Projeto: juaristi/ajws
static bool
dev_get_mac_addr(ajws_dev_t *dev)
{
	int i;
	char prefix[] = "/sys/class/net/", suffix[] = "/address";
#define DEV_NAME_LEN (sizeof(prefix) + strlen(dev->name) + sizeof(suffix))
	char *path = (char *) ec_malloc (DEV_NAME_LEN);

	strcpy(path, prefix);
	strcat(path, dev->name);
	strcat(path, suffix);

	FILE *f = fopen(path, "r");
	if (!f)
		return false;

	for (i = 0; i < MAC_ADDR_LEN; i++)
	{
		dev->mac_addr[i] = (read_hex_number(f) << 4) + read_hex_number(f);

		/* Skip the semicolon */
		read_hex_number(f);
	}

	fclose(f);
	return true;
}
Exemplo n.º 11
0
EC_API EC_OBJ EcMakeObject( EC_OBJ ofclass, void *user )
{
	EC_OBJ obj;
	EcInt nvars;

	obj = EcMakeUser( tc_object, NULL );
	if (EC_ERRORP(obj)) return obj;

	EC_OBJECT(obj) = ec_malloc( sizeof(EcObject) );
	if (! EC_OBJECT(obj)) return Ec_ERROR;

	EC_OBJECTCLASS(obj) = ofclass;
	nvars = EC_CLASSNIVARS(ofclass);

#if 0
	nvars = 0;
	inclass = ofclass;
	ec_msg_printf("of class %w\n", ofclass);
	while (EC_CLASSP(inclass)) {
		ec_msg_printf("  in class %w: ivars = %I\n", inclass, EC_CLASSNIVARS(inclass));
		nvars += EC_CLASSNIVARS(inclass);
		inclass = EC_CLASSSUPER(inclass);
	}
#endif

	if (nvars)
	{
		EcInt   i;
		EC_OBJ *objp;

		EC_OBJECTIVARS(obj) = ec_malloc( nvars * sizeof(EC_OBJ) );
		if (! EC_OBJECTIVARS(obj))
		{
			/* TODO XXX: how to handle this situation ? */
			/* EcAlert( EcFatal, "out of memory while building object" ); */
			return Ec_ERROR;
		}
		objp = EC_OBJECTIVARS(obj);
		for (i = 0; i < nvars; i++)
			*objp++ = EcUndefinedObject;
	}
	else
		EC_OBJECTIVARS(obj) = NULL;
	EC_OBJECTUSER(obj) = user;

	return obj;
}
Exemplo n.º 12
0
static PyObject
*gnm_hello(PyObject *self, PyObject *args) {
	struct module_state *st = GETSTATE(self);

	struct tcpstat *stats;
	FILE* fp;
	size_t nread;
	struct filter current_filter;
	int stats_length;

	fp = fopen(TCP_FILE, "r");

	if (fp == NULL)
		fatal("in main() while opening file");

	memset(&current_filter, 0, sizeof(current_filter));

	stats = (struct tcpstat*) ec_malloc(256 * sizeof(struct tcpstat));
	memset(stats, 0, sizeof(struct tcpstat) * 256);

	stats = generic_record_read(fp, &stats_length, AF_INET);

	fclose(fp);

	PyObject *dict = PyDict_New();
	PyObject *dictLocAddr = PyDict_New();
	PyObject *dictRemAddr = PyDict_New();
	PyObject *locAddr = NULL;
	PyObject *remAddr = NULL;

	int i = 0;
	for (i; i < stats_length; i++) {
                char bufl[1024];
                char *apl = bufl;
                char bufr[1024];
                char *apr = bufr;

                apl = inet_ntop(AF_INET, stats[i].local.data, bufl, INET_ADDRSTRLEN);
		apr = inet_ntop(AF_INET, stats[i].remote.data, bufr, INET_ADDRSTRLEN);

                locAddr = Py_BuildValue("s", strcmp(apl, "0.0.0.0") ? apl : "*");
                remAddr = Py_BuildValue("s", strcmp(apr, "0.0.0.0") ? apr : "*");
                PyObject *index = Py_BuildValue("i",i);

                PyDict_SetItem(dictLocAddr, index, locAddr);
                PyDict_SetItem(dictRemAddr, index, remAddr);
	}
	dict = Py_BuildValue(
			"{"
			"	s:O,"
			"       s:O"
			"}",
			"Dir Local.", dictLocAddr,
	                "Dir Remota.", dictRemAddr
	                );
        //Py_DECREF(dict);

	return (PyObject *) dict; //raise an exception
}
Exemplo n.º 13
0
int main(int argc, char *argv[]) {
    int userid, fd; //file descriptor
    char *buffer, *datafile;

    buffer = (char *) ec_malloc(100);
    datafile = (char *) ec_malloc(20);
    strcpy(datafile, "/var/notes");

    if (argc < 2)
        usage(argv[0], datafile);

    printf("%d\n",argc);
    strcpy(buffer, argv[1]);   // copy into buffer

    printf("[DEBUG] buffer   @ %p \'%s\'\n",buffer,buffer);
    printf("[DEBUG] datafile @ %p \'%s\'\n",datafile,datafile);

    strncat(buffer, "\n", 1);  // add a newline to the end

// Opening File
    fd = open(datafile, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR);
    if (fd == -1)
        fatal("in main while opening file");
    printf("[DEBUG] file descriptor is %d\n",fd);
    
    userid = getuid();

//Writing data
    if (write(fd, &userid, 4) == -1)
        fatal("in main while writing userid to file");
    write(fd, "\n", 1);  // terminate line

    if (write(fd, buffer, strlen(buffer)) == -1)
        fatal("in main while writing buffer to file");
    write(fd, "\n", 1);  // terminate line

// Closing file
    if (close(fd) == -1)
        fatal("in main while closing file");

    printf("Note has been saved.\n");
    free(buffer);
    free(datafile);
return 0;
}
Exemplo n.º 14
0
int main(int argc, char * argv[]) {
   int userid, fd;  // file descriptor
   char * buffer, * datafile;

   buffer = (char *) ec_malloc(100);
   datafile = (char *) ec_malloc(20);
   strcpy(datafile, "/var/notes");

   if (argc < 2)                 // If there aren't command line arguments
      usage(argv[0], datafile);  // display usage message and exit

   strcpy(buffer, argv[1]);       // Copy into buffer.

   printf("[DEBUG] buffer   @ %p: \'%s\'\n", buffer, buffer);
   printf("[DEBUG] datafile @ %p: \'%s\'\n", datafile, datafile);

   strncat(buffer, "\n", 1);  // Add a newline on the end

   // Opening file
   fd = open(datafile, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR);
   if (fd == -1)
      fatal("in main() while opening file");
   printf("[DEBUG] file descriptor is %d\n", fd);

   userid = getuid(); // Get the real userid

   // Writing data
   if (write(fd, &userid, 4) == -1) // Write userid before note data
      fatal("in main() while writing userid to file");
   write(fd, "\n", 1); // Terminate line

   if (write(fd, buffer, strlen(buffer)) == -1)
      fatal("in main() while writing buffer to file");
   write(fd, "\n", 1); // Terminate line

   // Closing file
   if (close(fd) == -1)
      fatal("in main() while closing file");

   printf("Note has been saved.\n");
   free(buffer);
   free(datafile);
}
Exemplo n.º 15
0
bool appbase_push_frame(struct appbase *ab,
		const unsigned char *data, size_t length,
		struct timeval *timestamp)
{
	CURLcode response_code;
	struct json_internal json;
	size_t b64_size = 0;
	char *b64_data;

	if (!ab || !ab->curl || !ab->url || !ab->json || !data || !length || !timestamp)
		return false;

	/* Transform raw frame data into base64 */
	b64_size = modp_b64_encode_len(length);
	b64_data = ec_malloc(b64_size);
	if (modp_b64_encode(b64_data, (char *) data, length) == -1)
		return false;

	/*
	 * Generate a JSON object with the format:
	 *
	 * 	{
	 * 		"image": "<data>",
	 * 		"sec": "<seconds>",
	 * 		"usec": "<milliseconds>"
	 * 	}
	 */
	json_object_object_add(ab->json, AB_KEY_IMAGE, json_object_new_string(b64_data));
	json_object_object_add(ab->json, AB_KEY_SEC, json_object_new_int64(timestamp->tv_sec));
	json_object_object_add(ab->json, AB_KEY_USEC, json_object_new_int64(timestamp->tv_usec));

	json.json = json_object_to_json_string_ext(ab->json, JSON_C_TO_STRING_PLAIN);
	json.length = strlen(json.json);
	json.offset = 0;

	curl_easy_setopt(ab->curl, CURLOPT_URL, ab->url);
	curl_easy_setopt(ab->curl, CURLOPT_UPLOAD, 1L);
	curl_easy_setopt(ab->curl, CURLOPT_INFILESIZE, json.length);
	curl_easy_setopt(ab->curl, CURLOPT_READDATA, &json);
	curl_easy_setopt(ab->curl, CURLOPT_READFUNCTION, reader_cb);

	response_code = curl_easy_perform(ab->curl);

	/*
	 * No need to free the JSON string.
	 * We call json_object_put() on the root JSON object in appbase_close(),
	 * and it will release the whole JSON object, including this string
	 * for us.
	 */
	json.length = 0;
	json.offset = 0;
	free(b64_data);

	return (response_code == CURLE_OK);
}
Exemplo n.º 16
0
int main(int argc, char *argv[]) {
   int userid, fd; // ファイル記述子
   char *buffer, *datafile;

   buffer = (char *) ec_malloc(100); 
   datafile = (char *) ec_malloc(20); 
   strcpy(datafile, "/var/notes");

   if(argc < 2)                 // コマンドライン引数が与えられていない場合、
      usage(argv[0], datafile); // 使用方法を表示して終了する。

   strcpy(buffer, argv[1]);  // コマンドライン引数をバッファにコピーする。

   printf("[DEBUG] buffer   @ %p: \'%s\'\n", buffer, buffer); 
   printf("[DEBUG] datafile @ %p: \'%s\'\n", datafile, datafile);

// ファイルのオープン
   fd = open(datafile, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR); 
   if(fd == -1)
      fatal("main()内、ファイルのオープン中にエラーが発生しました。"); 
   printf("[DEBUG] ファイル記述子:%d\n", fd);

   userid = getuid(); // 実ユーザIDを取得する。

// データの書き込み
   if(write(fd, &userid, 4) == -1) // メモの前にユーザIDを書き込む。
      fatal("main()内、ファイルへのユーザIDの書き込みでエラーが発生しました。");
   write(fd, "\n", 1); // 改行する。

   if(write(fd, buffer, strlen(buffer)) == -1) // メモを書き込む。
      fatal("main()内、ファイルへのバッファの書き込みでエラーが発生しました。"); 
   write(fd, "\n", 1); // 改行する。

// ファイルのクローズ
   if(close(fd) == -1) 
      fatal("main()内、ファイルのクローズ中にエラーが発生しました。");

   printf("メモが保存されました\n");
   free(buffer); 
   free(datafile);
}
Exemplo n.º 17
0
EC_API ec_list ec_list_create( void )
{
	ec_list list;

	list = (ec_list) ec_malloc( sizeof(struct ec_list_struct) );
	if (! list) return NULL;

	make_magic_list(list);
	HEAD(list) = NULL;
	check_list(list);
	return list;
}
Exemplo n.º 18
0
EC_API ec_hash_iterator ec_hash_iterator_create( ec_hash table )
{
	ec_hash_iterator iterator;

	ENTERF;
	iterator = (ec_hash_iterator) ec_malloc( sizeof(struct ec_hash_iterator_struct) );
	if (! iterator) return NULL;

	iterator->hash = table;
	iterator->next = 0;

	return iterator;
}
Exemplo n.º 19
0
static ec_list_node alloc_node( EcAny key, EcAny data )
{
	ec_list_node node;

	node = (ec_list_node) ec_malloc( sizeof(struct ec_list_node_struct) );
	if (! node) return NULL;

	make_magic_node(node);
	NEXT(node) = NULL;
	KEY(node)  = key;
	DATA(node) = data;
	return node;
}
Exemplo n.º 20
0
EC_API ec_list_iterator ec_list_iterator_create( ec_list list )
{
	ec_list_iterator iter;

	check_list(list);
	iter = (ec_list_iterator) ec_malloc( sizeof(struct ec_list_iterator_struct) );
	if (! iter) return NULL;

	make_magic_iter(iter);
	ITLIST(iter) = list;
	ITPOS(iter)  = HEAD(ITLIST(iter));
	check_iter(iter);
	return iter;
}
Exemplo n.º 21
0
EC_API EcInt ec_vasprintf( char **sres, const char *format, va_list ap )
{
	EcInt res;
	ec_string ds;

	ec_string_init( &ds, NULL );
	res = ec_vsprintf( &ds, format, ap );
	*sres = ec_malloc( ec_strlen( &ds ) );
	if (! *sres)
	{
		ec_string_cleanup( &ds );
		return -1;
	}
	memcpy( *sres, ec_strdata( &ds ), ec_strlen( &ds ) );
	ec_string_cleanup( &ds );
	return res;
}
Exemplo n.º 22
0
Arquivo: dev.c Projeto: juaristi/ajws
static bool
__dev_cmp_ipaddr(struct ifaddrs *iface, ajws_dev_t *dev)
{
	in_addr_t ipaddrs[] = {
			((struct sockaddr_in *)iface->ifa_addr)->sin_addr.s_addr,
			dev->addr.sin_addr.s_addr
	};

	if (ipaddrs[0] == ipaddrs[1])
	{
		dev->name = (char *) ec_malloc(strlen(iface->ifa_name) + 1);
		strcpy(dev->name, iface->ifa_name);
		return true;
	}

	return false;
}
Exemplo n.º 23
0
static EC_OBJ make_match( EC_OBJ regexp, EC_OBJ subject, ov_int *ovector, EcInt ovecsize, EcInt nsub )
{
	EC_OBJ obj;
	struct match_struct *match_s;

	match_s = (struct match_struct *) ec_malloc( sizeof(struct match_struct) );
	if (! match_s) return EcMemoryError();

	match_s->regexp   = regexp;
	match_s->subject  = subject;
	match_s->ovector  = ovector;
	match_s->ovecsize = ovecsize;
	match_s->nsub     = nsub;

	obj = EcMakeUser( tc_match, match_s );
	if (EC_ERRORP(obj)) return obj;

	return obj;
}
Exemplo n.º 24
0
/*
 * JSON Streamer public API
 */
struct json_streamer *json_streamer_init(json_streamer_frame_cb_t fcb, void *userdata)
{

	struct json_streamer *json = ec_malloc(sizeof(struct json_streamer));

	if (!fcb)
		goto fail;

	json->frame_callback = fcb;
	json->userdata = userdata;
	json->ctx = NULL;
	yajl_init(json, fcb, userdata, false);

	return json;

fail:
	free(json);
	return NULL;
}
Exemplo n.º 25
0
EC_API EC_OBJ EcMakeArray( EcInt dim )
{
	EC_OBJ obj;
	EcInt  ndim;

	obj = EcMakeUser( tc_array, NULL );
	if (EC_ERRORP(obj)) return obj;

	ndim  = (dim + (EcInt)ARRAY_INITIAL_SIZE) / (EcInt)ARRAY_INITIAL_SIZE;
	ndim *= (EcInt)ARRAY_INITIAL_SIZE;

	if (ndim < dim)
		ndim = dim;

	EC_ARRAYMEM(obj)  = ec_malloc( ndim * sizeof(EC_OBJ) );
	EC_ARRAYLEN(obj)  = 0;
	EC_ARRAYREAL(obj) = EC_ARRAYMEM(obj) ? ARRAY_INITIAL_SIZE : 0;

	return obj;
}
Exemplo n.º 26
0
static void yajl_init(struct json_streamer *json, json_streamer_frame_cb_t fcb, void *userdata, bool reinit)
{
	struct json_streamer_state_ctx *ctx = json->ctx;

	if (!ctx)
		ctx = ec_malloc(sizeof(struct json_streamer_state_ctx));

	ctx->cur_state = waiting;
	ctx->frame_callback = fcb;
	ctx->userdata = userdata;

	/* Save pointer so that we can free it later in json_streamer_destroy() */
	json->ctx = ctx;

	if (reinit) {
		yajl_complete_parse(json->yajl);
		yajl_free(json->yajl);
	}

	json->yajl = yajl_alloc(&yajl_cbs, NULL, ctx);
}
Exemplo n.º 27
0
EC_API char *EcQualifiedString( EcQualifiedSymbol *qsymbol )
{
	EcInt i;
	EcInt len;
	char *string;

	len = qualified_len( qsymbol );
	string = ec_malloc( len + 1 );
	if (! string)
		return NULL;

	string[0] = '\0';
	for (i = 0; i < QSLEN(qsymbol); i++)
	{
		strcat( string, EcSymbolAt( QSCOMP(qsymbol, i) ) );

		if (i + 1 < QSLEN(qsymbol))
			strcat( string, "." );
	}

	return string;
}
Exemplo n.º 28
0
EC_API EcBool ec_arena_create( ec_arena *arena, EcUInt initial_size )
{
	ASSERT(arena);

	arena->mem  = NULL;
	arena->last = NULL;
	arena->head = NULL;
	arena->tail = NULL;
	arena->size = 0;

	if (initial_size)
	{
		arena->mem = (EcUInt *) ec_malloc( sizeof(EcUInt) * initial_size );
		if (! arena->mem) return FALSE;
		arena->size = initial_size;
		arena->last = arena->mem + (initial_size - 1);
		arena->head = arena->mem;
		arena->tail = arena->mem;
	}

	return TRUE;
}
Exemplo n.º 29
0
/**
 * Function partially copied from ss command
 * see http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2
 */
static struct tcpstat*
generic_record_read(FILE *fp, int *index, int fam)
{
	char line[256];
	struct tcpstat *tcp_pkt, *value;
	*index = 0;

	tcp_pkt = (struct tcpstat*) ec_malloc(256*sizeof(struct tcpstat));
	memset(tcp_pkt, 0, sizeof(struct tcpstat) *256 );
	/* Skip Header */
	if (fgets(line, sizeof(line), fp) == NULL)
		goto outerr;

	while (fgets(line, sizeof(line), fp) != NULL)
	{
		//printf(line);
		int n = strlen(line);
		if (n == 0 || line[n - 1] != '\n')
		{
			errno = -EINVAL;
			memset(tcp_pkt, 0, sizeof(tcp_pkt));
			return tcp_pkt;
		}
		line[n - 1] = 0;
		value = tcp_show_line(line, fam); //TODO: check for errors
		tcp_pkt[(*index)++] = *value;

	}
	free(value);

	return tcp_pkt;

	outerr:

	/* return ferror(fp) ? -1 : 0; */
	if (ferror(fp))
		//fatal("in generic_record_read(), while skiping header");
		return NULL;
}
Exemplo n.º 30
0
LLIterator initLLIterator(const LinkedList list){
	LLIterator newIterator = ec_malloc(sizeof(LLIterator));;
	newIterator->marker = list->begining;
	newIterator->list = list;
	return newIterator;
}