Example #1
0
static SeafRepo* create_repo (const char *repo_name)
{
    SeafRepo *repo;
    const char *repo_id;
    GError *error = NULL;
    char *wt_path;
    char cmd[1024];

    wt_path = g_build_filename (WORKTREE_DIR, repo_name, NULL);
    snprintf (cmd, 1024, "cp -R %s/data %s", TEST_DIR, wt_path);
    int ret = system (cmd);
    if (ret < 0 || WEXITSTATUS(ret) != 0) {
        fprintf (stderr, "Failed to copy data\n");
        exit (1);
    }

    /* create a non encrypted repo */
    repo_id = seafile_create_repo (repo_name, "test",
                "example@abc.com", NULL, &error);
    if (!repo_id) {
        fprintf (stderr, "Failed to create repo: %s.\n", error->message);
        exit (1);
    }
    repo = seaf_repo_manager_get_repo (seaf->repo_mgr, repo_id);
   
    g_free (wt_path);
    return repo;
}
Example #2
0
void
typecheck_visit_assignment_stmt (struct _Visitor *visitor, struct AstNode *node)
{
    struct AstNode *lnode = node->children;
    struct AstNode *rnode = lnode->sibling;

    ast_node_accept(lnode, visitor);
    ast_node_accept(rnode, visitor);

    if (symbol_is_procfunc(lnode->symbol) && (_inside_procfunc == NULL ||
        strcmp(_inside_procfunc->children->symbol->name,
               lnode->symbol->name))) {
        node->type = ERROR;
        fprintf(stderr,
                "Error: Symbol '%s' is a function identifier, you cannot "
                "assign a value to it from outside the said function. "
                "Check line %d.\n", lnode->symbol->name, node->linenum);

    } else if (lnode->type != ERROR && rnode->type != ERROR &&
               lnode->type != rnode->type) {
        node->type = ERROR;
        fprintf(stderr,
                "Error: Incompatible types on assignment "
                "operation in line %d.\n", node->linenum);
    }
}
Example #3
0
static int vhost_verify_ring_mappings(struct vhost_dev *dev,
                                      uint64_t start_addr,
                                      uint64_t size)
{
    int i;
    for (i = 0; i < dev->nvqs; ++i) {
        struct vhost_virtqueue *vq = dev->vqs + i;
        target_phys_addr_t l;
        void *p;

        if (!ranges_overlap(start_addr, size, vq->ring_phys, vq->ring_size)) {
            continue;
        }
        l = vq->ring_size;
        p = cpu_physical_memory_map(vq->ring_phys, &l, 1);
        if (!p || l != vq->ring_size) {
            fprintf(stderr, "Unable to map ring buffer for ring %d\n", i);
            return -ENOMEM;
        }
        if (p != vq->ring) {
            fprintf(stderr, "Ring buffer relocated for ring %d\n", i);
            return -EBUSY;
        }
        cpu_physical_memory_unmap(p, l, 0, 0);
    }
    return 0;
}
Example #4
0
VOID	PolyPrint(OBJECT *po)
	{
	INT	i, j;
	INT	*vindex;		/* Ptr to vertex index. 	     */
	VEC3	*vlist, *vptr;		/* Ptr to vertex list.		     */
	POLY	*pp;			/* Ptr to polygon data. 	     */
	ELEMENT *pe;			/* Ptr to polygon element.	     */

	pe = po->pelem;
	fprintf(stderr, "\tpolygon: %ld polygons.\n", po->numelements);

	for (i = 0; i < po->numelements; i++)
		{
		pp = (POLY *)pe->data;

		fprintf(stderr, "\t\tVertices: %ld  Plane eq: %f %f %f %f\n", pp->nverts, pp->norm[0], pp->norm[1], pp->norm[2], pp->d);

		vlist  = pp->vptr;
		vindex = pp->vindex;

		for (j = 0; j < pp->nverts; j++)
			{
			vptr = vlist + (*vindex);
			fprintf(stderr, "\t\t%f %f %f \n", (*vptr)[0], (*vptr)[1], (*vptr)[2]);
			vindex++;
			}

		pe++;
		}
	}
void CmdHeaptrace::printGraphToFile(DebuggerClient &client,
                                    String filename,
                                    const GraphFormat &gf) {
  const char *name = filename->data();
  FILE *graphFile = fopen(name, "w");
  if (!graphFile) {
    client.print("Could not open file!");
    return;
  }

  fprintf(graphFile, "%s", gf.prologue.c_str());
  for (const auto &pair : m_accum.typesMap) {
    std::string n = gf.stringifyNode((TypedValue *)pair.first,
                                     typeName(pair.second));
    fprintf(graphFile, "%s", n.c_str());
    std::vector<int64_t> &adjList = m_accum.adjacencyList[pair.first];
    for (const int64_t adjacent : adjList) {
      std::string e = gf.stringifyEdge((TypedValue *)pair.first,
                                       (TypedValue *)adjacent);
      fprintf(graphFile, "%s", e.c_str());
    }
  }
  fprintf(graphFile, "%s", gf.epilogue.c_str());
  fclose(graphFile);

  client.print(folly::stringPrintf("Wrote heap graph to %s.", name));
}
Example #6
0
void CenterModel(Model *m)
{
    int i;
    float maxx = -1e10, maxy = -1e10, maxz = -1e10, minx = 1e10, miny = 1e10, minz = 1e10;

    for (i = 0; i < m->numVertices; i++)
    {
        if (m->vertexArray[3 * i] < minx) minx = m->vertexArray[3 * i];
        if (m->vertexArray[3 * i] > maxx) maxx = m->vertexArray[3 * i];
        if (m->vertexArray[3 * i+1] < miny) miny = m->vertexArray[3 * i+1];
        if (m->vertexArray[3 * i+1] > maxy) maxy = m->vertexArray[3 * i+1];
        if (m->vertexArray[3 * i+2] < minz) minz = m->vertexArray[3 * i+2];
        if (m->vertexArray[3 * i+2] > maxz) maxz = m->vertexArray[3 * i+2];
    }

    fprintf(stderr, "maxx %f minx %f \n", maxx, minx);
    fprintf(stderr, "maxy %f miny %f \n", maxy, miny);
    fprintf(stderr, "maxz %f minz %f \n", maxz, minz);

    for (i = 0; i < m->numVertices; i++)
    {
        m->vertexArray[3 * i] -= (maxx + minx)/2.0;
        m->vertexArray[3 * i+1] -= (maxy + miny)/2.0;
        m->vertexArray[3 * i+2] -= (maxz + minz)/2.0;
    }
}
Example #7
0
/*--------------------------------------------------------------------*/
int mbr_dem_hsurivax(int verbose, void *mbio_ptr, int *error) {
	char *function_name = "mbr_dem_hsurivax";
	int status = MB_SUCCESS;
	struct mb_io_struct *mb_io_ptr;

	/* print input debug statements */
	if (verbose >= 2) {
		fprintf(stderr, "\ndbg2  MBIO function <%s> called\n", function_name);
		fprintf(stderr, "dbg2  Revision id: %s\n", rcs_id);
		fprintf(stderr, "dbg2  Input arguments:\n");
		fprintf(stderr, "dbg2       verbose:    %d\n", verbose);
		fprintf(stderr, "dbg2       mbio_ptr:   %p\n", (void *)mbio_ptr);
	}

	/* get pointer to mbio descriptor */
	mb_io_ptr = (struct mb_io_struct *)mbio_ptr;

	/* deallocate memory for data descriptor */
	status = mb_freed(verbose, __FILE__, __LINE__, (void **)&mb_io_ptr->raw_data, error);
	status = mb_freed(verbose, __FILE__, __LINE__, (void **)&mb_io_ptr->store_data, error);

	/* print output debug statements */
	if (verbose >= 2) {
		fprintf(stderr, "\ndbg2  MBIO function <%s> completed\n", function_name);
		fprintf(stderr, "dbg2  Return values:\n");
		fprintf(stderr, "dbg2       error:      %d\n", *error);
		fprintf(stderr, "dbg2  Return status:\n");
		fprintf(stderr, "dbg2       status:  %d\n", status);
	}

	/* return status */
	return (status);
}
Example #8
0
//
// Z_FileDumpHeap
//
void Z_FileDumpHeap (FILE* f)
{
    memblock_t*	block;

    fprintf (f,"zone size: %i  location: %p\n",mainzone->size,mainzone);

    for (block = mainzone->blocklist.next ; ; block = block->next)
    {
	fprintf (f,"block:%p    size:%7i    user:%p    tag:%3i\n",
		 block, block->size, block->user, block->tag);

	if (block->next == &mainzone->blocklist)
	{
	    // all blocks have been hit
	    break;
	}

	if ( (byte *)block + block->size != (byte *)block->next)
	    fprintf (f,"ERROR: block size does not touch the next block\n");

	if ( block->next->prev != block)
	    fprintf (f,"ERROR: next block doesn't have proper back link\n");

	if (!block->user && !block->next->user)
	    fprintf (f,"ERROR: two consecutive free blocks\n");
    }
}
Example #9
0
int acceptClientOn(int socket) {

    socklen_t acceptlen = sizeof(struct sockaddr_in);
    struct sockaddr_in clientaddr;
    int connection;

    if ((connection = accept(socket, (struct sockaddr *)&clientaddr, &acceptlen)) < 0) {
      fprintf(stderr,"ACCEPT failed.\n");
      exit(-1);
    }

    //
    // Report the client that connected.
    //
    struct hostent *hostp;
    if ((hostp = gethostbyaddr((const char *)&clientaddr.sin_addr.s_addr, 
			       sizeof(struct in_addr), AF_INET)) == NULL) {
      fprintf(stderr, "GETHOSTBYADDR failed.");
    }
    
    printf("Accepted connection from client %s (%s)\n", 
	   hostp->h_name, inet_ntoa(clientaddr.sin_addr));
    
    return connection;
}
Example #10
0
int AddItem(const Item * pi, Tree * ptree)
{
	Node * new_node;

	if(TreeIsFull(ptree))
	{
		fprintf(stderr,"Tree is full.\n");
		return FALSE;
	}

	if(SeekItem(pi,ptree).child != NULL)
	{
		fprintf(stderr,"Attempt to add duplicate item.\n");
		return FALSE;
	}

	new_node = MakeNode(pi);
	if(new_node == NULL)
	{
		fprintf(stderr,"couldn't create node.\n");
		return FALSE;
	}

	ptree->size++;
	if(ptree->root == NULL)
		ptree->root = new_node;
	else
		AddNode(new_node,ptree->root);
	
	return TRUE; 
}
Example #11
0
static void write_state(void)
{
    FILE *fp;
    int k,ns,*state;
    float base,r[N];

    ns=rlxs_size();
    state=malloc(ns*sizeof(int));
    base=(float)(ldexp(1.0,24));
    rlxs_init(1,1234567);

    for (k=0; k<10; k++)
        ranlxs(r,N);

    rlxs_get(state);
    ranlxs(r,N);

    fp=fopen(".tmp","w");

    for (k=0; k<ns; k++)
        fprintf(fp,"%d\n",state[k]);

    for (k=0; k<N; k++)
        fprintf(fp,"%12.1f\n",base*r[k]);

    fclose(fp);
}
Example #12
0
static int pass_frame_to_decoder(AVCodecContext * avctx, AVFrame * picture,
		int inlen, unsigned char * in, int * outlen, char * out)
{
	int bytes_decoded;
	int got_picture;

	bytes_decoded = avcodec_decode_video(avctx, picture, &got_picture,
			in, inlen);

	if ( bytes_decoded != inlen )
	{
		fprintf(stderr,
			"codec_ffmpeg: decode: failed to decode whole frame %d / %d\n",
			bytes_decoded, inlen);
		return -1;
	}

	if ( !got_picture )
	{
		fprintf(stderr,
			"codec_ffmpeg: decode: failed to get picture\n");
		return -1;
	}

	frame_to_frame_xlate(avctx, picture, outlen, out);

	return 0;
}
Example #13
0
void gen3(int number) {
  sprintf(input, "%s%d.in", name, number);
  out = fopen(input, "w");
  
  if (number & 1) std::random_shuffle(p2, p2 + 20); 
  
  fprintf(out, "%d\n", 5);
  for (int tt = 0; tt <= 4; ++tt) {
    n = 100000 - tt * 5000 - rand(); 
    m = 100000 - tt * 5000 - rand();  
    C = 0;
    D = 0;
    if (number & 1) fprintf(out, "%d %d %d %d %d\n", n, m, C, D, p2[tt]);
    else fprintf(out, "%d %d %d %d %d\n", n, m, C, D, 500000000 + Rand() % M2);

    bo.clear();
    bo[mp(1, 1)] = bo[mp(n, m)] = true;
    for (int i = 1; i <= C; ++i) {
      int x, y;
      do {
        x = Rand() % n + 1;
        y = Rand() % m + 1;
      } while (bo[mp(x, y)]);
      bo[mp(x, y)] = true;
      fprintf(out, "%d %d\n", x, y);
    }
  }
}
Example #14
0
void gen2(int number) {
  sprintf(input, "%s%d.in", name, number);
  out = fopen(input, "w");
  
  if (number & 1) std::random_shuffle(p1, p1 + 20); 
  
  fprintf(out, "%d\n", 5);
  for (int tt = 1; tt <= 5; ++tt) {
    n = 40 + rand() % 11;
    m = 40 + rand() % 11; 
    C = 10 + rand() % 41;
    D = 2 + rand() % (C * 2 / 3);
    if (number & 1) fprintf(out, "%d %d %d %d %d\n", n, m, C, D, p1[tt]);
    else fprintf(out, "%d %d %d %d %d\n", n, m, C, D, 100000 + Rand() % M1 + 1);

    bo.clear();
    bo[mp(1, 1)] = bo[mp(n, m)] = true;
    for (int i = 1; i <= C; ++i) {
      int x, y;
      do {
        x = Rand() % n + 1;
        y = Rand() % m + 1;
      } while (bo[mp(x, y)]);
      bo[mp(x, y)] = true;
      fprintf(out, "%d %d\n", x, y);
    }
  }
}
Example #15
0
size_t qng2d(DoubleFunc2d func, double xlower, double xupper,
	     double ylower, double yupper,
	     double abseps,double releps, double *result, double *abserr)
{
  gsl_function F;
  
  int returnval;
  size_t neval;
  double params[4];
  
  /* set the 2d integrand globally */
  Func_QNG2D = func;

  /* init the function */
  F.function=F_Qng2d;
  params[0]=xlower;
  params[1]=xupper;
  params[2]=abseps;
  params[3]=releps;
  F.params=params;

  returnval=gsl_integration_qng (&F, ylower, yupper, abseps, releps, result, abserr, &neval);
  
#ifdef DEBUG_QNG2D
  fprintf(stderr,"qng2d: returnval =  %d\n", returnval);
  fprintf(stderr,"qng2d: intervals =  %d\n", neval);
  fprintf(stderr,"qng2d: result    =  % .18f\n", *result);
  fprintf(stderr,"qng2d: abserr    =  % .18f\n", *abserr);
#endif
  
  return returnval;
}
Example #16
0
static int h_counter(int argc, unsigned char **argv){
	struct counter_header ch1;
	if(conf.counterd >=0)close(conf.counterd);
	if(!conf.trafcountfunc) conf.trafcountfunc = trafcountfunc;
	conf.counterd = open((char *)argv[1], O_BINARY|O_RDWR|O_CREAT, 0660);
	if(conf.counterd<0){
		fprintf(stderr, "Unable to open counter file %s, line %d\n", argv[1], linenum);
		return 1;
	}
	if(read(conf.counterd, &ch1, sizeof(ch1))==sizeof(ch1)){
		if(memcmp(&ch1, &cheader, 4)){
			fprintf(stderr, "Not a counter file %s, line %d\n", argv[1], linenum);
			return 2;
		}
#ifdef  _MSC_VER
#ifdef _TIME64_T_DEFINED
#ifndef _MAX__TIME64_T
#define _MAX__TIME64_T     0x793406fffi64
#endif 
#endif
		if(ch1.updated >= _MAX__TIME64_T){
			fprintf(stderr, "Invalid or corrupted counter file %s. Use countersutil utility to convert from older version\n", argv[1]);
			return 3;
		}
#endif
		cheader.updated = ch1.updated;
	}
	if(argc >=4) {
		conf.countertype = getrotate(*argv[2]);
		if(conf.counterfile) myfree(conf.counterfile);
		conf.counterfile = mystrdup((char *)argv[3]);
	}
	return 0;
}
Example #17
0
/* 
 * params should give the parameters to integrate over X:
 * params[0]: xlower;
 * params[1]: xupper;
 * params[2]: abseps;
 * params[3]: releps;
 *
 */
double F_Qng2d(double y, void * params)
{
  double *array;
  double result,abserr;
  size_t neval;

  double valy;
  size_t returnval;
  gsl_function F;
  
  valy=y;
  array=(double *)params;
  F.function=F_Qng2d_FixY;
  F.params=&valy;

  gsl_integration_qng (&F, array[0], array[1], array[2], array[3], &result, &abserr, &neval);

#ifdef DEBUG_QNG2D
  fprintf(stderr,"F_Qng2d: returnval =  %d\n", returnval);
  fprintf(stderr,"F_Qng2d: intervals =  %d\n", neval);
  fprintf(stderr,"F_Qng2d: result    =  % .18f\n", result);
  fprintf(stderr,"F_Qng2d: abserr    =  % .18f\n", abserr);
#endif

  return result;
}
Example #18
0
/**
 * Pre-print macro expression to be expanded.
 * @param mb		macro expansion state
 * @param s		current expansion string
 * @param se		end of string
 */
static void
printMacro(MacroBuf mb, const char * s, const char * se)
{
    const char *senl;
    const char *ellipsis;
    int choplen;

    if (s >= se) {	/* XXX just in case */
	fprintf(stderr, _("%3d>%*s(empty)"), mb->depth,
		(2 * mb->depth + 1), "");
	return;
    }

    if (s[-1] == '{')
	s--;

    /* Print only to first end-of-line (or end-of-string). */
    for (senl = se; *senl && !iseol(*senl); senl++)
	{};

    /* Limit trailing non-trace output */
    choplen = 61 - (2 * mb->depth);
    if ((senl - s) > choplen) {
	senl = s + choplen;
	ellipsis = "...";
    } else
	ellipsis = "";

    /* Substitute caret at end-of-macro position */
    fprintf(stderr, "%3d>%*s%%%.*s^", mb->depth,
	(2 * mb->depth + 1), "", (int)(se - s), s);
    if (se[1] != '\0' && (senl - (se+1)) > 0)
	fprintf(stderr, "%-.*s%s", (int)(senl - (se+1)), se+1, ellipsis);
    fprintf(stderr, "\n");
}
Example #19
0
int main()
{
  char buf[BSZ];

  memset(buf, 'a', BSZ-2);
  buf[BSZ-2] = '\0';
  buf[BSZ-1] = 'X';
  FILE *fp = fmemopen(buf, BSZ, "w+");
  if (fp == NULL)
    err_exit("fmemopen failed");
  printf("initial buffer contents: %s\n", buf);
  fprintf(fp, "hello, world");
  printf("before flush: %s\n", buf);
  fflush(fp);
  printf("after fflush: %s\n", buf);
  printf("len of string in buf = %ld\n", (long)strlen(buf));

  memset(buf, 'b', BSZ-2);
  buf[BSZ-2] = '\0';
  buf[BSZ-1] = 'X';
  fprintf(fp, "hello, world");
  fseek(fp, 0, SEEK_SET);
  printf("after  fseek: %s\n", buf);
  printf("len of string in buf = %ld\n", (long)strlen(buf));

  memset(buf, 'c', BSZ-2);
  buf[BSZ-2] = '\0';
  buf[BSZ-1] = 'X';
  fprintf(fp, "hello, world");
  fclose(fp);
  printf("after fclose: %s\n", buf);
  printf("len of string in buf = %ld\n", (long)strlen(buf));

  return(0);
}
Example #20
0
int
main(void)
{
	odbc_use_version3 = 1;

	odbc_mark_sockets_opened();
	odbc_connect();

	CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, (void *) SQL_AUTOCOMMIT_OFF, 0, "S");

	odbc_command("SELECT 1");
	CHKMoreResults("No");

	if (!close_last_socket()) {
		fprintf(stderr, "Error closing connection\n");
		return 1;
	}
	CHKEndTran(SQL_HANDLE_DBC, odbc_conn, SQL_ROLLBACK, "E");

	/* the error should be written in the connection, not in the statement */
	ReadErrorConn();
	if (strcmp(odbc_sqlstate, "08S01") != 0 || strstr(odbc_err, "Write to the server") == NULL) {
		odbc_disconnect();
		fprintf(stderr, "Unexpected error message %s %s\n", odbc_sqlstate, odbc_err);
		return 1;
	}

	odbc_disconnect();
	return 0;
}
Example #21
0
//-----------------------------------------------------------------------------
bool AdScreen::Init(void) {
    s_pScreen = SDL_CreateRGBSurface(
                    0, s_iWinWidth, s_iWinHeight,
                    32, 0x00, 0x00, 0x00, 0x00
                );

    if(s_pScreen == NULL) {
        fprintf(stderr, SDL_GetError());
        return false;
    }

    s_pTexture = SDL_CreateTexture(
                     GetRenderer(),
                     SDL_PIXELFORMAT_RGBA8888,
                     SDL_TEXTUREACCESS_STREAMING,
                     s_pScreen->w,
                     s_pScreen->h
                 );

    if(s_pTexture == NULL) {
        fprintf(stderr, SDL_GetError());
        return false;
    }

    return true;
}
Example #22
0
/**
 * @brief normalize a float array
 *
 * This function operates in-place. It computes the minimum and
 * maximum values of the data, and rescales the data to
 * [0-1], with optionally flattening some extremal pixels.
 *
 * @param data input/output array
 * @param size array size
 * @param nb_min, nb_max number extremal pixels flattened
 *
 * @return data
 */
float *balance_f32(float *data, size_t size, size_t nb_min, size_t nb_max)
{
    float min, max;

    /* sanity checks */
    if (NULL == data) {
        fprintf(stderr, "a pointer is NULL and should not be so\n");
        abort();
    }
    if (nb_min + nb_max >= size) {
        nb_min = (size - 1) / 2;
        nb_max = (size - 1) / 2;
        fprintf(stderr, "the number of pixels to flatten is too large\n");
        fprintf(stderr, "using (size - 1) / 2\n");
    }

    /* get the min/max */
    if (0 != nb_min || 0 != nb_max)
        quantiles_f32(data, size, nb_min, nb_max, &min, &max);
    else
        minmax_f32(data, size, &min, &max);

    /* rescale */
    (void) rescale_f32(data, size, min, max);

    return data;
}
Example #23
0
void check_page(unsigned char *data,const int *header,ogg_page *og){
  long j;
  /* Test data */
  for(j=0;j<og->body_len;j++)
    if(og->body[j]!=data[j]){
      fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
	      j,data[j],og->body[j]);
      exit(1);
    }

  /* Test header */
  for(j=0;j<og->header_len;j++){
    if(og->header[j]!=header[j]){
      fprintf(stderr,"header content mismatch at pos %ld:\n",j);
      for(j=0;j<header[26]+27;j++)
	fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
      fprintf(stderr,"\n");
      exit(1);
    }
  }
  if(og->header_len!=header[26]+27){
    fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
	    og->header_len,header[26]+27);
    exit(1);
  }
}
Example #24
0
int
get_next_index( simple_reader * sri, const int last_index )
{
    int index, check;
    char *iline = NULL;

    while( sr_readline( sri ) ) {
        iline = sr_line( sri );
        if( sr_line_isempty( sri ) )
            continue;
        if( '#' == iline[0] )
            continue;
        break;
    }

    if( sr_eof( sri ) || NULL == iline )
        return -1;

    check = sscanf( iline, "%d", &index );
    if( check != 1 ) {
        fprintf( stderr, "ERROR: could not read index on line %d of %s\n",
                 sr_linenum( sri ), sr_filename( sri ) );
        exit( EXIT_FAILURE );
    }

    if( index <= 0 || index <= last_index ) {
        fprintf( stderr, "ERROR: bad index on line %d of %s\n",
                 sr_linenum( sri ), sr_filename( sri ) );
        fprintf( stderr, "  -> INDEX must be positive non-zero and monotonically increasing\n" );
        exit( EXIT_FAILURE );
    }

    return index;
}
Example #25
0
int vrpn_BaseClassUnique::register_autodeleted_handler(vrpn_int32 type,
		vrpn_MESSAGEHANDLER handler, void *userdata,
		vrpn_int32 sender)
{
    // Make sure we have a Connection
    if (d_connection == NULL) {
        fprintf(stderr,"vrpn_BaseClassUnique::register_autodeleted_handler: "
                "No vrpn_Connection.\n");
        return -1;
    }

    // Make sure we have an empy entry to fill in.
    if (d_num_autodeletions >= vrpn_MAX_BCADRS) {
        fprintf(stderr,"vrpn_BaseClassUnique::register_autodeleted_handler: "
                "Too many handlers registered.  Increase vrpn_MAX_BCADRS "
                "and recompile VRPN.  Please report to vrpn@cs.unc.edu.\n");
        return -1;
    }

    // Fill in the values so we know what to delete, and bump the count
    d_handler_autodeletion_record[d_num_autodeletions].handler = handler;
    d_handler_autodeletion_record[d_num_autodeletions].sender = sender;
    d_handler_autodeletion_record[d_num_autodeletions].type = type;
    d_handler_autodeletion_record[d_num_autodeletions].userdata = userdata;
    d_num_autodeletions++;

    // Call the register command.
    return d_connection->register_handler(type, handler, userdata, sender);
}
Example #26
0
File: post.c Project: gerow/hnfs
static size_t
curl_saver(void *buffer, size_t size, size_t nmemb, void *userp)
{
  size_t bytes = size * nmemb;
  curl_saver_t *saver = userp;

  fprintf(stderr, "curl_saver called\n");
  fprintf(stderr, "input size: %zu\n", size);
  fprintf(stderr, "input nmemb: %zu\n", nmemb);
  fprintf(stderr, "saver size: %zu\n", saver->size);

  size_t new_size = saver->size + bytes;


  /* alloc one more for the null character */
  saver->data = realloc(saver->data, new_size + 1);
  if (saver->data == NULL) {
    perror("failed to realloc in curl_saver");
    exit(EXIT_FAILURE);
  }

  memcpy(saver->data + saver->size, buffer, bytes);
  saver->size += bytes;

  /* make sure we're null terminated */
  saver->data[saver->size] = '\0';

  return bytes;
}
Example #27
0
void
typecheck_visit_for_stmt (struct _Visitor *visitor, struct AstNode *node)
{
    struct AstNode *asgn = node->children;
    struct AstNode *expr = asgn->sibling;
    struct AstNode *stmt = expr->sibling;
    struct AstNode *id_node = asgn->children;

    ast_node_accept(asgn, visitor);
    ast_node_accept(expr, visitor);

    if (id_node->type != INTEGER) {
        node->type = ERROR;
        fprintf(stderr,
                "Error: Identifier '%s' is of %s type; it must be Integer. "
                "Check line %d.\n", id_node->symbol->name,
                type_get_lexeme(id_node->type), id_node->linenum);
    }

    if (expr->type != INTEGER) {
        node->type = ERROR;
        fprintf(stderr,
                "Error: Value of stop condition is not of Integer type. "
                "Check line %d.\n", expr->linenum);
    }

    ast_node_accept(stmt, visitor);

}
Example #28
0
File: post.c Project: gerow/hnfs
/*
 * the calling thread should have a lock on the collection before
 * calling this function
 */
int hnfs_post_fetch_content(hnfs_post_t *post)
{
  if ((time(NULL) - post->content_update_time) < HNFS_TIME_BETWEEN_UPDATES) {
    fprintf(stderr, "Content fresh. Skipping update.\n");
    return 0;
  }

  /* if content is allocated free it */
  if (post->content) {
    free(post->content);
  }

  curl_saver_t saver = {
    .data = NULL,
    .size = 0
  };
  CURLcode res = fetch_url(post->url, &saver);
  if (res != CURLE_OK) {
    fprintf(stderr,
            "Failed to fetch url %s: %s\n",
            post->url,
            curl_easy_strerror(res));
    return res;
  }
  post->content = saver.data;
  post->content_update_time = time(NULL);

  return 0;
}
Example #29
0
static void vhost_virtqueue_cleanup(struct vhost_dev *dev,
                                    struct VirtIODevice *vdev,
                                    struct vhost_virtqueue *vq,
                                    unsigned idx)
{
    struct vhost_vring_state state = {
        .index = idx,
    };
    int r;
    r = vdev->binding->set_host_notifier(vdev->binding_opaque, idx, false);
    if (r < 0) {
        fprintf(stderr, "vhost VQ %d host cleanup failed: %d\n", idx, r);
        fflush(stderr);
    }
    assert (r >= 0);
    r = ioctl(dev->control, VHOST_GET_VRING_BASE, &state);
    if (r < 0) {
        fprintf(stderr, "vhost VQ %d ring restore failed: %d\n", idx, r);
        fflush(stderr);
    }
    virtio_queue_set_last_avail_idx(vdev, idx, state.num);
    assert (r >= 0);
    cpu_physical_memory_unmap(vq->ring, virtio_queue_get_ring_size(vdev, idx),
                              0, virtio_queue_get_ring_size(vdev, idx));
    cpu_physical_memory_unmap(vq->used, virtio_queue_get_used_size(vdev, idx),
                              1, virtio_queue_get_used_size(vdev, idx));
    cpu_physical_memory_unmap(vq->avail, virtio_queue_get_avail_size(vdev, idx),
                              0, virtio_queue_get_avail_size(vdev, idx));
    cpu_physical_memory_unmap(vq->desc, virtio_queue_get_desc_size(vdev, idx),
                              0, virtio_queue_get_desc_size(vdev, idx));
}
Example #30
0
static void setup()
{
    client = ccnet_client_new ();
    if ( ccnet_client_load_confdir(client, CCNET_DIR) < 0 ) {
        fprintf (stderr, "Read config dir error\n");
        exit(1);
    }

    event_init ();

    if (g_access (TEST_DIR "worktree", F_OK) != 0 &&
        g_mkdir (TEST_DIR "worktree", 0777) < 0) {
        fprintf (stderr, "Failed to create worktree.\n");
        exit (1);
    }

    seaf = seafile_session_new (SEAF_DIR, 
                                WORKTREE_DIR,
                                client);
    if (!seaf) {
        fprintf (stderr, "Failed to create seafile session.\n");
        exit (1);
    }
    seafile_session_prepare (seaf);
}