示例#1
0
void CDemoRecorder::WriteDemoFile()
{
	// using operator<<(basic_stringbuf*) requires the stream to be opened with std::ios::in
	// stringbuf::{eback(), egptr(), gptr()} are protected so we cannot access them directly
	// (plus data is not guaranteed to be stored contiguously) ==> the only clean OO solution
	// that avoids str()'s copy would be to supply our own stringbuffer backend to demoStream
	// which is slightly overdoing it
	const std::string data = demoStream.str();
	gzwrite(file, data.c_str(), data.size());
	gzflush(file, Z_FINISH);
	gzclose(file);
}
示例#2
0
int ZOLTAN_FILE_flush(ZOLTAN_FILE* file)
{
  switch (file->type) {
  case STANDARD:
    return (fflush(file->strm.fileunc));
#ifdef ZOLTAN_GZIP
  case GZIP:
    return (gzflush(file->strm.filegz, Z_SYNC_FLUSH));
#endif
  default:
    break;
  }
  return (0);
}
示例#3
0
文件: c_gz.c 项目: amnh/poy5
value mlgz_gzflush(value flush, value chan)
{
  static const int flush_val[] = { 
    Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH } ;
  gzFile str = Gzfile_val(chan);
  int c_flush_val = 0;
  int res;
  if(Is_block(flush))
    c_flush_val = Int_val(Field(flush, 0));
  res = gzflush(str, flush_val[ c_flush_val ]) ;
  if(res<0)
    mlgz_error(str);
  return Val_unit;
}
示例#4
0
文件: fzp.c 项目: vanElden/burp
int fzp_flush(struct fzp *fzp)
{
	if(fzp) switch(fzp->type)
	{
		case FZP_FILE:
			return fflush(fzp->fp);
		case FZP_COMPRESSED:
			return gzflush(fzp->zp, Z_FINISH);
		default:
			unknown_type(fzp->type, __func__);
			goto error;
	}
	not_open(__func__);
error:
	return EOF;
}
示例#5
0
HIDDEN int backup_real_append_start(struct backup *backup,
                                    time_t ts, off_t offset,
                                    const char *file_sha1,
                                    int index_only,
                                    enum backup_append_flush flush)
{
    int r;

    if (backup->append_state != NULL
        && backup->append_state->mode != BACKUP_APPEND_INACTIVE) {
        fatal("backup append already started", EX_SOFTWARE);
    }

    if (!backup->append_state)
        backup->append_state = xzmalloc(sizeof(*backup->append_state));

    if (index_only) backup->append_state->mode |= BACKUP_APPEND_INDEXONLY;

    backup->append_state->wrote = 0;
    SHA1_Init(&backup->append_state->sha_ctx);

    char header[80];
    snprintf(header, sizeof(header), "# cyrus backup: chunk start\r\n");

    if (!index_only) {
        if (!backup->append_state->gzfile) {
            backup->append_state->gzfile = gzdopen(backup->fd, "ab");
            if (!backup->append_state->gzfile) {
                fprintf(stderr, "%s: gzdopen fd %i failed: %s\n",
                        __func__, backup->fd, strerror(errno));
                goto error;
            }
        }

        r = retry_gzwrite(backup->append_state->gzfile,
                          header, strlen(header), backup->data_fname);
        if (!r && flush)
            r = gzflush(backup->append_state->gzfile, Z_FULL_FLUSH);

        if (r) goto error;
    }

    SHA1_Update(&backup->append_state->sha_ctx, header, strlen(header));
    backup->append_state->wrote += strlen(header);

    struct sqldb_bindval bval[] = {
        { ":ts_start",  SQLITE_INTEGER, { .i = ts           } },
示例#6
0
void MDFNI_SaveMovie(char *fname, const MDFN_Surface *surface, const MDFN_Rect *DisplayRect, const int32 *LineWidths)
{
 gzFile fp;

 if(!MDFNGameInfo->StateAction)
  return;

 if(MDFNnetplay && (MDFNGameInfo->SaveStateAltersState == true))
 {
  char sb[256];
  trio_snprintf(sb, sizeof(sb), _("Module %s is not compatible with manual movie save starting/stopping during netplay."), MDFNGameInfo->shortname);
  MDFND_NetplayText((const uint8*)sb, false);
  return;
 }

 if(current < 0)	/* Can't interrupt playback.*/
  return;

 if(current > 0)	/* Stop saving. */
 {
  StopRecording();
  return;  
 }

 memset(&RewindBuffer, 0, sizeof(StateMem));
 RewindBuffer.initial_malloc = 16;

 current = CurrentMovie;

 if(fname)
  fp = gzopen(fname, "wb3");
 else
 {
  fp=gzopen(MDFN_MakeFName(MDFNMKF_MOVIE,CurrentMovie,0).c_str(),"wb3");
 }

 if(!fp) return;

 MDFNSS_SaveFP(fp, surface, DisplayRect, LineWidths);
 gzseek(fp, 0, SEEK_END);
 gzflush(fp, Z_SYNC_FLUSH); // Flush output so that previews will still work right while
			    // the movie is being recorded.  Purely cosmetic. :)
 slots[current] = fp;
 current++;
 MDFN_DispMessage(_("Movie recording started."));
}
示例#7
0
static int z_fflush(void *_fh)
{     struct z_file *fh = _fh;
      int ret;
      ret = gzflush(fh->file, Z_FINISH);
      if (ret == Z_OK)
         ret = 0;
      else
      {  int errnum;
         const char *msg;
         fh->err = 1;
         msg = gzerror(fh->file, &errnum);
         if (errnum == Z_ERRNO)
            lib_err_msg(strerror(errno));
         else
            lib_err_msg(msg);
         ret = XEOF;
      }
      return ret;
}
示例#8
0
文件: iolib.cpp 项目: AMDmi3/Wyrmgus
void CFile::PImpl::flush()
{
	if (cl_type != CLF_TYPE_INVALID) {
		if (cl_type == CLF_TYPE_PLAIN) {
			fflush(cl_plain);
		}
#ifdef USE_ZLIB
		if (cl_type == CLF_TYPE_GZIP) {
			gzflush(cl_gz, Z_SYNC_FLUSH);
		}
#endif // USE_ZLIB
#ifdef USE_BZ2LIB
		if (cl_type == CLF_TYPE_BZIP2) {
			BZ2_bzflush(cl_bz);
		}
#endif // USE_BZ2LIB
	} else {
		errno = EBADF;
	}
}
示例#9
0
文件: ts_file.c 项目: cutebomb/tickdb
int ts_fflush(ts_file_t *fp)
{
  TS_TRY(fp);
  int rv = -1;
  switch(fp->type) {
  case TS_FILE_STD: return(fflush(fp->fp.std));
  case TS_FILE_ZLB: 
    rv = gzflush(fp->fp.zlb, Z_SYNC_FLUSH);
    if(rv == Z_OK)
      return 0;
    else
      return EOF;
    break;
  case TS_FILE_XZ:  return (xzflush(fp->fp.xz));
  default:
    (void)ts_warn(stderr, "\n");
    goto fail;
  }
 fail:
  return(-1);
}
示例#10
0
FileBase& OFile::flush() {
  if(heavyFlush) {
    if(gzfp) {
#ifdef __PLUMED_HAS_ZLIB
      gzclose(gzFile(gzfp));
      gzfp=(void*)gzopen(const_cast<char*>(path.c_str()),"a");
#endif
    } else {
      fclose(fp);
      fp=std::fopen(const_cast<char*>(path.c_str()),"a");
    }
  } else {
    FileBase::flush();
    // if(gzfp) gzflush(gzFile(gzfp),Z_FINISH);
    // for some reason flushing with Z_FINISH has problems on linux
    // I thus use this (incomplete) flush
#ifdef __PLUMED_HAS_ZLIB
    if(gzfp) gzflush(gzFile(gzfp),Z_FULL_FLUSH);
#endif
  }
  return *this;
}
示例#11
0
void gzcompress(const char *file, const char * filename)
{
	FILE * fin;
	void * buf;
	size_t size, temp;
	
	gzFile gzfile;
	fin = fopen(file, "rb");
	fseek(fin, 0, SEEK_END);
	size = ftell(fin);
	printf("Input file size %d\n", size);
	buf = malloc(size);
	rewind(fin);
	fread(buf, 1, size, fin);
	gzfile = gzopen(filename, "wb");
	temp = gzwrite(gzfile, buf, size);
	printf("Write size %d\n", temp);
	size = gzflush(gzfile, Z_FINISH);
	if(size != Z_OK)
		printf("Doomed!\n");
	free(buf);
	gzclose(gzfile);
}
示例#12
0
/**
 * Flush the messages to the log file
 *
 * @param data ignored
 * @param scheduled time when the callback should have been called
 * @param interval ignored
 *
 * @return DESSERT_PER_KEEP (do not unregister)
 */
dessert_per_result_t _dessert_flush_log(void* data, struct timeval* scheduled, struct timeval* interval) {
    if(_dessert_logfd != NULL) {
        pthread_mutex_lock(&_dessert_logfile_mutex);
        fflush(_dessert_logfd);
        pthread_mutex_unlock(&_dessert_logfile_mutex);
    }

#ifdef HAVE_LIBZ

    if(_dessert_logfdgz != NULL) {
        pthread_mutex_lock(&_dessert_logfile_mutex);
        int r = gzflush(_dessert_logfdgz, Z_SYNC_FLUSH);
        pthread_mutex_unlock(&_dessert_logfile_mutex);

        if(r != Z_OK) {
            dessert_warn("gzflush returned %d", r);
        }
    }

#endif
    dessert_debug("*** flushed log ***");
    return DESSERT_PER_KEEP;
}
示例#13
0
static TACommandVerdict gzflush_cmd(TAThread thread,TAInputStream stream)
{
    void* file;
    int res, flush, errnum;

    file = readPointer(&stream);
    flush = readInt(&stream);

    START_TARGET_OPERATION(thread);

    res = gzflush(file, flush);

    END_TARGET_OPERATION(thread);

    gzerror(file, &errnum);

    writeInt(thread, errnum);
    writeInt(thread, errno);
    writeInt(thread, res);

    sendResponse(thread);

    return taDefaultVerdict;
}
示例#14
0
/* Dump database into output_file_name if it's non-NULL, stdout
 * otherwise.
 */
int
notmuch_database_dump (notmuch_database_t *notmuch,
		       const char *output_file_name,
		       const char *query_str,
		       dump_format_t output_format,
		       notmuch_bool_t gzip_output)
{
    gzFile output = NULL;
    const char *mode = gzip_output ? "w9" : "wT";
    const char *name_for_error = output_file_name ? output_file_name : "stdout";

    char *tempname = NULL;
    int outfd = -1;

    int ret = -1;

    if (output_file_name) {
	tempname = talloc_asprintf (notmuch, "%s.XXXXXX", output_file_name);
	outfd = mkstemp (tempname);
    } else {
	outfd = dup (STDOUT_FILENO);
    }

    if (outfd < 0) {
	fprintf (stderr, "Bad output file %s\n", name_for_error);
	goto DONE;
    }

    output = gzdopen (outfd, mode);

    if (output == NULL) {
	fprintf (stderr, "Error opening %s for (gzip) writing: %s\n",
		 name_for_error, strerror (errno));
	if (close (outfd))
	    fprintf (stderr, "Error closing %s during shutdown: %s\n",
		 name_for_error, strerror (errno));
	goto DONE;
    }

    ret = database_dump_file (notmuch, output, query_str, output_format);
    if (ret) goto DONE;

    ret = gzflush (output, Z_FINISH);
    if (ret) {
	fprintf (stderr, "Error flushing output: %s\n", gzerror (output, NULL));
	goto DONE;
    }

    if (output_file_name) {
	ret = fdatasync (outfd);
	if (ret) {
	    fprintf (stderr, "Error syncing %s to disk: %s\n",
		     name_for_error, strerror (errno));
	    goto DONE;
	}
    }

    if (gzclose_w (output) != Z_OK) {
	fprintf (stderr, "Error closing %s: %s\n", name_for_error,
		 gzerror (output, NULL));
	ret = EXIT_FAILURE;
	output = NULL;
	goto DONE;
    }

    if (output_file_name) {
	ret = rename (tempname, output_file_name);
	if (ret) {
	    fprintf (stderr, "Error renaming %s to %s: %s\n",
		     tempname, output_file_name, strerror (errno));
	    goto DONE;
	}

    }
 DONE:
    if (ret != EXIT_SUCCESS && output)
	(void) gzclose_w (output);

    if (ret != EXIT_SUCCESS && output_file_name)
	(void) unlink (tempname);

    return ret;
}
示例#15
0
文件: deliver-mbox.c 项目: mbeck-/fdm
int
deliver_mbox_deliver(struct deliver_ctx *dctx, struct actitem *ti)
{
    struct account			*a = dctx->account;
    struct mail			*m = dctx->mail;
    struct deliver_mbox_data	*data = ti->data;
    char				*path, *ptr, *lptr, *from = NULL;
    const char			*msg;
    size_t				 len, llen;
    int				 fd, saved_errno;
    FILE				*f;
    gzFile				 gzf;
    long long			 used;
    sigset_t			 set, oset;
    struct stat			 sb;

    f = gzf = NULL;
    fd = -1;

    path = replacepath(&data->path, m->tags, m, &m->rml, dctx->udata->home);
    if (path == NULL || *path == '\0') {
        log_warnx("%s: empty path", a->name);
        goto error;
    }
    if (data->compress) {
        len = strlen(path);
        if (len < 3 || strcmp(path + len - 3, ".gz") != 0) {
            path = xrealloc(path, 1, len + 4);
            strlcat(path, ".gz", len + 4);
        }
    }
    log_debug2("%s: saving to mbox %s", a->name, path);

    /* Save the mbox path. */
    add_tag(&m->tags, "mbox_file", "%s", path);

    /* Check permissions and ownership. */
    if (stat(path, &sb) != 0) {
        if (conf.no_create || errno != ENOENT)
            goto error_log;

        log_debug2("%s: creating %s", a->name, xdirname(path));
        if (xmkpath(xdirname(path), -1, conf.file_group, DIRMODE) != 0)
            goto error_log;
    } else {
        if ((msg = checkmode(&sb, UMASK(FILEMODE))) != NULL)
            log_warnx("%s: %s: %s", a->name, path, msg);
        if ((msg = checkowner(&sb, -1)) != NULL)
            log_warnx("%s: %s: %s", a->name, path, msg);
        if ((msg = checkgroup(&sb, conf.file_group)) != NULL)
            log_warnx("%s: %s: %s", a->name, path, msg);
    }

    /* Create or open the mbox. */
    used = 0;
    do {
        if (conf.no_create)
            fd = openlock(path, O_WRONLY|O_APPEND, conf.lock_types);
        else {
            fd = createlock(path, O_WRONLY|O_APPEND,
                            -1, conf.file_group, FILEMODE, conf.lock_types);
        }
        if (fd == -1 && errno == EEXIST)
            fd = openlock(path, O_WRONLY|O_APPEND, conf.lock_types);
        if (fd == -1) {
            if (errno == EAGAIN) {
                if (locksleep(a->name, path, &used) != 0)
                    goto error;
                continue;
            }
            goto error_log;
        }
    } while (fd < 0);

    /* Open gzFile or FILE * for writing. */
    if (data->compress) {
        if ((gzf = gzdopen(fd, "a")) == NULL) {
            errno = ENOMEM;
            goto error_log;
        }
    } else {
        if ((f = fdopen(fd, "a")) == NULL)
            goto error_log;
    }

    /*
     * mboxes are a pain: if we are interrupted after this we risk
     * having written a partial mail. So, block SIGTERM until we're
     * done.
     */
    sigemptyset(&set);
    sigaddset(&set, SIGTERM);
    if (sigprocmask(SIG_BLOCK, &set, &oset) < 0)
        fatal("sigprocmask failed");

    /* Write the from line. */
    from = make_from(m, dctx->udata->name);
    if (deliver_mbox_write(f, gzf, from, strlen(from)) < 0) {
        xfree(from);
        goto error_unblock;
    }
    if (deliver_mbox_write(f, gzf, "\n", 1) < 0) {
        xfree(from);
        goto error_unblock;
    }
    log_debug3("%s: using from line: %s", a->name, from);
    xfree(from);

    /* Write the mail, escaping from lines. */
    line_init(m, &ptr, &len);
    while (ptr != NULL) {
        if (ptr != m->data) {
            /* Skip leading >s. */
            lptr = ptr;
            llen = len;
            while (*lptr == '>' && llen > 0) {
                lptr++;
                llen--;
            }

            if (llen >= 5 && strncmp(lptr, "From ", 5) == 0) {
                log_debug2("%s: quoting from line: %.*s",
                           a->name, (int) len - 1, ptr);
                if (deliver_mbox_write(f, gzf, ">", 1) < 0)
                    goto error_unblock;
            }
        }

        if (deliver_mbox_write(f, gzf, ptr, len) < 0)
            goto error_unblock;

        line_next(m, &ptr, &len);
    }

    /* Append newlines. */
    if (m->data[m->size - 1] == '\n') {
        if (deliver_mbox_write(f, gzf, "\n", 1) < 0)
            goto error_unblock;
    } else {
        if (deliver_mbox_write(f, gzf, "\n\n", 2) < 0)
            goto error_unblock;
    }

    /* Flush buffers and sync. */
    if (gzf == NULL) {
        if (fflush(f) != 0)
            goto error_unblock;
    } else {
        if (gzflush(gzf, Z_FINISH) != Z_OK) {
            errno = EIO;
            goto error_unblock;
        }
    }
    if (fsync(fd) != 0)
        goto error_unblock;

    if (sigprocmask(SIG_SETMASK, &oset, NULL) < 0)
        fatal("sigprocmask failed");

    if (gzf != NULL)
        gzclose(gzf);
    if (f != NULL)
        fclose(f);
    closelock(fd, path, conf.lock_types);

    xfree(path);
    return (DELIVER_SUCCESS);

error_unblock:
    saved_errno = errno;
    if (sigprocmask(SIG_SETMASK, &oset, NULL) < 0)
        fatal("sigprocmask failed");
    errno = saved_errno;

error_log:
    log_warn("%s: %s", a->name, path);

error:
    if (gzf != NULL)
        gzclose(gzf);
    if (f != NULL)
        fclose(f);
    if (fd != -1)
        closelock(fd, path, conf.lock_types);

    if (path != NULL)
        xfree(path);
    return (DELIVER_FAILURE);
}
示例#16
0
void flush_health() {
    // printf("flush health\n");
    gzflush( fhealth, Z_SYNC_FLUSH );
}
示例#17
0
void flush_servo() {
    // printf("flush servo\n");
    gzflush( fservo, Z_SYNC_FLUSH );
}
示例#18
0
文件: omfp.c 项目: nixnodes/glutil
int
g_print_stats (char *file, uint32_t flags, size_t block_sz)
{
  g_setjmp (0, "g_print_stats", NULL, NULL);

  if (block_sz)
    {
      g_act_1.block_sz = block_sz;
    }

  if (g_fopen (file, "r", F_DL_FOPEN_BUFFER | flags, &g_act_1))
    {
      return 2;
    }

  if (gfl & F_OPT_LOADQ)
    {
      goto rc_end;
    }

  void *buffer = calloc (1, g_act_1.block_sz);

  pt_g_bmatch proc_match = g_bmatch;

  int r = 0;

  if (gfl & F_OPT_SORT)
    {
      if (gfl & F_OPT_NOBUFFER)
	{
	  print_str ("ERROR: %s: unable to sort with buffering disabled\n",
		     g_act_1.file);
	  goto r_end;
	}

      void *s_exec = (void*) g_act_1.exec_args.exc;

      if (l_sfo == L_STFO_SORT)
	{
	  if (g_print_do_filter (&g_act_1, s_exec))
	    {
	      goto r_end;
	    }
	}

      if (gfl & F_OPT_KILL_GLOBAL)
	{
	  goto r_end;
	}

      if (do_sort (&g_act_1, g_sort_field, g_sort_flags))
	{
	  goto r_end;
	}

      if (l_sfo == L_STFO_FILTER)
	{
	  if (g_print_do_filter (&g_act_1, s_exec))
	    {
	      goto r_end;
	    }
	}

      if (gfl & F_OPT_KILL_GLOBAL)
	{
	  goto r_end;
	}

      g_act_1.max_hits = 0;
      g_act_1.max_results = 0;

      if (g_act_1.j_offset == 2)
	{
	  g_act_1.buffer.r_pos = md_last (&g_act_1.buffer);
	}
      else
	{
	  g_act_1.buffer.r_pos = md_first (&g_act_1.buffer);
	}

      //proc_match = g_bmatch_dummy;

      md_g_free_cb (&g_act_1._match_rr, g_cl_mrr);
    }

  __d_is_wb w_d_s = g_act_1.w_d;

  g_act_1.w_d = g_act_1.w_d_pr;

  g_do_ppprint (&g_act_1, F_GH_PRE_PRINT, &g_act_1.pre_print_mech,
		g_act_1.g_proc4_pr);

  if (gfl0 & F_OPT_LOADQA)
    {
      goto r_end;
    }

  g_act_1.w_d = w_d_s;

  void *ptr;

  size_t c = 0;

  g_setjmp (F_SIGERR_CONTINUE, "g_print_stats(loop)", NULL, NULL);

  g_act_1.buffer.offset = 0;

  if (!sigsetjmp(g_sigjmp.env, 1))
    {
      while ((ptr = g_read (buffer, &g_act_1, g_act_1.block_sz)))
	{
	  if ((gfl & F_OPT_KILL_GLOBAL))
	    {
	      break;
	    }

	  if ((r = proc_match (ptr, &g_act_1, &g_act_1.buffer)))
	    {
	      if (r == -1)
		{
		  print_str ("ERROR: %s: [%d] matching record failed\n",
			     g_act_1.file, r);
		  break;
		}

	      continue;
	    }

	  c++;
	  g_act_1.g_proc4 ((void*) &g_act_1, ptr, NULL);

	}

    }
  else
    {
      print_str (
	  "ERROR: %s: an exception has occured, terminating enumeration and attempt cleanup..\n",
	  g_act_1.file);
      EXITVAL = 2;
      goto r_end;
    }

  g_act_1.w_d = g_act_1.w_d_po;

  g_do_ppprint (&g_act_1, F_GH_POST_PRINT, &g_act_1.post_print_mech,
		g_act_1.g_proc4_po);

  if (gfl & F_OPT_MODE_RAWDUMP)
    {
#ifdef HAVE_ZLIB_H
      if ((g_act_1.flags & F_GH_IO_GZIP) && g_act_1.gz_fh1)
	{
	  gzflush(g_act_1.gz_fh1, Z_FINISH);
	}
#endif
      fflush (stdout);
    }

  // g_setjmp(0, "dirlog_print_stats(2)", NULL, NULL);

  if (!(g_act_1.flags & F_GH_ISONLINE) && (gfl0 & F_OPT_STATS))
    {
      fprintf (
	  stderr,
	  "STATS: %s: processed %llu/%llu records\n",
	  file,
	  (unsigned long long int) c,
	  !g_act_1.buffer.count ?
	      (unsigned long long int) c : g_act_1.buffer.count);
    }

  if (0 == c && 0 == EXITVAL)
    {
      EXITVAL = 2;
    }

  r_end:

  free (buffer);

  rc_end:

  g_close (&g_act_1);

  return EXITVAL;
}
示例#19
0
int gzipFilterX(FILE *in,FILE *out,SyncXF syncf,void *sp,int si){
	gzFile gz;
	int len,rcc;
	CStr(buf,1024*8);
	int size;
	int gsize;
	int wcc;
	int bcc = 0;
	double Start = Time();
	double Prevf = 0;
	int ibz = sizeof(buf);
	int gi;
	int fd = -1;
	int ofd = fileno(out);
	int xfd;
	int zerr = 0;
	/*
	int rready = -1;
	*/

	errno = 0;
	fd = dup(fileno(out));
	if( fd < 0 ){
		syslog_ERROR("--gzipFilter[%d]<-[%d] errno=%d\n",fd,ofd,errno);
		return -1;
	}

	/*
	if( 0 <= GZIPready )
		rready = dup(GZIPready);
	*/
	len = 0;
	/*
	if( gz = GZdopen(dup(fileno(out)),"w") ){
	*/
	if( file_isSOCKET(ofd) || file_ISSOCK(ofd) )
	if( !IsConnected(ofd,NULL) || !IsAlive(ofd) ){

fprintf(stderr,"[%d.%X] gzip DISCONN\n",getpid(),getthreadid());
fprintf(stderr,"[%d.%X] gzip DISCONN fd[%d] con=%d isSOCK=%d,%d,%d\n",
getpid(),getthreadid(),ofd,IsConnected(ofd,NULL),
file_isSOCKET(ofd),file_ISSOCK(ofd),file_issock(ofd));

		sendsync(rready,1);
		close(fd);
		return -1;
	}
	gz = GZdopen(fd,"w");
	if( file_isSOCKET(ofd) || file_ISSOCK(ofd) )
	if( !IsConnected(ofd,NULL) || !IsAlive(ofd) ){

fprintf(stderr,"[%d.%X] gzip DISCONN gx=%d\n",getpid(),getthreadid(),p2i(gz));
fprintf(stderr,"[%d.%X] gzip DISCONN fd[%d] con=%d isSOCK=%d,%d,%d\n",
getpid(),getthreadid(),ofd,IsConnected(ofd,NULL),
file_isSOCKET(ofd),file_ISSOCK(ofd),file_issock(ofd));

		close(fd);
		sendsync(rready,2);
		close(fd);
		return -1;
	}

	if( gz ){
		LOGX_gzip++;
		if( Gzip_NoFlush ){
			GZDBG(stderr,"-- %X gzip flush disabled(%d)\n",
				TID,Gzip_NoFlush);
		}
		Prevf = Time();

		sendsync(rready,0);
		setCloseOnFork("GZIPstart",fd);
		/*
		while( rcc = fread(buf,1,sizeof(buf),in) ){
		*/
		for( gi = 0;; gi++ ){
			if( gotsigTERM("gzip gi=%d",gi) ){
				if( numthreads() && !ismainthread() ){
					thread_exit(0);
				}
				break;
			}
			if( !Gzip_NoFlush )
			if( bcc )
			if( 0 < len && finputReady(in,NULL) == 0 ){
				zerr =
				gzflush(gz,Z_SYNC_FLUSH);
if( zerr ){
porting_dbg("+++EPIPE[%d] gzflush() zerr=%d %d SIG*%d",fd,zerr,len,gotSIGPIPE());
}
				bcc = 0;
			}
			if( lSINGLEP() ) /* could be generic */
			{
				if( 0 < len )
				if( !Gzip_NoFlush
				 || 4 < gi && 5 < Time()-Prevf
				){
				GZDBG(stderr,"-- %X gzip flush %d(%f) %d/%d\n",
				TID,Gzip_NoFlush,Time()-Start,len,gi);
					Prevf = Time();
					zerr = gzflush(gz,Z_SYNC_FLUSH);
					bcc = 0;
					if( zerr ){
				GZDBG(stderr,"-- %X gzip gzflush()%d err=%d\n",
				TID,len,zerr);
						break;
					}
				}
			}
			/*
			rcc = fread(buf,1,sizeof(buf),in);
			*/
			rcc = xread(in,AVStr(buf),QVSSize(buf,ibz));

			if( rcc <= 0 ){
				break;
			}
			wcc =
			gzwrite(gz,buf,rcc);

//fprintf(stderr,"[%d] Gzwrite %d/%d / %d\n",getpid(),wcc,rcc,len);

if( wcc <= 0 ){
porting_dbg("+++EPIPE[%d] gzwrite() %d/%d %d SIG*%d",fd,wcc,rcc,len,gotSIGPIPE());
fprintf(stderr,"[%d] Gzwrite %d/%d / %d\n",getpid(),wcc,rcc,len);
break;
}

			if( wcc != rcc ){
				syslog_ERROR("gzwrite %d/%d\n",wcc,rcc);
			}
			if( 0 < wcc ){
				bcc += wcc;
			}
			if( sizeof(buf) <= len ){
				ibz = sizeof(buf);
			}
			if( !Gzip_NoFlush )
			if( bcc )
			if( sizeof(buf) <= bcc || len < 16*1024 ){
				zerr =
				gzflush(gz,Z_SYNC_FLUSH);
				bcc = 0;
			}
			if( zerr || gotSIGPIPE() ){
porting_dbg("+++EPIPE[%d] gzflush() zerr=%d %d SIG*%d",fd,zerr,len,gotSIGPIPE());
				break;
			}
			len += rcc;
		}
		if( len == 0 ){
			const char *em;
			int en;
			int ef;
			em = gzerror(gz,&en);
			ef = gzeof(gz);
			if( en == -1 /* see errno */ && errno == 0 ){
				/* no error */
			}else{
			daemonlog("F","FATAL: gzwrite(%d)=%d/%d eof=%d %d %s\n",
				fd,len,bcc,ef,en,em);
			porting_dbg("FATAL: gzwrite(%d)=%d/%d eof=%d %d %s",
				fd,len,bcc,ef,en,em);
			}
		}
		clearCloseOnFork("GZIPend",fd);
		gzflush(gz,Z_SYNC_FLUSH);
		xfd = dup(fd);
		gsize = GZtell(gz);
		GZclose(gz);
		if( isWindowsCE() || lMULTIST() ){
			/* duplicated close of fd is harmful */
		}else
		if( isWindows() ) close(fd); /* to clear osf-handle mapping */
		Lseek(xfd,0,2);
		size = Lseek(xfd,0,1);
		Lseek(xfd,0,0);
		close(xfd);
		syslog_DEBUG("(%f)gzipFilter %d -> %d / %d\n",Time()-Start,
			len,gsize,size);
		return len;
	}
	sendsync(rready,3);
	close(fd);
	return 0;
}
示例#20
0
void ZipFile::flush() {
	if (m_gzipFile)
		gzflush(m_gzipFile, Z_FINISH);
	else if (m_plainFile)
		fflush(m_plainFile);
}
示例#21
0
文件: rpmio.c 项目: maxamillion/rpm
static int gzdFlush(FDSTACK_t fps)
{
    gzFile gzfile = fps->fp;
    if (gzfile == NULL) return -2;
    return gzflush(gzfile, Z_SYNC_FLUSH);	/* XXX W2DO? */
}
示例#22
0
文件: main.c 项目: ramonelalto/gambas
static int CZ_stream_flush(GB_STREAM *stream)
{
	gzflush(((STREAM_COMPRESS *)stream)->handle,Z_SYNC_FLUSH);
	return 0;
}
示例#23
0
 int sync()
 {
    return gzflush(file, Z_SYNC_FLUSH) == Z_OK ? 0 : -1;
 }
示例#24
0
static int php_gziop_flush(php_stream *stream)
{
	struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract;

	return gzflush(self->gz_file, Z_SYNC_FLUSH);
}
示例#25
0
void GzipOutputStream::flush()
{
	assert(m_fp);
	if (gzflush((gzFile)m_fp, Z_SYNC_FLUSH) == EOF)
		throw DelayWriteException(BOOST_CURRENT_FUNCTION);
}
示例#26
0
void flush_gps() {
    // printf("flush gps\n");
    gzflush( fgps, Z_SYNC_FLUSH );
}
示例#27
0
void EndLeave(void) {
    WriteByte(Trace::CALL_END);
    gzflush(g_gzFile, Z_SYNC_FLUSH);
    OS::ReleaseMutex();
}
示例#28
0
void flush_imu() {
    // printf("flush imu\n");
    gzflush( fimu, Z_SYNC_FLUSH );
}
示例#29
0
bool ZipFile::flush() {
  assert(m_gzFile);
  return gzflush(m_gzFile, Z_SYNC_FLUSH);
}
示例#30
0
void flush_nav() {
    // printf("flush nav\n");
    gzflush( fnav, Z_SYNC_FLUSH );
}