Exemplo n.º 1
0
// Attempt to parse the specified source file and add it to the given AST
// @return true on success, false on error
static bool parse_source_file(ast_t* package, const char* file_path,
  pass_opt_t* options)
{
  assert(package != NULL);
  assert(file_path != NULL);
  source_t* source = source_open(file_path);

  if(source == NULL)
  {
    errorf(file_path, "couldn't open file %s", file_path);
    return false;
  }

  return module_passes(package, options, source);
}
Exemplo n.º 2
0
int thread_read_openstream(struct  thread_read *thread)
{
    thread->source = new_source(thread->url, thread->headers, thread->flags);
    if (thread->source != NULL) {
        int ret;
        ret = source_open(thread->source);
        if (ret != 0) {
            LOGI("source opened failed\n");
            release_source(thread->source);
            thread_read_wakewait(thread);
            thread->source = NULL;
            thread->error = ret;
            return ret;
        }
        source_getoptions(thread->source, &thread->options);
        thread_read_wakewait(thread);
        thread->opened = 1;
    }
    return 0;
}
Exemplo n.º 3
0
Arquivo: usb.c Projeto: helaibai/usbip
static void *simple_source_thread (void *param)
{
	char		*name = (char *) param;
	int		status;
	char		buf [USB_BUFSIZE];

	status = source_open (name);
	if (status < 0)
		return 0;
	source_fd = status;

	pthread_cleanup_push (close_fd, &source_fd);
	do {
		unsigned long	len;

		/* original LinuxThreads cancelation didn't work right
		 * so test for it explicitly.
		 */
		pthread_testcancel ();

		len = fill_in_buf (buf, sizeof buf);
		if (len > 0)
			status = write (source_fd, buf, len);
		else
			status = 0;

	} while (status > 0);
	if (status == 0) {
		if (verbose)
			fprintf (stderr, "done %s\n", __FUNCTION__);
	} else if (verbose > 2 || errno != ESHUTDOWN) /* normal disconnect */
		perror ("write");
	fflush (stdout);
	fflush (stderr);
	pthread_cleanup_pop (1);

	return 0;
}
Exemplo n.º 4
0
int
main(int argc, const char *argv[])
{
    int result = 0;
    apr_pool_t *mp;
    apr_status_t status;
    char next_char;
    Source *source = NULL;

    apr_initialize();

    status = apr_pool_create(&mp, NULL);
    handle_and_display_error(status);

    source_init(&source, mp);

    status = source_set_options(source, argc, argv, mp);
    handle_and_display_error(status);

    status = source_open(source, mp);
    handle_and_display_error(status);

    while (source_shift_character(source, &next_char) == APR_SUCCESS) {
        printf("%c", next_char);
    }

    goto cleanup;

error:
    result = 1;

cleanup:
    if (source) { source_cleanup(source); }
    apr_pool_destroy(mp);
    apr_terminate();

    return result;
}
Exemplo n.º 5
0
// Attempt to parse the specified source file and add it to the given AST
// @return true on success, false on error
static bool parse_source_file(ast_t* package, const char* file_path,
  pass_opt_t* opt)
{
  pony_assert(package != NULL);
  pony_assert(file_path != NULL);
  pony_assert(opt != NULL);

  if(opt->print_filenames)
    printf("Opening %s\n", file_path);

  const char* error_msg = NULL;
  source_t* source = source_open(file_path, &error_msg);

  if(source == NULL)
  {
    if(error_msg == NULL)
      error_msg = "couldn't open file";

    errorf(opt->check.errors, file_path, "%s %s", error_msg, file_path);
    return false;
  }

  return module_passes(package, opt, source);
}
Exemplo n.º 6
0
Arquivo: usb.c Projeto: helaibai/usbip
static void *aio_in_thread (void *param)
{
	char		*name = (char *) param;
	int		status;
	io_context_t	ctx = 0;
	struct iocb	*queue, *iocb;
	unsigned	i;

	status = source_open (name);
	if (status < 0)
		return 0;
	source_fd = status;
	pthread_cleanup_push (close_fd, &source_fd);

	/* initialize i/o queue */
	status = io_setup (aio_in, &ctx);
	if (status < 0) {
		perror ("aio_in_thread, io_setup");
		return 0;
	}
	pthread_cleanup_push (queue_release, &ctx);

	if (aio_in == 0)
		aio_in = 1;
	queue = alloca (aio_in * sizeof *iocb);

	/* populate and (re)run the queue */
	for (i = 0, iocb = queue; i < aio_in; i++, iocb++) {
		char *buf = malloc (iosize);

		if (!buf) {
			fprintf(stderr, "%s can't get buffer[%d]\n",
				__FUNCTION__, i);
			return 0;
		}

		/* host receives the data we're writing */
		io_prep_pwrite (iocb, source_fd,
			buf, fill_in_buf (buf, iosize),
			0);
		io_set_callback (iocb, in_complete);
		iocb->key = USB_DIR_IN;

		status = io_submit (ctx, 1, &iocb);
		if (status < 0) {
			perror (__FUNCTION__);
			break;
		}
		aio_in_pending++;
		if (verbose > 2)
			fprintf(stderr, "%s submit uiocb %p\n",
				__FUNCTION__, iocb);
	}

	status = io_run (ctx, &aio_in_pending);
	if (status < 0)
		perror ("aio_in_thread, io_run");

	/* clean up */
	fflush (stderr);
	pthread_cleanup_pop (1);
	pthread_cleanup_pop (1);

	return 0;
}
Exemplo n.º 7
0
/* ccid thread, forwards ccid requests to pcsc and returns results  */
static void *ccid (void *param)
{
    char	**names      = (char **) param;
    char	*source_name = names[0];
    char	*sink_name   = names[1];
    int		result;
    size_t      bufsize = sizeof(PC_to_RDR_XfrBlock_t) + CCID_EXT_APDU_MAX;
    __u8        inbuf[bufsize];

    source_fd = source_open (source_name);
    if (source_fd < 0) {
        if (verbose > 1)
            perror("source_fd");
        goto error;
    }
    pthread_cleanup_push (close_fd, &source_fd);

    sink_fd   = sink_open (sink_name);
    if (sink_fd   < 0) {
        if (verbose > 1)
            perror("sink_fd");
        goto error;
    }
    pthread_cleanup_push (close_fd, &sink_fd);

    pthread_cleanup_push (close_ccid, NULL);

    __u8 *outbuf = NULL;
    pthread_cleanup_push (free, outbuf);

    do {

        /* original LinuxThreads cancelation didn't work right
         * so test for it explicitly.
         */
        pthread_testcancel ();

        if (verbose > 1)
            fprintf(stderr, "bulk loop: reading %lu bytes... ", (long unsigned) bufsize);
        result = read(sink_fd, inbuf, bufsize);
        if (result < 0) break;
        if (verbose > 1)
            fprintf(stderr, "bulk loop: got %d, done.\n", result);
        if (!result) break;

        result = ccid_parse_bulkout(inbuf, result, &outbuf);
        if (result < 0) break;

        if (verbose > 1)
            fprintf(stderr, "bulk loop: writing %d bytes... ", result);
        result = write(source_fd, outbuf, result);
        if (verbose > 1)
            fprintf(stderr, "done (%d written).\n", result);
    } while (result >= 0);

    if (errno != ESHUTDOWN || result < 0) {
        perror ("ccid loop aborted");
        pthread_cancel(ep0);
    }

    pthread_cleanup_pop (1);
    pthread_cleanup_pop (1);
    pthread_cleanup_pop (1);
    pthread_cleanup_pop (1);

    fflush (stdout);
    fflush (stderr);

    return 0;

error:
    pthread_cancel(ep0);
    pthread_exit(0);
}
Exemplo n.º 8
0
media_source_t* client_open_source(sipua_t* sipua, char* name, char* mode, void* param)
{
	ogmp_client_t *client = (ogmp_client_t*)sipua;
	
	return source_open(name, client->control, mode, param);
}