コード例 #1
0
ファイル: testfile.c プロジェクト: cmjonze/apr
static void test_file_trunc(abts_case *tc, void *data)
{
    apr_status_t rv;
    apr_file_t *f;
    const char *fname = "data/testtruncate.dat";
    const char *s;
    apr_size_t nbytes;
    apr_finfo_t finfo;

    apr_file_remove(fname, p);

    /* Test unbuffered */
    rv = apr_file_open(&f, fname,
                        APR_FOPEN_CREATE | APR_FOPEN_READ |
                        APR_FOPEN_WRITE,
                        APR_FPROT_UREAD | APR_FPROT_UWRITE, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    s = "some data";
    nbytes = strlen(s);
    rv = apr_file_write(f, s, &nbytes);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
    rv = apr_file_trunc(f, 4);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    rv = apr_file_close(f);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_ASSERT(tc, "File size mismatch, expected 4", finfo.size == 4);

    rv = apr_file_remove(fname, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    /* Test buffered */
    rv = apr_file_open(&f, fname,
                        APR_FOPEN_CREATE | APR_FOPEN_READ |
                        APR_FOPEN_WRITE | APR_FOPEN_BUFFERED,
                        APR_FPROT_UREAD | APR_FPROT_UWRITE, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    nbytes = strlen(s);
    rv = apr_file_write(f, s, &nbytes);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
    rv = apr_file_trunc(f, 4);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    rv = apr_file_close(f);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_ASSERT(tc, "File size mismatch, expected 4", finfo.size == 4);

    rv = apr_file_remove(fname, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
}
コード例 #2
0
ファイル: readwrite.c プロジェクト: hjwsm1989/apache2
APR_DECLARE(apr_status_t) apr_file_puts(const char *str, apr_file_t *thefile)
{
    apr_size_t len;

    len = strlen(str);
    return apr_file_write(thefile, str, &len); 
}
コード例 #3
0
ファイル: testpipe.c プロジェクト: AbrahamJewowich/FreeSWITCH
static void read_write_notimeout(abts_case *tc, void *data)
{
    apr_status_t rv;
    char *buf = "this is a test";
    char *input;
    apr_size_t nbytes;
    
    nbytes = strlen("this is a test");

    rv = apr_file_pipe_create(&readp, &writep, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_PTR_NOTNULL(tc, readp);
    ABTS_PTR_NOTNULL(tc, writep);

    rv = apr_file_write(writep, buf, &nbytes);
    ABTS_INT_EQUAL(tc, strlen("this is a test"), nbytes);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    nbytes = 256;
    input = apr_pcalloc(p, nbytes + 1);
    rv = apr_file_read(readp, input, &nbytes);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_INT_EQUAL(tc, strlen("this is a test"), nbytes);
    ABTS_STR_EQUAL(tc, "this is a test", input);
}
コード例 #4
0
ファイル: lock.c プロジェクト: jmckenna/mapcache
mapcache_lock_result mapcache_locker_disk_aquire_lock(mapcache_context *ctx, mapcache_locker *self, char *resource, void **lock) {
  char *lockname, errmsg[120];
  mapcache_locker_disk *ldisk;
  apr_file_t *lockfile;
  apr_status_t rv;
  
  assert(self->type == MAPCACHE_LOCKER_DISK);
  ldisk = (mapcache_locker_disk*)self;
  *lock = NULL; /*unused*/

  lockname = lock_filename_for_resource(ctx,ldisk,resource);
  /* create the lockfile */
  rv = apr_file_open(&lockfile,lockname,APR_WRITE|APR_CREATE|APR_EXCL|APR_XTHREAD,APR_OS_DEFAULT,ctx->pool);

  /* if the file already exists, wait for it to disappear */
  /* TODO: check the lock isn't stale (i.e. too old) */
  if( rv != APR_SUCCESS ) {
    if( !APR_STATUS_IS_EEXIST(rv) ) {
      ctx->set_error(ctx, 500, "failed to create lockfile %s: %s", lockname, apr_strerror(rv,errmsg,120));
      return MAPCACHE_LOCK_NOENT;
    }
    return MAPCACHE_LOCK_LOCKED;
  } else {
    /* we acquired the lock */
    char *pid_s;
    pid_t pid;
    apr_size_t pid_s_len;
    pid = getpid();
    pid_s = apr_psprintf(ctx->pool,"%"APR_PID_T_FMT,pid);
    pid_s_len = strlen(pid_s);
    apr_file_write(lockfile,pid_s,&pid_s_len);
    apr_file_close(lockfile);
    return MAPCACHE_LOCK_AQUIRED;
  }
}
コード例 #5
0
ファイル: testfile.c プロジェクト: aptana/Jaxer
static void test_fail_write_flush(abts_case *tc, void *data)
{
    apr_file_t *f;
    const char *fname = "data/testflush.dat";
    apr_status_t rv;
    char buf[APR_BUFFERSIZE];
    int n;

    apr_file_remove(fname, p);

    APR_ASSERT_SUCCESS(tc, "open test file",
                       apr_file_open(&f, fname,
                                     APR_CREATE|APR_READ|APR_BUFFERED,
                                     APR_UREAD|APR_UWRITE, p));

    memset(buf, 'A', sizeof buf);

    /* Try three writes.  One of these should fail when it exceeds the
     * internal buffer and actually tries to write to the file, which
     * was opened read-only and hence should be unwritable. */
    for (n = 0, rv = APR_SUCCESS; n < 4 && rv == APR_SUCCESS; n++) {
        apr_size_t bytes = sizeof buf;
        rv = apr_file_write(f, buf, &bytes);
    }

    ABTS_ASSERT(tc, "failed to write to read-only buffered fd",
                rv != APR_SUCCESS);

    apr_file_close(f);
}
コード例 #6
0
/* write a color bar with (roughly) logarithmic scale as BMP image to FILE.
 */
static void
write_scale(apr_file_t *file)
{
  int x;
  word value = 0, inc = 1;

  /* write header to file */
  write_bitmap_header(file, 64, 1);

  for (x = 0; x < 64; ++x)
    {
      apr_size_t written;
      byte color[3] = { 128, 128, 128 };

      select_color(color, value);
      if (value + (int)inc < 0x10000)
        {
          value += inc;
          if (value >= 8 * inc)
            inc *= 2;
        }

      written = sizeof(color);
      apr_file_write(file, color, &written);
    }
}
コード例 #7
0
/* output css file */
static void
sass_output_file(request_rec *r, char *filename, char *data)
{
    apr_status_t rc;
    apr_size_t bytes;
    apr_file_t *file = NULL;

    if (!data) {
        return;
    }

    rc = apr_file_open(&file, filename,
                       APR_FOPEN_WRITE | APR_FOPEN_CREATE | APR_FOPEN_TRUNCATE,
                       APR_FPROT_OS_DEFAULT, r->pool);
    if (rc == APR_SUCCESS) {
        bytes = strlen(data);
        rc = apr_file_write(file, data, &bytes);
        if (rc != APR_SUCCESS) {
            _RERR(r, "Can't create/write to file: %s", filename);
        }
        apr_file_close(file);
    } else {
        _RERR(r, "Can't create/write to file: %s", filename);
    }
}
コード例 #8
0
ファイル: testfileinfo.c プロジェクト: AAthresh/quantlib
static void test_buffered_write_size(abts_case *tc, void *data)
{
    const apr_size_t data_len = strlen(NEWFILEDATA);
    apr_file_t *thefile;
    apr_finfo_t finfo;
    apr_status_t rv;
    apr_size_t bytes;

    rv = apr_file_open(&thefile, NEWFILENAME,
                       APR_READ | APR_WRITE | APR_CREATE | APR_TRUNCATE
                       | APR_BUFFERED | APR_DELONCLOSE,
                       APR_OS_DEFAULT, p);
    APR_ASSERT_SUCCESS(tc, "open file", rv);

    /* A funny thing happened to me the other day: I wrote something
     * into a buffered file, then asked for its size using
     * apr_file_info_get; and guess what? The size was 0! That's not a
     * nice way to behave.
     */
    bytes = data_len;
    rv = apr_file_write(thefile, NEWFILEDATA, &bytes);
    APR_ASSERT_SUCCESS(tc, "write file contents", rv);
    ABTS_TRUE(tc, data_len == bytes);

    rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, thefile);
    APR_ASSERT_SUCCESS(tc, "get file size", rv);
    ABTS_TRUE(tc, bytes == (apr_size_t) finfo.size);
    apr_file_close(thefile);
}
コード例 #9
0
ファイル: testpipe.c プロジェクト: kheradmand/Break
static void read_write_notimeout(CuTest *tc)
{
    apr_status_t rv;
    char *buf = "this is a test";
    char *input;
    apr_size_t nbytes;
    
    nbytes = strlen("this is a test");

    rv = apr_file_pipe_create(&readp, &writep, p);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);
    CuAssertPtrNotNull(tc, readp);
    CuAssertPtrNotNull(tc, writep);

    rv = apr_file_write(writep, buf, &nbytes);
    CuAssertIntEquals(tc, strlen("this is a test"), nbytes);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);

    nbytes = 256;
    input = apr_pcalloc(p, nbytes + 1);
    rv = apr_file_read(readp, input, &nbytes);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);
    CuAssertIntEquals(tc, strlen("this is a test"), nbytes);
    CuAssertStrEquals(tc, "this is a test", input);
}
コード例 #10
0
APR_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile, const struct iovec *vec,
                                          apr_size_t nvec, apr_size_t *nbytes)
{
#ifdef HAVE_WRITEV
    int bytes;

    if ((bytes = writev(thefile->filedes, vec, nvec)) < 0) {
        *nbytes = 0;
        return errno;
    }
    else {
        *nbytes = bytes;
        return APR_SUCCESS;
    }
#else
    /**
     * The problem with trying to output the entire iovec is that we cannot
     * maintain the behavoir that a real writev would have.  If we iterate
     * over the iovec one at a time, we loose the atomic properties of 
     * writev().  The other option is to combine the entire iovec into one
     * buffer that we could then send in one call to write().  This is not 
     * reasonable since we do not know how much data an iovec could contain.
     *
     * The only reasonable option, that maintains the semantics of a real 
     * writev(), is to only write the first iovec.  Callers of file_writev()
     * must deal with partial writes as they normally would. If you want to 
     * ensure an entire iovec is written, use apr_file_writev_full().
     */

    *nbytes = vec[0].iov_len;
    return apr_file_write(thefile, vec[0].iov_base, nbytes);
#endif
}
コード例 #11
0
ファイル: testfile.c プロジェクト: kheradmand/Break
static void test_writev_buffered(CuTest *tc)
{
    apr_status_t rv;
    apr_file_t *f;
    apr_size_t nbytes;
    struct iovec vec[2];
    const char *fname = "data/testwritev_buffered.dat";

    rv = apr_file_open(&f, fname,
                       APR_WRITE | APR_CREATE | APR_TRUNCATE |
                       APR_BUFFERED, APR_OS_DEFAULT, p);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);

    nbytes = strlen(TESTSTR);
    rv = apr_file_write(f, TESTSTR, &nbytes);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);

    vec[0].iov_base = LINE1;
    vec[0].iov_len = strlen(LINE1);
    vec[1].iov_base = LINE2;
    vec[1].iov_len = strlen(LINE2);

    rv = apr_file_writev(f, vec, 2, &nbytes);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);

    rv = apr_file_close(f);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);

    file_contents_equal(tc, fname, TESTSTR LINE1 LINE2,
                        strlen(TESTSTR) + strlen(LINE1) + strlen(LINE2));
}
コード例 #12
0
static apr_status_t pass_data_to_filter(ap_filter_t *f, const char *data,
                                        apr_size_t len, apr_bucket_brigade *bb)
{
    ef_ctx_t *ctx = f->ctx;
    ef_dir_t *dc = ctx->dc;
    apr_status_t rv;
    apr_size_t bytes_written = 0;
    apr_size_t tmplen;

    do {
        tmplen = len - bytes_written;
        rv = apr_file_write(ctx->proc->in,
                       (const char *)data + bytes_written,
                       &tmplen);
        bytes_written += tmplen;
        if (rv != APR_SUCCESS && !APR_STATUS_IS_EAGAIN(rv)) {
            ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, f->r,
                          "apr_file_write(child input), len %" APR_SIZE_T_FMT,
                          tmplen);
            return rv;
        }
        if (APR_STATUS_IS_EAGAIN(rv)) {
            /* XXX handle blocking conditions here...  if we block, we need
             * to read data from the child process and pass it down to the
             * next filter!
             */
            rv = drain_available_output(f, bb);
            if (APR_STATUS_IS_EAGAIN(rv)) {
#if APR_FILES_AS_SOCKETS
                int num_events;
                const apr_pollfd_t *pdesc;

                rv = apr_pollset_poll(ctx->pollset, f->r->server->timeout,
                                      &num_events, &pdesc);
                if (rv || dc->debug >= DBGLVL_GORY) {
                    ap_log_rerror(APLOG_MARK, APLOG_DEBUG,
                                  rv, f->r, "apr_pollset_poll()");
                }
                if (rv != APR_SUCCESS && !APR_STATUS_IS_EINTR(rv)) {
                    /* some error such as APR_TIMEUP */
                    return rv;
                }
#else /* APR_FILES_AS_SOCKETS */
                /* Yuck... I'd really like to wait until I can read
                 * or write, but instead I have to sleep and try again
                 */
                apr_sleep(100000); /* 100 milliseconds */
                if (dc->debug >= DBGLVL_GORY) {
                    ap_log_rerror(APLOG_MARK, APLOG_DEBUG,
                                  0, f->r, "apr_sleep()");
                }
#endif /* APR_FILES_AS_SOCKETS */
            }
            else if (rv != APR_SUCCESS) {
                return rv;
            }
        }
    } while (bytes_written < len);
    return rv;
}
コード例 #13
0
ファイル: mod_moon.c プロジェクト: valderrama/ModSSOBand
// this callback fucntion is used to write all the data from a CURL request to a file
static int write_data(void *ptr, size_t size, size_t nmemb, void *stream) {
	int len = size * nmemb;
	int written = 	apr_file_write((apr_file_t*)stream, ptr, &len);
	apr_off_t offset = 0;
	apr_file_seek((apr_file_t*)stream, APR_SET, &offset);
	return size * nmemb;
}
コード例 #14
0
static void flush_log(buffered_log *buf)
{
    if (buf->outcnt && buf->handle != NULL) {
        apr_file_write(buf->handle, buf->outbuf, &buf->outcnt);
        buf->outcnt = 0;
    }
}
コード例 #15
0
ファイル: testrand.c プロジェクト: 0jpq0/kbengine
static int rand_check_kat(rnd_fn *f, apr_random_t *r,
                          const unsigned char expected[RANDOM_BUF_SZ],
                          apr_file_t *readp, apr_file_t *writep)
{
    apr_size_t nbytes = RANDOM_BUF_SZ;
    apr_size_t cmd_size = 1;
    unsigned char c[RANDOM_BUF_SZ];
    char ack;
    apr_status_t rv;

    rv = f(r, c, RANDOM_BUF_SZ);
    if (rv)
        return 2;
    rv = 0;
    if (memcmp(c, expected, RANDOM_BUF_SZ)) {
        rv = 1;
    } else {
        hexdump("Generated: ", c, RANDOM_BUF_SZ);
        hexdump("Previous:  ", expected, RANDOM_BUF_SZ);
    }
    /* Report back our random values for comparison in another child */
    apr_file_write(writep, c, &nbytes);
    /* Wait for our parent ack the data */
    apr_file_read(readp, &ack, &cmd_size);
    return rv;
}
コード例 #16
0
ファイル: testfile.c プロジェクト: aptana/Jaxer
static void test_writev_buffered(abts_case *tc, void *data)
{
    apr_file_t *f;
    apr_size_t nbytes;
    struct iovec vec[2];
    const char *fname = "data/testwritev_buffered.dat";

    APR_ASSERT_SUCCESS(tc, "open file for writing",
                       apr_file_open(&f, fname,
                                     APR_WRITE | APR_CREATE | APR_TRUNCATE |
                                     APR_BUFFERED, APR_OS_DEFAULT, p));

    nbytes = strlen(TESTSTR);
    APR_ASSERT_SUCCESS(tc, "buffered write",
                       apr_file_write(f, TESTSTR, &nbytes));

    vec[0].iov_base = LINE1;
    vec[0].iov_len = strlen(LINE1);
    vec[1].iov_base = LINE2;
    vec[1].iov_len = strlen(LINE2);

    APR_ASSERT_SUCCESS(tc, "writev of size 2 to file",
                       apr_file_writev(f, vec, 2, &nbytes));

    APR_ASSERT_SUCCESS(tc, "close for writing",
                       apr_file_close(f));

    file_contents_equal(tc, fname, TESTSTR LINE1 LINE2,
                        strlen(TESTSTR) + strlen(LINE1) + strlen(LINE2));
}
コード例 #17
0
/* Write the cluster read map for all files in INFO as BMP image to FILE.
 * If MAX_X is not 0, scale all lines to MAX_X pixels.  Use POOL for
 * allocations.
 */
static void
write_bitmap(apr_array_header_t *info,
             int max_x,
             apr_file_t *file,
             apr_pool_t *pool)
{
  int ysize = info->nelts;
  int xsize = 0;
  int x, y;
  apr_size_t row_size;
  apr_size_t written;
  color_t *line, *scaled_line;
  svn_boolean_t do_scale = max_x > 0;

  /* xsize = max cluster number */
  for (y = 0; y < ysize; ++y)
    if (xsize < APR_ARRAY_IDX(info, y, file_stats_t *)->read_map->nelts)
      xsize = APR_ARRAY_IDX(info, y, file_stats_t *)->read_map->nelts;

  /* limit picture dimensions (16k pixels in each direction) */
  if (xsize >= 0x4000)
    xsize = 0x3fff;
  if (ysize >= 0x4000)
    ysize = 0x3fff;
  if (max_x == 0)
    max_x = xsize;

  /* rows in BMP files must be aligned to 4 bytes */
  row_size = APR_ALIGN(max_x * sizeof(color_t), 4);

  /**/
  line = apr_pcalloc(pool, xsize * sizeof(color_t));
  scaled_line = apr_pcalloc(pool, row_size);

  /* write header to file */
  write_bitmap_header(file, max_x, ysize);

  /* write all rows */
  for (y = 0; y < ysize; ++y)
    {
      file_stats_t *file_info = APR_ARRAY_IDX(info, y, file_stats_t *);
      int block_count = file_info->read_map->nelts;
      for (x = 0; x < xsize; ++x)
        {
          color_t color = { 128, 128, 128 };
          if (x < block_count)
            {
              word count = APR_ARRAY_IDX(file_info->read_map, x, word);
              select_color(color, count);
            }

          memcpy(line[x], color, sizeof(color));
        }

      scale_line(scaled_line, max_x, line, block_count ? block_count : 1);

      written = row_size;
      apr_file_write(file, do_scale ? scaled_line : line, &written);
    }
}
コード例 #18
0
ファイル: io.c プロジェクト: njlg/mod_sq
// write
SQInteger file_put_contents(HSQUIRRELVM v) {
	// function parameters
	const SQChar* filename;
	const SQChar* contents;

	// internal structures
	apr_file_t* file;
	apr_size_t nbytes;
	apr_status_t status;
	request_rec* r = get_request_rec(v);

	// for error messages
	char error[120];
	char errorMessage[120];

	ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "file_put_contents()");

	// grab filename param
	if( sq_gettype(v, 2) != OT_STRING ) {
		return SQ_ERROR;
	}
	else if( SQ_FAILED(sq_getstring(v, 2, &filename)) ) {
		return SQ_ERROR;
	}

	// grab contents param
	if( sq_gettype(v, 3) != OT_STRING ) {
		return SQ_ERROR;
	}
	else if( SQ_FAILED(sq_getstring(v, 3, &contents)) ) {
		return SQ_ERROR;
	}

	nbytes = strlen(contents);

	ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "    file_put_contents('%s', '%s') %d", filename, contents, (int)nbytes);
	if( (status = apr_file_open(&file, filename, APR_WRITE|APR_CREATE, APR_OS_DEFAULT, r->pool)) != APR_SUCCESS ) {
		apr_strerror(status, error, sizeof error);
		ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "    file_put_contents() failed: %s", error);
		sprintf(errorMessage, "file_put_contents() failed: %s", error);
		errorfunc(v, errorMessage);
		sq_pushbool(v, SQFalse);
	}
	else if( (status = apr_file_write(file, contents, &nbytes)) != APR_SUCCESS ) {
		apr_strerror(status, error, sizeof error);
		ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "    file_put_contents() failed: %s", error);
		sprintf(errorMessage, "file_put_contents() failed: %s", error);
		errorfunc(v, errorMessage);
		sq_pushbool(v, SQFalse);
	}
	else {
		sq_pushinteger(v, nbytes);
		ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "    file_put_contents() wrote %d bytes", (int)nbytes);
	}

	ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "file_put_contents() returning 1");
	return 1;
}
コード例 #19
0
ファイル: aos_log.c プロジェクト: EricChen2013/EasyRMS
void aos_log_print_default(const char *message, int len)
{
    if (aos_stderr_file == NULL) {
        fprintf(stderr, "%s", message);
    } else {
        apr_size_t bnytes = len;
        apr_file_write(aos_stderr_file, message, &bnytes);
    }
}
コード例 #20
0
ファイル: readwrite.c プロジェクト: AAthresh/quantlib
APR_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile, const struct iovec *vec,
                                          apr_size_t nvec, apr_size_t *nbytes)
{
#ifdef HAVE_WRITEV
    apr_status_t rv;
    int bytes;

    if (thefile->buffered) {
        file_lock(thefile);

        rv = apr_file_flush_locked(thefile);
        if (rv != APR_SUCCESS) {
            file_unlock(thefile);
            return rv;
        }
        if (thefile->direction == 0) {
            /* Position file pointer for writing at the offset we are
             * logically reading from
             */
            apr_int64_t offset = thefile->filePtr - thefile->dataRead +
                                 thefile->bufpos;
            if (offset != thefile->filePtr)
                lseek(thefile->filedes, offset, SEEK_SET);
            thefile->bufpos = thefile->dataRead = 0;
        }

        file_unlock(thefile);
    }

    if ((bytes = writev(thefile->filedes, vec, nvec)) < 0) {
        *nbytes = 0;
        rv = errno;
    }
    else {
        *nbytes = bytes;
        rv = APR_SUCCESS;
    }
    return rv;
#else
    /**
     * The problem with trying to output the entire iovec is that we cannot
     * maintain the behavoir that a real writev would have.  If we iterate
     * over the iovec one at a time, we loose the atomic properties of 
     * writev().  The other option is to combine the entire iovec into one
     * buffer that we could then send in one call to write().  This is not 
     * reasonable since we do not know how much data an iovec could contain.
     *
     * The only reasonable option, that maintains the semantics of a real 
     * writev(), is to only write the first iovec.  Callers of file_writev()
     * must deal with partial writes as they normally would. If you want to 
     * ensure an entire iovec is written, use apr_file_writev_full().
     */

    *nbytes = vec[0].iov_len;
    return apr_file_write(thefile, vec[0].iov_base, nbytes);
#endif
}
コード例 #21
0
int slayer_server_log_message(slayer_server_log_manager_t *manager, const char *message) {
	if (message && manager->fhandle) {
		apr_thread_mutex_lock(manager->file_mutex);
		apr_size_t nbytes =  strlen(message);
		apr_file_write(manager->fhandle,message,&nbytes);
		apr_thread_mutex_unlock(manager->file_mutex);
	}
	return 0;
}
コード例 #22
0
ファイル: streams.c プロジェクト: Alkzndr/freebsd
/* Implements svn_write_fn_t */
static svn_error_t *
file_write_cb(void *baton, const char *buffer, apr_size_t *len)
{
  file_baton_t *b = baton;
  apr_status_t status = apr_file_write(b->out_file, buffer, len);
  if (status)
    return svn_error_wrap_apr(status, _("Can't write to connection"));
  return SVN_NO_ERROR;
}
コード例 #23
0
ファイル: fs_index_output.c プロジェクト: Moddus/lucino
static apr_status_t
lcn_fs_index_output_flush_buffer ( lcn_index_output_t *os, char *buf, size_t len )
{
    apr_status_t s;
    apr_size_t l = len;
    
    LCNCR( apr_file_write( ( ( lcn_fs_index_output_t* ) os )->_apr_file, buf, &l ) );
    
    return s;
}
コード例 #24
0
ファイル: mod_moon.c プロジェクト: valderrama/ModSSOBand
// write_name_data is a call back function used by libcurl to deal with the body
// data from http requests to websites. it modifies a file/stream with information
// about a place's coordinates
static int write_name_data(void *ptr, size_t size, size_t nmemb, void *stream) {
	char * result = match_and_process_expression( NULL, ptr, LATLON_NUM_GROUPS, 										REGEXP_GROUP_SIZE, LATLON_REG_EXP, get_lat_and_lon);
	if(result==NULL) {
		return OK;
	}
	int result_len = strlen(result);
	apr_file_write((apr_file_t*)stream, result, &result_len);
	free(result);
	return result_len;
}
コード例 #25
0
static apr_status_t tmpfile_filter(ap_filter_t *f, apr_bucket_brigade *bbout,
	ap_input_mode_t mode, apr_read_type_e block, apr_off_t nbytes) {

  apr_bucket_brigade* bbin = apr_brigade_create(f->r->pool,
	     f->r->connection->bucket_alloc);

  apr_file_t* tmpfile ;
  char* tmpname = apr_pstrdup(f->r->pool, "/tmp/mod-upload.XXXXXX") ;

  if ( f->ctx ) {
    APR_BRIGADE_INSERT_TAIL(bbout, apr_bucket_eos_create(bbout->bucket_alloc)) ;
    return APR_SUCCESS ;
  }
  if ( apr_file_mktemp(&tmpfile, tmpname, KEEPONCLOSE, f->r->pool) != APR_SUCCESS ) {
	            // error
    ap_remove_input_filter(f) ;
  }
  apr_pool_cleanup_register(f->r->pool, tmpfile,
		(void*)apr_file_close, apr_pool_cleanup_null) ;

  for ( ; ; ) {
    apr_bucket* b ;
    const char* ptr = 0 ;
    apr_size_t bytes ;
#ifdef DEBUG
    ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0, f->r, "get_brigade") ;
#endif
    ap_get_brigade(f->next, bbin, AP_MODE_READBYTES, APR_BLOCK_READ, BUFLEN) ;
    for ( b = APR_BRIGADE_FIRST(bbin) ;
	b != APR_BRIGADE_SENTINEL(bbin) && ! f->ctx ;
	b = APR_BUCKET_NEXT(b) ) {
      if ( APR_BUCKET_IS_EOS(b) ) {
	f->ctx = f ;	// just using it as a flag; any nonzero will do
	apr_file_flush(tmpfile) ;
	apr_brigade_puts(bbout, ap_filter_flush, f, tmpname) ;
	APR_BRIGADE_INSERT_TAIL(bbout,
		apr_bucket_eos_create(bbout->bucket_alloc) ) ;
      } else if ( apr_bucket_read(b, &ptr, &bytes, APR_BLOCK_READ)
		== APR_SUCCESS ) {
#ifdef DEBUG
  ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0, f->r, "	%d bytes in bucket", bytes) ;
#endif
	apr_file_write(tmpfile, ptr, &bytes) ;
      }
    }
    if ( f->ctx )
      break ;
    else
      apr_brigade_cleanup(bbin) ;
  }

  apr_brigade_destroy(bbin) ;

  return APR_SUCCESS ;
}
コード例 #26
0
/* Returns the amount written. */
static int bio_file_write(BIO *bio, const char *in, int inl)
{
    apr_file_t *file = bio->ptr;
    apr_size_t nbytes;

    BIO_clear_retry_flags(bio);

    nbytes = inl;
    apr_file_write(file, in, &nbytes);

    return nbytes;
}
コード例 #27
0
ファイル: protolog.c プロジェクト: rachelbythebay/protolog
static int write_to_log_array(request_rec* r, apr_array_header_t* logs,
                              const char* buf, size_t buflen) {
  int i;
  protolog_file* log_array = (protolog_file*) logs->elts;

  for (i = 0; i < logs->nelts; ++i) {
    protolog_file* log = &log_array[i];

    apr_file_write(log->log_handle, buf, &buflen);
  }

  return OK;
}
コード例 #28
0
ファイル: testdup.c プロジェクト: Ga-vin/apache
static void test_dup2_readwrite(abts_case *tc, void *data)
{
    apr_file_t *errfile = NULL;
    apr_file_t *testfile = NULL;
    apr_file_t *saveerr = NULL;
    apr_status_t rv;
    apr_size_t txtlen = sizeof(TEST);
    char buff[50];
    apr_off_t fpos;

    rv = apr_file_open(&testfile, FILEPATH "testdup2.readwrite.file",
                       APR_FOPEN_READ | APR_FOPEN_WRITE | APR_FOPEN_CREATE |
                       APR_FOPEN_DELONCLOSE, APR_OS_DEFAULT, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_PTR_NOTNULL(tc, testfile);

    rv = apr_file_open_stderr(&errfile, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    /* Set aside the real errfile */
    rv = apr_file_dup(&saveerr, errfile, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_PTR_NOTNULL(tc, saveerr);

    rv = apr_file_dup2(errfile, testfile, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_PTR_NOTNULL(tc, errfile);

    txtlen = sizeof(TEST2);
    rv = apr_file_write(errfile, TEST2, &txtlen);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_SIZE_EQUAL(tc, sizeof(TEST2), txtlen);

    fpos = 0;
    rv = apr_file_seek(testfile, APR_SET, &fpos);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_ASSERT(tc, "File position mismatch, expected 0", fpos == 0);

    txtlen = 50;
    rv = apr_file_read(testfile, buff, &txtlen);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_STR_EQUAL(tc, TEST2, buff);

    apr_file_close(testfile);

    rv = apr_file_dup2(errfile, saveerr, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_PTR_NOTNULL(tc, errfile);

    apr_file_close(saveerr);
}
コード例 #29
0
ファイル: mpm_unix.c プロジェクト: amaji/httpd-online-2.4.3
static apr_status_t pod_signal_internal(ap_pod_t *pod)
{
    apr_status_t rv;
    char char_of_death = '!';
    apr_size_t one = 1;

    rv = apr_file_write(pod->pod_out, &char_of_death, &one);
    if (rv != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf, APLOGNO(00053)
                     "write pipe_of_death");
    }

    return rv;
}
コード例 #30
0
S32 ll_apr_file_write(apr_file_t* apr_file, const void *buf, S32 nbytes)
{
	apr_size_t sz = nbytes;
	apr_status_t s = apr_file_write(apr_file, buf, &sz);
	if (s != APR_SUCCESS)
	{
		return 0;
	}
	else
	{
		llassert_always(sz <= 0x7fffffff);
		return (S32)sz;
	}
}