本文整理汇总了C++中close_fp函数的典型用法代码示例。如果您正苦于以下问题:C++ close_fp函数的具体用法?C++ close_fp怎么用?C++ close_fp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了close_fp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: make_rev_sig
static int make_rev_sig(const char *dst, const char *sig, const char *endfile, int compression, struct cntr *cntr)
{
FILE *dstfp=NULL;
gzFile dstzp=NULL;
FILE *sigp=NULL;
rs_result result;
//logp("make rev sig: %s %s\n", dst, sig);
if(dpth_is_compressed(compression, dst))
dstzp=gzopen_file(dst, "rb");
else
dstfp=open_file(dst, "rb");
if((!dstzp && !dstfp)
|| !(sigp=open_file(sig, "wb")))
{
gzclose_fp(&dstzp);
close_fp(&dstfp);
return -1;
}
result=rs_sig_gzfile(dstfp, dstzp, sigp,
get_librsync_block_len(endfile),
RS_DEFAULT_STRONG_LEN, NULL, cntr);
gzclose_fp(&dstzp);
close_fp(&dstfp);
close_fp(&sigp);
//logp("end of make rev sig\n");
return result;
}
示例2: ncp_put_super
static void
ncp_put_super(struct super_block *sb)
{
struct ncp_server *server = NCP_SBP(sb);
lock_super(sb);
ncp_lock_server(server);
ncp_disconnect(server);
ncp_unlock_server(server);
close_fp(server->ncp_filp);
ncp_dont_catch_watchdog(server);
close_fp(server->wdog_filp);
close_fp(server->msg_filp);
ncp_free_all_inodes(server);
ncp_kfree_s(server->packet, server->packet_size);
sb->s_dev = 0;
ncp_kfree_s(NCP_SBP(sb), sizeof(struct ncp_server));
NCP_SBP(sb) = NULL;
unlock_super(sb);
MOD_DEC_USE_COUNT;
}
示例3: make_rev_sig
static int make_rev_sig(const char *dst, const char *sig, const char *endfile,
int compression, struct conf *conf)
{
int ret=-1;
FILE *dstfp=NULL;
gzFile dstzp=NULL;
FILE *sigp=NULL;
//logp("make rev sig: %s %s\n", dst, sig);
if(dpthl_is_compressed(compression, dst))
dstzp=gzopen_file(dst, "rb");
else
dstfp=open_file(dst, "rb");
if((!dstzp && !dstfp)
|| !(sigp=open_file(sig, "wb"))
|| rs_sig_gzfile(NULL, dstfp, dstzp, sigp,
get_librsync_block_len(endfile),
RS_DEFAULT_STRONG_LEN, NULL, conf->cntr)!=RS_DONE)
goto end;
ret=0;
end:
//logp("end of make rev sig\n");
gzclose_fp(&dstzp);
close_fp(&dstfp);
if(close_fp(&sigp))
{
logp("error closing %s in %s\n", sig, __func__);
return -1;
}
return ret;
}
示例4: compress
static int compress(const char *src, const char *dst, struct config *cconf)
{
int res;
int got;
FILE *mp=NULL;
gzFile zp=NULL;
char buf[ZCHUNK];
if(!(mp=open_file(src, "rb"))
|| !(zp=gzopen_file(dst, comp_level(cconf))))
{
close_fp(&mp);
gzclose_fp(&zp);
return -1;
}
while((got=fread(buf, 1, sizeof(buf), mp))>0)
{
res=gzwrite(zp, buf, got);
if(res!=got)
{
logp("compressing manifest - read %d but wrote %d\n",
got, res);
close_fp(&mp);
gzclose_fp(&zp);
return -1;
}
}
close_fp(&mp);
return gzclose_fp(&zp); // this can give an error when out of space
}
示例5: rewrite_client_conf
/* Rewrite the config file with the ssl_peer_cn value changed to what the
server told us it should be. */
static int rewrite_client_conf(struct config *conf)
{
int ret=-1;
char p[32]="";
FILE *dp=NULL;
FILE *sp=NULL;
char *tmp=NULL;
char buf[4096]="";
logp("Rewriting config file: %s\n", conf->configfile);
snprintf(p, sizeof(p), ".%d", getpid());
if(!(tmp=prepend(conf->configfile, p, strlen(p), "")))
goto end;
if(!(sp=open_file(conf->configfile, "rb"))
|| !(dp=open_file(tmp, "wb")))
goto end;
while(fgets(buf, sizeof(buf), sp))
{
char *copy=NULL;
char *field=NULL;
char *value=NULL;
if(!(copy=strdup(buf)))
{
logp("out of memory\n");
goto end;
}
if(config_get_pair(buf, &field, &value)
|| !field || !value
|| strcmp(field, "ssl_peer_cn"))
{
fprintf(dp, "%s", copy);
free(copy);
continue;
}
free(copy);
fprintf(dp, "ssl_peer_cn = %s\n", conf->ssl_peer_cn);
}
close_fp(&sp);
close_fp(&dp);
#ifdef HAVE_WIN32
// Need to delete the destination, or Windows gets upset.
unlink(conf->configfile);
#endif
if(do_rename(tmp, conf->configfile)) goto end;
ret=0;
end:
close_fp(&sp);
close_fp(&dp);
if(ret)
{
logp("Rewrite failed\n");
unlink(tmp);
}
if(tmp) free(tmp);
return ret;
}
示例6: inflate_or_link_oldfile
static int inflate_or_link_oldfile(const char *oldpath, const char *infpath)
{
int ret=0;
struct stat statp;
if(lstat(oldpath, &statp))
{
logp("could not lstat %s\n", oldpath);
return -1;
}
if(dpth_is_compressed(oldpath))
{
FILE *source=NULL;
FILE *dest=NULL;
//logp("inflating...\n");
if(!(dest=open_file(infpath, "wb")))
{
close_fp(&dest);
return -1;
}
if(!statp.st_size)
{
// Empty file - cannot inflate.
// just close the destination and we have duplicated a
// zero length file.
logp("asked to inflate zero length file: %s\n", oldpath);
close_fp(&dest);
return 0;
}
if(!(source=open_file(oldpath, "rb")))
{
close_fp(&dest);
return -1;
}
if((ret=zlib_inflate(source, dest))!=Z_OK)
logp("zlib_inflate returned: %d\n", ret);
close_fp(&source);
close_fp(&dest);
}
else
{
// Not compressed - just hard link it.
if(link(oldpath, infpath))
{
logp("hardlink %s to %s failed: %s\n",
infpath, oldpath, strerror(errno));
ret=-1;
}
}
return ret;
}
示例7: make_rev_delta
static int make_rev_delta(const char *src, const char *sig, const char *del,
int compression, struct conf *cconf)
{
int ret=-1;
FILE *srcfp=NULL;
FILE *delfp=NULL;
FILE *sigp=NULL;
gzFile srczp=NULL;
gzFile delzp=NULL;
rs_signature_t *sumset=NULL;
//logp("make rev delta: %s %s %s\n", src, sig, del);
if(!(sigp=open_file(sig, "rb"))) goto end;
if(rs_loadsig_file(sigp, &sumset, NULL)!=RS_DONE
|| rs_build_hash_table(sumset)!=RS_DONE)
goto end;
//logp("make rev deltb: %s %s %s\n", src, sig, del);
if(dpthl_is_compressed(compression, src))
srczp=gzopen_file(src, "rb");
else
srcfp=open_file(src, "rb");
if(!srczp && !srcfp) goto end;
if(cconf->compression)
delzp=gzopen_file(del, comp_level(cconf));
else
delfp=open_file(del, "wb");
if(!delzp && !delfp) goto end;
if(rs_delta_gzfile(NULL, sumset, srcfp, srczp,
delfp, delzp, NULL, cconf->cntr)!=RS_DONE)
goto end;
ret=0;
end:
if(sumset) rs_free_sumset(sumset);
gzclose_fp(&srczp);
close_fp(&srcfp);
close_fp(&sigp);
if(gzclose_fp(&delzp))
{
logp("error closing zp %s in %s\n", del, __func__);
ret=-1;
}
if(close_fp(&delfp))
{
logp("error closing fp %s in %s\n", del, __func__);
ret=-1;
}
return ret;
}
示例8: do_patch
// Also used by backup_phase4_server.c
int do_patch(const char *dst, const char *del, const char *upd, bool gzupd, struct cntr *cntr, struct config *cconf)
{
FILE *dstp=NULL;
FILE *delfp=NULL;
gzFile delzp=NULL;
gzFile updp=NULL;
FILE *updfp=NULL;
rs_result result;
//logp("patching...\n");
if(!(dstp=fopen(dst, "rb")))
{
logp("could not open %s for reading\n", dst);
return -1;
}
if(dpth_is_compressed(del))
delzp=gzopen(del, "rb");
else
delfp=fopen(del, "rb");
if(!delzp && !delfp)
{
logp("could not open %s for reading\n", del);
close_fp(&dstp);
return -1;
}
if(gzupd)
updp=gzopen(upd, comp_level(cconf));
else
updfp=fopen(upd, "wb");
if(!updp && !updfp)
{
logp("could not open %s for writing\n", upd);
close_fp(&dstp);
gzclose_fp(&delzp);
close_fp(&delfp);
return -1;
}
result=rs_patch_gzfile(dstp, delfp, delzp, updfp, updp, NULL, cntr);
fclose(dstp);
gzclose_fp(&delzp);
close_fp(&delfp);
if(updp) gzclose_fp(&updp);
if(updfp) fclose(updfp);
return result;
}
示例9: manio_read_fcount
int manio_read_fcount(struct manio *manio)
{
int ret=-1;
size_t s;
FILE *fp=NULL;
char *path=NULL;
char buf[16]="";
if(!(path=get_fcount_path(manio))
|| !(fp=open_file(path, "rb")))
goto end;
if(!fgets(buf, sizeof(buf), fp))
{
logp("fgets on %s failed\n", path);
goto end;
}
s=strlen(buf);
if(s!=9)
{
logp("data in %s is not the right length (%s!=9)\n", s);
goto end;
}
manio->offset.fcount=strtoul(buf, NULL, 16);
ret=0;
end:
close_fp(&fp);
free_w(&path);
return ret;
}
示例10: incexc_matches
static int incexc_matches(const char *fullrealwork, const char *incexc)
{
int ret=0;
int got=0;
FILE *fp=NULL;
char buf[4096]="";
const char *inc=NULL;
char *old_incexc_path=NULL;
if(!(old_incexc_path=prepend_s(fullrealwork, "incexc")))
return -1;
if(!(fp=open_file(old_incexc_path, "rb")))
{
// Assume that no incexc file could be found because the client
// was on an old version. Assume resume is OK and return 1.
ret=1;
goto end;
}
inc=incexc;
while((got=fread(buf, 1, sizeof(buf), fp))>0)
{
if(strlen(inc)<(size_t)got) break;
if(strncmp(buf, inc, got)) break;
inc+=got;
}
if(inc && strlen(inc)) ret=0;
else ret=1;
end:
close_fp(&fp);
free(old_incexc_path);
return ret;
}
示例11: zlib_inflate
int zlib_inflate(struct asfd *asfd, const char *source,
const char *dest, struct conf *conf)
{
int ret=-1;
size_t b=0;
FILE *fp=NULL;
gzFile zp=NULL;
unsigned char in[ZCHUNK];
if(!(zp=gzopen_file(source, "rb")))
{
logw(asfd, conf, "could not open %s in %s\n", source, __func__);
goto end;
}
if(!(fp=open_file(dest, "wb")))
{
logw(asfd, conf, "could not open %s in %s: %s\n",
dest, __func__, strerror(errno));
goto end;
}
while((b=gzread(zp, in, ZCHUNK))>0)
{
if(fwrite(in, 1, b, fp)!=b)
{
logw(asfd, conf, "error when writing to %s\n", dest);
goto end;
}
}
if(!gzeof(zp))
{
logw(asfd, conf,
"error while gzreading %s in %s\n", source, __func__);
goto end;
}
if(close_fp(&fp))
{
logw(asfd, conf,
"error when closing %s in %s: %s\n",
dest, __func__, strerror(errno));
goto end;
}
ret=0;
end:
gzclose_fp(&zp);
close_fp(&fp);
return ret;
}
示例12: do_patch
// Also used by restore.c.
// FIX THIS: This stuff is very similar to make_rev_delta, can maybe share
// some code.
int do_patch(struct asfd *asfd, const char *dst, const char *del,
const char *upd, bool gzupd, int compression, struct conf *cconf)
{
FILE *dstp=NULL;
FILE *delfp=NULL;
gzFile delzp=NULL;
gzFile updp=NULL;
FILE *updfp=NULL;
rs_result result=RS_IO_ERROR;
//logp("patching...\n");
if(!(dstp=open_file(dst, "rb"))) goto end;
if(dpthl_is_compressed(compression, del))
delzp=gzopen_file(del, "rb");
else
delfp=open_file(del, "rb");
if(!delzp && !delfp) goto end;
if(gzupd)
updp=gzopen(upd, comp_level(cconf));
else
updfp=fopen(upd, "wb");
if(!updp && !updfp) goto end;
result=rs_patch_gzfile(asfd,
dstp, delfp, delzp, updfp, updp, NULL, cconf->cntr);
end:
close_fp(&dstp);
gzclose_fp(&delzp);
close_fp(&delfp);
if(close_fp(&updfp))
{
logp("error closing %s in %s\n", upd, __func__);
result=RS_IO_ERROR;
}
if(gzclose_fp(&updp))
{
logp("error gzclosing %s in %s\n", upd, __func__);
result=RS_IO_ERROR;
}
return result;
}
示例13: close_file_for_send
int close_file_for_send(BFILE *bfd, FILE **fp)
{
if(fp) return close_fp(fp);
#ifdef HAVE_WIN32
if(bfd) return bclose(bfd);
#endif
return -1;
}
示例14: nfs_put_super
void nfs_put_super(struct super_block *sb)
{
/* No locks should be open on this, so 0 should be safe as a fd. */
close_fp(sb->u.nfs_sb.s_server.file, 0);
lock_super(sb);
sb->s_dev = 0;
unlock_super(sb);
}
示例15: dpth_release_all
int dpth_release_all(struct dpth *dpth)
{
int ret=0;
if(!dpth) return 0;
if(dpth->fp && close_fp(&dpth->fp)) ret=-1;
while(dpth->head) if(release_and_move_to_next_in_list(dpth)) ret=-1;
return ret;
}