本文整理汇总了C++中closefile函数的典型用法代码示例。如果您正苦于以下问题:C++ closefile函数的具体用法?C++ closefile怎么用?C++ closefile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了closefile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: walkfile1
static File*
walkfile1(File *dir, char *elem)
{
File *fp;
Filelist *fl;
rlock(&dir->RWLock);
if(strcmp(elem, "..") == 0){
fp = dir->parent;
incref(&fp->Ref);
runlock(&dir->RWLock);
closefile(dir);
return fp;
}
fp = nil;
for(fl=dir->filelist; fl; fl=fl->link)
if(fl->f && strcmp(fl->f->Dir.name, elem)==0){
fp = fl->f;
incref(&fp->Ref);
break;
}
runlock(&dir->RWLock);
closefile(dir);
return fp;
}
示例2: main
/**
* Main execution of the program. Function calls
* to load data from file, calculation of maximum flow
* and to save result answer to a file
*/
int main(int argc, char *argv[])
{
/* Corrects terminal output buffer */
setvbuf(stderr, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
/* Parse main arguments */
char input[ARGS_BUFFER_SIZE], output[ARGS_BUFFER_SIZE];
arg_parser(argc, argv, input, output);
#ifdef MYDEBUG
printf("input: %s output: %s\n", input, output);
#endif
/* Import input file */
FILE *inpfile = openfile(input, READ_MODE);
/* Loads data from file */
Champ champ;
load(inpfile, &champ);
closefile(inpfile);
/* output file that will store the results */
FILE *outfile = openfile(output, WRITE_MODE);
/* Calculate the maximum flow on the graph */
maximum_flow(&champ, outfile);
closefile(outfile);
return EXIT_SUCCESS;
}
示例3: dbopenverb
static boolean dbopenverb (hdltreenode hparam1, tyvaluerecord *vreturned) {
//
// 2006-06-20 creedon: for Mac, extend filespec
//
// 4.1b5 dmb: added ability to access already-open root in Frontier
//
tyodbrecord odbrec;
hdlodbrecord hodb;
WindowPtr w;
odbrec.fref = 0;
if ( ! getfilespecvalue ( hparam1, 1, &odbrec.fs ) )
return (false);
flnextparamislast = true;
if (!getbooleanvalue (hparam1, 2, &odbrec.flreadonly))
return (false);
w = shellfindfilewindow ( &odbrec.fs );
if (w != nil) {
if (odberror (odbaccesswindow (w, &odbrec.odb)))
return (false);
// fref remains zero, so unwanted closefiles aren't a problem
}
else {
if ( ! openfile ( &odbrec.fs, &odbrec.fref, odbrec.flreadonly))
return (false);
if (odberror (odbopenfile (odbrec.fref, &odbrec.odb, odbrec.flreadonly))) {
closefile (odbrec.fref);
return (false);
}
}
if (!newfilledhandle (&odbrec, sizeof (odbrec), (Handle *) &hodb)) {
odbclosefile (odbrec.odb);
closefile (odbrec.fref);
return (false);
}
listlink ((hdllinkedlist) hodblist, (hdllinkedlist) hodb);
return (setbooleanvalue (true, vreturned));
} // dbopenverb
示例4: Write_Displ
void
Write_Displ( int* pid,
int* stepno,
int* nshg,
int* numVars,
double* array1 ) { //TO BE UPDATED FOR SYNCIO
char fname[255];
char rfile[60];
int irstou;
int magic_number = 362436;
int* mptr = &magic_number;
time_t timenow = time ( &timenow);
double version=0.0;
int isize, nitems;
int iarray[10];
sprintf(rfile,"restart.%d.%d",*stepno,*pid+1);
openfile(rfile,"append", &irstou);
isize = (*nshg)*(*numVars);
nitems = 3;
iarray[ 0 ] = (*nshg);
iarray[ 1 ] = (*numVars);
iarray[ 2 ] = (*stepno);
writeheader( &irstou, "displacement", (void*)iarray, &nitems, &isize, "double", phasta_iotype );
writedatablock( &irstou, "displacement", (void*)(array1), &isize, "double", phasta_iotype );
closefile( &irstou, "append" );
}
示例5: main
int main(int argc,char** argv)
{
int rv = 0;
FILE *f = NULL;
Initialize();
if ( argc > 1)
{
if( strcmp(argv[1],"--help")==0 || strcmp(argv[1],"-H")==0 )
{
printf("Use: %s [rtf_filename]\n",argv[0]);
rv = 0;
} else if ( strcmp(argv[1],"--version")==0 || strcmp(argv[1],"-V")==0 ) {
printf("rtf2html version 1.2\n");
rv = 0;
}
else
{
rv = openfile(argv[1], &f);
if ( rv ) rv = RTF_FindCharset(f);
if ( rv )
{
rewind(f);
rv = RTF_Parse(f);
}
if ( rv ) rv = closefile(f);
}
}
else
{
printf("Use: %s [rtf_filename]\n",argv[0]);
}
return rv;
}
示例6: player_play
/*
* Loads url and starts playback.
* On success returns 0, on failure -1.
*/
int
player_play(const char *url)
{
if (state != STOPPED)
player_stop();
if (openfile(url) < 0)
return -1;
if (openaudio() < 0) {
closefile();
return -1;
}
flinit(); /* initialize the framelist */
/*
* Create two threads: one for reading and decoding the url,
* the other one for cleaning up after the track has finished or
* after an abort signal.
*/
pthread_create(&decodetid, NULL, decodethread, NULL);
pthread_create(&watchtid, NULL, watchthread, NULL);
pthread_detach(watchtid);
SDL_PauseAudio(0); /* start playback (1 = Pause, 0 = Play) */
state = PLAYING;
return 0;
}
示例7: io_writeto
static void io_writeto() {
lua_Object f = lua_getparam(FIRSTARG);
if (f == LUA_NOOBJECT) {
closefile(FOUTPUT);
setreturn(2, FOUTPUT);
} else if (lua_tag(f) == gettag(IOTAG)) {
int32 id = lua_getuserdata(f);
LuaFile *current = getfile(id);
if (!current->isOpen()) {
pushresult(0);
return;
}
setreturn(id, FOUTPUT);
} else {
Common::String s = Common::lastPathComponent(luaL_check_string(FIRSTARG), '\\');
LuaFile *current;
Common::WriteStream *outFile = NULL;
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
outFile = saveFileMan->openForSaving(s);
if (!outFile) {
pushresult(0);
return;
}
current = new LuaFile();
current->_out = outFile;
current->_filename = s;
setreturn(addfile(current), FOUTPUT);
}
}
示例8: fatal
static void
fatal(char *string, char *arg)
{
char *fls;
int num;
(void) fprintf(stderr, "csplit: ");
/* gettext dynamically replaces string */
(void) fprintf(stderr, gettext(string), arg);
if (!keep) {
if (outfile) {
(void) fclose(outfile);
for (fls = file; *fls != '\0'; fls++)
continue;
fls -= fiwidth;
for (num = atoi(fls); num >= 0; num--) {
(void) sprintf(fls, "%.*d", fiwidth, num);
(void) unlink(file);
}
}
} else
if (outfile)
closefile();
exit(1);
}
示例9: io_readfrom
static void io_readfrom() {
lua_Object f = lua_getparam(FIRSTARG);
if (f == LUA_NOOBJECT) {
closefile(FINPUT);
setreturn(1, FINPUT);
} else if (lua_tag(f) == gettag(IOTAG)) {
int32 id = lua_getuserdata(f);
LuaFile *current = getfile(id);
if (!current) {
pushresult(0);
return;
}
setreturn(id, FINPUT);
} else {
const char *s = luaL_check_string(FIRSTARG);
LuaFile *current;
Common::SeekableReadStream *inFile = NULL;
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
inFile = saveFileMan->openForLoading(s);
if (!inFile)
current = g_resourceloader->openNewStreamLuaFile(s);
else {
current = new LuaFile();
current->_in = inFile;
current->_filename = s;
}
if (!current) {
delete current;
pushresult(0);
} else {
setreturn(addfile(current), FINPUT);
}
}
}
示例10: fscreate
static void
fscreate(Req* r)
{
File* file;
Query* q;
char* name;
char* uid;
int mode;
File* f;
file = r->fid->file;
name = r->ifcall.name;
uid = r->fid->uid;
mode = r->fid->file->dir.mode & 0x777 & r->ifcall.perm;
mode |= (r->ifcall.perm & ~0x777);
if(mode&DMDIR){
respond(r, "queries cannot be directories");
return;
}
if(f = createfile(file, name, uid, mode, nil)){
q = emalloc9p(sizeof *q);
q->text = estrdup9p("");
q->expr = nil;
f->aux = q;
closefile(r->fid->file);
r->fid->file = f;
r->ofcall.qid = f->dir.qid;
respond(r, nil);
} else
respond(r, "problem creating file");
}
示例11: createDebuggerFile
const char* createDebuggerFile(const char* debugger, int argc, char* argv[]) {
const char* dbgfilename = genIntermediateFilename(astr(debugger, ".commands"));
FILE* dbgfile = openfile(dbgfilename);
int i;
if (strcmp(debugger, "gdb") == 0) {
fprintf(dbgfile, "set args");
} else if (strcmp(debugger, "lldb") == 0) {
fprintf(dbgfile, "settings set -- target.run-args");
} else {
INT_FATAL(astr("createDebuggerFile doesn't know how to handle the given "
"debugger: '", debugger, "'"));
}
for (i=1; i<argc; i++) {
if (strcmp(argv[i], astr("--", debugger)) != 0) {
fprintf(dbgfile, " %s", argv[i]);
}
}
fprintf(dbgfile, "\n");
closefile(dbgfile);
mysystem(astr("cat ", CHPL_HOME, "/compiler/etc/", debugger, ".commands >> ",
dbgfilename),
astr("appending ", debugger, " commands"),
false);
return dbgfilename;
}
示例12: storetofile
/*
* Open the file with @param path and wirte @param sz byte of data starting from @param buf into the file
* @param path the path of the file to open and write
* @param buf the starting address of the data to write into file
* @param sz how many bytes to write at most
* @return the byte we've written, or Linux specific error code
*/
static int storetofile(char *path, u8 __user *buf, u32 sz)
{
int ret = 0;
mm_segment_t oldfs;
struct file *fp;
if (path && buf) {
ret = openfile(&fp, path, O_CREAT|O_WRONLY, 0666);
if (0 == ret) {
DBG_88E("%s openfile path:%s fp =%p\n", __func__, path, fp);
oldfs = get_fs(); set_fs(get_ds());
ret = writefile(fp, buf, sz);
set_fs(oldfs);
closefile(fp);
DBG_88E("%s writefile, ret:%d\n", __func__, ret);
} else {
DBG_88E("%s openfile path:%s Fail, ret:%d\n", __func__, path, ret);
}
} else {
DBG_88E("%s NULL pointer\n", __func__);
ret = -EINVAL;
}
return ret;
}
示例13: closefile
Interface::~Interface()
{
//将修改后的信息保存进文件中,关闭文件
ofstream closefile("database.txt",ios::out);
closefile << "账号 " <<"密码"<< endl;
data->inOrder(closefile);
closefile.close();
}
示例14: export_delim
// fname indica la ruta y denominación del archivo
void export_delim(char * fname, char coldelim, int r0, int c0, int rn, int cn) {
FILE *f;
int row, col;
register struct ent **pp;
int pid;
info("Writing file \"%s\"...", fname);
if ((f = openfile(fname, &pid, NULL)) == (FILE *)0) {
error ("Can't create file \"%s\"", fname);
return;
}
struct ent * ent = go_end();
if (rn > ent->row) rn = ent->row;
//if (cn > ent->col) cn = ent->col;
for (row = r0; row <= rn; row++) {
for (pp = ATBL(tbl, row, col = c0); col <= cn; col++, pp++) {
if (*pp) {
char * s;
if ((*pp)->flags & is_valid) {
if ((*pp)->cellerror) {
(void) fprintf (f, "%*s", fwidth[col], ((*pp)->cellerror == CELLERROR ? "ERROR" : "INVALID"));
} else if ((*pp)->format) {
char field[FBUFLEN];
if (*((*pp)->format) == 'd') { // formato fecha
time_t v = (time_t) ((*pp)->v);
strftime(field, sizeof(field), ((*pp)->format)+1, localtime(&v));
} else { // formato numerico
format((*pp)->format, precision[col], (*pp)->v, field, sizeof(field));
}
ltrim(field, ' ');
unspecial(f, field, coldelim);
} else { //eng number format
char field[FBUFLEN] = "";
(void) engformat(realfmt[col], fwidth[col], precision[col], (*pp)->v, field, sizeof(field));
ltrim(field, ' ');
unspecial(f, field, coldelim);
}
}
if ((s = (*pp)->label)) {
ltrim(s, ' ');
unspecial(f, s, coldelim);
}
}
if (col < cn)
(void) fprintf(f,"%c", coldelim);
}
(void) fprintf(f,"\n");
}
closefile(f, pid, 0);
if (! pid) {
info("File \"%s\" written", fname);
}
}
示例15: format
/*
the symbol table is loaded from 'nm' output
All platforms have their own 'nm' output format, but luckily some
support POSIX format (although often poorly supported).
POSIX.2 format is <symbol> <type> <address> [<size>]
The symbol apperently may be empty on some systems
The address may be empty, when type is 'U'
The size is optional
*/
int load_SymbolTable(char *filename) {
AtomicFile *f;
char buf[MAX_LONGLINE], namebuf[MAX_LONGLINE], type;
unsigned long addr;
SymbolTable *st;
listdestroy_SymbolTable(symbol_table);
symbol_table = NULL;
if ((f = openfile(filename, "r")) == NULL)
return 1;
while(fgets(buf, MAX_LONGLINE, f->f) != NULL) {
cstrip_line(buf);
if (!*buf)
continue;
addr = 0UL;
type = '#';
cstrcpy(namebuf, "<unknown>", MAX_LONGLINE);
if (*buf == ' ')
sscanf(buf, " %c %lx", &type, &addr);
else
sscanf(buf, "%s %c %lx", namebuf, &type, &addr);
if ((st = new_SymbolTable()) == NULL) {
closefile(f);
listdestroy_SymbolTable(symbol_table);
symbol_table = NULL;
return -1;
}
st->name = cstrdup(namebuf);
st->type = type;
st->addr = addr;
symbol_table = add_SymbolTable(&symbol_table, st);
}
closefile(f);
symbol_table = rewind_SymbolTable(symbol_table);
return 0;
}