本文整理汇总了C++中setfile函数的典型用法代码示例。如果您正苦于以下问题:C++ setfile函数的具体用法?C++ setfile怎么用?C++ setfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setfile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: openwithcontrol
static void openwithcontrol (lua_State *L) {
IOCtrl *ctrl = (IOCtrl *)lua_newuserdata(L, sizeof(IOCtrl));
unsigned int i;
ctrl->iotag = lua_newtag(L);
ctrl->closedtag = lua_newtag(L);
for (i=0; i<sizeof(iolibtag)/sizeof(iolibtag[0]); i++) {
/* put `ctrl' as upvalue for these functions */
lua_pushvalue(L, -1);
lua_pushcclosure(L, iolibtag[i].func, 1);
lua_setglobal(L, iolibtag[i].name);
}
/* create references to variable names */
lua_pushstring(L, filenames[INFILE]);
ctrl->ref[INFILE] = lua_ref(L, 1);
lua_pushstring(L, filenames[OUTFILE]);
ctrl->ref[OUTFILE] = lua_ref(L, 1);
/* predefined file handles */
setfile(L, ctrl, stdin, INFILE);
setfile(L, ctrl, stdout, OUTFILE);
setfilebyname(L, ctrl, stdin, "_STDIN");
setfilebyname(L, ctrl, stdout, "_STDOUT");
setfilebyname(L, ctrl, stderr, "_STDERR");
/* close files when collected */
lua_pushcclosure(L, file_collect, 1); /* pops `ctrl' from stack */
lua_settagmethod(L, ctrl->iotag, "gc");
}
示例2: openwithtags
static void openwithtags() {
int32 iotag = lua_newtag();
int32 closedtag = lua_newtag();
uint32 i;
for (i = 0; i < sizeof(iolibtag) / sizeof(iolibtag[0]); i++) {
// put both tags as upvalues for these functions
lua_pushnumber(iotag);
lua_pushnumber(closedtag);
lua_pushCclosure(iolibtag[i].func, 2);
lua_setglobal(iolibtag[i].name);
}
g_fin = new LuaFile();
g_fin->_stdin = true;
setfile(addfile(g_fin), FINPUT, iotag);
g_fout = new LuaFile();
g_fout->_stdout = true;
setfile(addfile(g_fout), FOUTPUT, iotag);
g_stdin = new LuaFile();
g_stdin->_stdin = true;
setfile(addfile(g_stdin), "_STDIN", iotag);
g_stdout = new LuaFile();
g_stdout->_stdout = true;
setfile(addfile(g_stdout), "_STDOUT", iotag);
g_stderr = new LuaFile();
g_stderr->_stderr = true;
setfile(addfile(g_stderr), "_STDERR", iotag);
}
示例3: copy_directory
/**
* copy a directory between branches (includes all contents of the directory)
*/
int copy_directory(const char *path, int branch_ro, int branch_rw) {
DBG("%s\n", path);
/* create the directory on the destination branch */
int res = path_create(path, branch_ro, branch_rw);
if (res != 0) {
RETURN(res);
}
/* determine path to source directory on read-only branch */
char from[PATHLEN_MAX];
if (BUILD_PATH(from, uopt.branches[branch_ro].path, path)) RETURN(1);
DIR *dp = opendir(from);
if (dp == NULL) RETURN(1);
struct dirent *de;
while ((de = readdir(dp)) != NULL) {
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
char member[PATHLEN_MAX];
if (BUILD_PATH(member, path, "/", de->d_name)) {
res = 1;
break;
}
res = cow_cp(member, branch_ro, branch_rw, true);
if (res != 0) break;
}
closedir(dp);
struct stat buf;
lstat(from, &buf);
setfile(from, &buf);
RETURN(res);
}
示例4: Prim_PCLOSE
/******************************************************************************
* Prim_PCLOSE - close a pipe opened by Prim_POPEN().
* (code stolen from xlfio.c:xclose())
*
* syntax: (pclose <stream>)
* <stream> is a stream created by popen.
* returns T if the command executed successfully, otherwise,
* returns the exit status of the opened command.
*
* Added to XLISP by Niels Mayer
******************************************************************************/
LVAL Prim_PCLOSE()
{
extern LVAL true;
LVAL fptr;
int result;
/* get file pointer */
fptr = xlgastream();
xllastarg();
/* make sure the file exists */
if (getfile(fptr) == NULL)
xlfail("file not open");
/* close the pipe */
result = pclose(getfile(fptr));
if (result == -1)
xlfail("<stream> has not been opened with popen");
setfile(fptr,NULL);
/* return T if success (exit status 0), else return exit status */
return (result ? cvfixnum(result) : true);
}
示例5: null_close
int
null_close(void *cookie, struct z_info *info, const char *name, struct stat *sb)
{
null_stream *s = (null_stream*) cookie;
int err = 0;
if (s == NULL)
return -1;
if (info != NULL) {
info->mtime = 0;
info->crc = (u_int32_t)-1;
info->hlen = 0;
info->total_in = (off_t) s->total_in;
info->total_out = (off_t) s->total_out;
}
setfile(name, s->fd, sb);
err = close(s->fd);
free(s);
return err;
}
示例6: copy_link
int
copy_link(const FTSENT *p, int exists)
{
int len;
char llink[PATH_MAX];
if (exists && nflag) {
if (vflag)
printf("%s not overwritten\n", to.p_path);
return (1);
}
if ((len = readlink(p->fts_path, llink, sizeof(llink) - 1)) == -1) {
warn("readlink: %s", p->fts_path);
return (1);
}
llink[len] = '\0';
if (exists && unlink(to.p_path)) {
warn("unlink: %s", to.p_path);
return (1);
}
if (symlink(llink, to.p_path)) {
warn("symlink: %s", llink);
return (1);
}
return (pflag ? setfile(p->fts_statp, -1) : 0);
}
示例7: outputfile
void outputfile(char *buf, char *orgbuf, char *ext)
{
if (has_output_file)
AddExt(buf, ext);
else
setfile(buf, orgbuf, ext);
}
示例8: copy_special
/**
* copy a special file, actually we recreate this file and only copy
* its stat() data
*/
int copy_special(struct cow *cow)
{
if (mknod(cow->to_path, cow->stat->st_mode, cow->stat->st_rdev)) {
syslog(LOG_WARNING, "mknod: %s", cow->to_path);
return (1);
}
return setfile(cow->to_path, cow->stat);
}
示例9: copy_fifo
/**
* copy a fifo, actually we recreate the fifo and only copy
* its stat() data
**/
int copy_fifo(struct cow *cow)
{
if (mkfifo(cow->to_path, cow->stat->st_mode)) {
syslog(LOG_WARNING, "mkfifo: %s", cow->to_path);
return (1);
}
return setfile(cow->to_path, cow->stat);
}
示例10: cvfile
/* cvfile - convert a file pointer to a stream */
LVAL cvfile(FILE *fp)
{
LVAL val;
val = newnode(STREAM);
setfile(val,fp);
setsavech(val,'\0');
return (val);
}
示例11: newnode
/* cvfile - convert a file pointer to a file */
NODE *cvfile( FILE *fp)
{
NODE *val;
val = newnode(FPTR);
setfile(val,fp);
setsavech(val,0);
return (val);
}
示例12: setreturn
static int setreturn (lua_State *L, IOCtrl *ctrl, FILE *f, int inout) {
if (f == NULL)
return pushresult(L, 0);
else {
setfile(L, ctrl, f, inout);
lua_pushusertag(L, f, ctrl->iotag);
return 1;
}
}
示例13: openwithtags
static void openwithtags (void)
{
int iotag = lua_newtag();
int closedtag = lua_newtag();
int i;
for (i=0; i<sizeof(iolibtag)/sizeof(iolibtag[0]); i++) {
/* put both tags as upvalues for these functions */
lua_pushnumber(iotag);
lua_pushnumber(closedtag);
lua_pushCclosure(iolibtag[i].func, 2);
lua_setglobal(iolibtag[i].name);
}
setfile(stdin, FINPUT, iotag);
setfile(stdout, FOUTPUT, iotag);
setfile(stdin, "_STDIN", iotag);
setfile(stdout, "_STDOUT", iotag);
setfile(stderr, "_STDERR", iotag);
}
示例14: file
/*
* Change to another file. With no argument, print information about
* the current file.
*/
int
file(char **argv)
{
if (argv[0] == NULL) {
newfileinfo(0);
return (0);
}
if (setfile(*argv) < 0)
return (1);
announce();
return (0);
}
示例15: copy_ro_rw_stat
/**
*
* Sets a file/dir stat to it's original in the RO branch
* path: relative path to the file/dir
* nbranch_ro: number of the branch used as ro
* nbranch_rw: number of the branch used as rw
*/
int copy_ro_rw_stat(char * path, int nbranch_ro, int nbranch_rw)
{
if (nbranch_ro == nbranch_rw) RETURN(0); // same file -> nothing to do here
char ro_dir_path[PATHLEN_MAX]; // original dir path
char rw_dir_path[PATHLEN_MAX]; // dir path to create
sprintf(ro_dir_path, "%s%s", uopt.branches[nbranch_ro].path, path);
struct stat buf;
if (stat(ro_dir_path, &buf) == -1) RETURN(1);
sprintf(rw_dir_path, "%s%s", uopt.branches[nbranch_rw].path, path);
if (setfile(rw_dir_path, &buf)) RETURN(1); // directory already removed by another process?
RETURN(0);
}