本文整理汇总了C++中sfopen函数的典型用法代码示例。如果您正苦于以下问题:C++ sfopen函数的具体用法?C++ sfopen怎么用?C++ sfopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sfopen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MAIN
MAIN()
{
Sfio_t* f;
Sfio_t sf;
if(sfopen(sfstdout,"abc","s") != sfstdout)
terror("Bad reopening of sfstdout\n");
if(sfopen(sfstdin,"123","s") != sfstdin)
terror("Bad reopening of sfstdin\n");
sfclose(sfstdin);
if(!(f = sfopen(NIL(Sfio_t*),"123","s")) )
terror("Opening a stream\n");
sfclose(f);
if(sfopen(f,"123","s") != NIL(Sfio_t*))
terror("can't reopen a closed stream!\n");
if(sfnew(&sf,NIL(char*),(size_t)SF_UNBOUND,0,SF_EOF|SF_READ) != &sf)
terror("Did not open sf\n");
sfset(&sf,SF_STATIC,1);
if(sfclose(&sf) < 0 || !(sfset(&sf,0,0)&SF_STATIC))
terror("Did not close sf\n");
/* test for exclusive opens */
unlink(tstfile(0));
if(!(f = sfopen(NIL(Sfio_t*),tstfile(0),"wx") ) )
terror("sfopen failed\n");
if((f = sfopen(f,tstfile(0),"wx") ) )
terror("sfopen should not succeed here\n");
TSTEXIT(0);
}
示例2: tmain
tmain()
{
Sfio_t* f;
Sfio_t sf;
if(sfopen(sfstdout,"abc","s") != sfstdout)
terror("Bad reopening of sfstdout");
if(sfopen(sfstdin,"123","s") != sfstdin)
terror("Bad reopening of sfstdin");
sfclose(sfstdin);
if(!(f = sfopen(NIL(Sfio_t*),"123","s")) )
terror("Opening a stream");
sfclose(f);
if(sfopen(f,"123","s") != NIL(Sfio_t*))
terror("can't reopen a closed stream!");
if(sfnew(&sf,NIL(char*),(size_t)SF_UNBOUND,0,SF_EOF|SF_READ) != &sf)
terror("Did not open sf");
sfset(&sf,SF_STATIC,1);
if(!sfclose(&sf) || errno != EBADF)
terror("sfclose(sf) should fail with EBADF");
if(!(sfset(&sf,0,0)&SF_STATIC))
terror("Did not close sf");
/* test for exclusive opens */
unlink(tstfile("sf", 0));
if(!(f = sfopen(NIL(Sfio_t*),tstfile("sf", 0),"wx") ) )
terror("sfopen failed");
if((f = sfopen(f,tstfile("sf", 0),"wx") ) )
terror("sfopen should not succeed here");
texit(0);
}
示例3: b_comm
int
b_comm(int argc, char *argv[], Shbltin_t* context)
{
register int mode = C_FILE1|C_FILE2|C_COMMON;
register char *cp;
Sfio_t *f1, *f2;
cmdinit(argc, argv, context, ERROR_CATALOG, 0);
for (;;)
{
switch (optget(argv, usage))
{
case '1':
mode &= ~C_FILE1;
continue;
case '2':
mode &= ~C_FILE2;
continue;
case '3':
mode &= ~C_COMMON;
continue;
case ':':
error(2, "%s",opt_info.arg);
break;
case '?':
error(ERROR_usage(2), "%s",opt_info.arg);
break;
}
break;
}
argv += opt_info.index;
argc -= opt_info.index;
if(error_info.errors || argc!=2)
error(ERROR_usage(2),"%s",optusage(NiL));
cp = *argv++;
if(streq(cp,"-"))
f1 = sfstdin;
else if(!(f1 = sfopen(NiL, cp,"r")))
error(ERROR_system(1),"%s: cannot open",cp);
cp = *argv;
if(streq(cp,"-"))
f2 = sfstdin;
else if(!(f2 = sfopen(NiL, cp,"r")))
error(ERROR_system(1),"%s: cannot open",cp);
if(mode)
{
if(comm(f1,f2,sfstdout,mode) < 0)
error(ERROR_system(1)," write error");
}
else if(f1==sfstdin || f2==sfstdin)
sfseek(sfstdin,(Sfoff_t)0,SEEK_END);
if(f1!=sfstdin)
sfclose(f1);
if(f2!=sfstdin)
sfclose(f2);
return error_info.errors;
}
示例4: MAIN
MAIN()
{
char *s = "1234567890\n";
Sfoff_t n, i;
Sfio_t *f;
char buf[1024];
char* addr;
if(sfopen(sfstdout,tstfile(0),"w+") != sfstdout)
terror("Opening output file\n");
for(i = 0; i < 10000; ++i)
if(sfputr(sfstdout,s,-1) < 0)
terror("Writing data\n");
if(!(f = sfopen((Sfio_t*)0,tstfile(1),"w")))
terror("Opening output file \n");
sfseek(sfstdout,(Sfoff_t)0,0);
if((n = sfmove(sfstdout,f,(Sfoff_t)SF_UNBOUND,'\n')) != i)
terror("Move %d lines, Expect %d\n",n,i);
sfseek(sfstdout,(Sfoff_t)0,0);
sfseek(f,(Sfoff_t)0,0);
sfsetbuf(sfstdout,buf,sizeof(buf));
if((n = sfmove(sfstdout,f,(Sfoff_t)SF_UNBOUND,'\n')) != i)
terror("Move %d lines, Expect %d\n",n,i);
sfopen(sfstdin,tstfile(0),"r");
sfopen(sfstdout,tstfile(1),"w");
sfmove(sfstdin,sfstdout,(Sfoff_t)SF_UNBOUND,-1);
if(!sfeof(sfstdin))
terror("Sfstdin is not eof\n");
if(sferror(sfstdin))
terror("Sfstdin is in error\n");
if(sferror(sfstdout))
terror("Sfstdout is in error\n");
sfseek(sfstdin,(Sfoff_t)0,0);
sfseek(sfstdout,(Sfoff_t)0,0);
sfsetbuf(sfstdin,buf,sizeof(buf));
addr = (char*)sbrk(0);
sfmove(sfstdin,sfstdout,(Sfoff_t)((unsigned long)(~0L)>>1),-1);
if((ssize_t)((char*)sbrk(0)-addr) > 256*1024)
terror("Too much space allocated in sfmove\n");
if(!sfeof(sfstdin))
terror("Sfstdin is not eof2\n");
if(sferror(sfstdin))
terror("Sfstdin is in error2\n");
if(sferror(sfstdout))
terror("Sfstdout is in error2\n");
TSTEXIT(0);
}
示例5: tmain
tmain() {
UNUSED(argc);
UNUSED(argv);
Sfio_t *f;
char *str, *alpha, *s;
char buf[128];
int n;
str = "0123456789";
alpha = "abcdefghijklmnop";
if (!(f = sfopen(NULL, alpha, "s"))) terror("Opening stream");
for (n = 9; n >= 0; --n) {
if (sfungetc(f, n + '0') != n + '0') terror("Ungetc");
}
if (!(s = sfreserve(f, SF_UNBOUND, 0)) || sfvalue(f) != 10) terror("Peek stream1");
if (strncmp(s, str, 10) != 0) terror("Bad data1");
if (!(s = sfreserve(f, SF_UNBOUND, 0)) || sfvalue(f) != (ssize_t)strlen(alpha)) {
terror("Peek stream2");
}
if (strncmp(s, alpha, strlen(alpha)) != 0) terror("Bad data2");
sfseek(f, (Sfoff_t)0, 0);
for (n = 9; n >= 0; --n) {
if (sfungetc(f, n + '0') != n + '0') terror("Ungetc2");
}
if (sfgetc(f) != '0') terror("Sfgetc");
sfseek(f, (Sfoff_t)0, 0);
if (!(s = sfreserve(f, SF_UNBOUND, 0)) || sfvalue(f) != (ssize_t)strlen(alpha)) {
terror("Peek stream3");
}
if (strncmp(s, alpha, strlen(alpha)) != 0) terror("Bad data2");
sfseek(f, (Sfoff_t)0, 0);
if (sfungetc(f, '0') != '0') terror("Ungetc3");
strcpy(buf, "0123456789\n");
if (!(f = sfopen(f, buf, "s+"))) terror("Reopening string");
if (sfungetc(f, '\n') != '\n') terror("Can't unget new-line2");
if (sfungetc(f, 'd') != 'd') terror("Can't unget d");
if (sfungetc(f, 'c') != 'c') terror("Can't unget c");
if (sfungetc(f, '\n') != '\n') terror("Can't unget new-line");
if (sfungetc(f, 'b') != 'b') terror("Can't unget b");
if (sfungetc(f, 'a') != 'a') terror("Can't unget a");
if (!(s = sfgetr(f, '\n', 1)) || strcmp(s, "ab") != 0) terror("Did not get ab");
if (!(s = sfgetr(f, '\n', 1)) || strcmp(s, "cd") != 0) terror("Did not get cd");
if (!(s = sfgetr(f, '\n', 1)) || strcmp(s, "0123456789") != 0) terror("Did not get 0123456789");
texit(0);
}
示例6: verify
static int
verify(char* path, char* old, char* processor, int must)
{
char* ns;
char* os;
int nz;
int oz;
int r;
Sfio_t* nf;
Sfio_t* of;
r = 0;
if (nf = sfopen(NiL, path, "r"))
{
if ((ns = sfgetr(nf, '\n', 1)) && (nz = sfvalue(nf) - 1) > 0)
{
ns += nz;
if ((oz = strlen(processor)) <= nz && !strcmp(processor, ns - oz))
r = 1;
else
error(2, "%s: %s clashes with %s", path, processor, ns - nz);
}
if (r && old && sfseek(nf, 0L, 0) == 0 && (of = sfopen(NiL, old, "r")))
{
for (;;)
{
ns = sfreserve(nf, 0, 0);
nz = sfvalue(nf);
os = sfreserve(of, 0, 0);
oz = sfvalue(nf);
if (nz <= 0 || oz <= 0)
break;
if (nz > oz)
nz = oz;
if (memcmp(ns, os, nz))
break;
nz = sfread(nf, ns, nz);
oz = sfread(of, os, nz);
if (!nz || !oz)
break;
}
sfclose(of);
if (!nz && !oz && !touch(old, (time_t)-1, (time_t)-1, 0))
r = 0;
}
sfclose(nf);
}
else if (must)
error(ERROR_SYSTEM|2, "%s: cannot read", path);
return r;
}
示例7: main
main()
{
if(sfopen(sfstdout,"xxx","w") != sfstdout)
terror("Can't open xxx to write\n");
if(sfputr(sfstdout,"012345678\n",-1) != 10)
terror("Can't write to xxx\n");
sfsync(sfstdout);
if(sfopen(sfstdout,"yyy","w") != sfstdout)
terror("Can't open yyy to write\n");
sfclose(sfstdout);
return 0;
}
示例8: loadnpanxx
static int loadnpanxx (char *file) {
Sfio_t *fp;
char *s, *line, *avs[10];
SUmessage (1, "loadnpanxx", "loading file %s", file);
if (!(fp = sfopen (NULL, file, "r"))) {
SUwarning (1, "loadnpanxx", "open failed for file %s", file);
return -1;
}
while ((line = sfgetr (fp, '\n', 1))) {
if (line[strlen (line) - 1] == '\r')
line[strlen (line) - 1] = 0;
if (tokscan (
line, &s, "%s:%s:%s:%s\n", &avs[0], &avs[1], &avs[2], &avs[3]
) != 4) {
SUwarning (1, "loadnpanxx", "bad line in file %s, %s", file, line);
continue;
}
if (additem (avs[0], avs[1], avs[2], avs[3]) == -1) {
SUwarning (1, "loadnpanxx", "additem failed");
return -1;
}
}
sfclose (fp);
return 0;
}
示例9: timerangesload
int timerangesload (char *file, int size) {
Sfio_t *fp;
char *line, *s1, *s2;
int trm;
trm = 0, trn = atoi (getenv ("TIMERANGESSIZE"));
if (trn > 0) {
if (!(trs = vmalloc (Vmheap, sizeof (timerange_t) * trn)))
SUerror ("vg_timeranges", "cannot allocate trs");
memset (trs, 0, sizeof (timerange_t) * trn);
if (!(fp = sfopen (NULL, getenv ("TIMERANGESFILE"), "r")))
SUerror ("vg_timeranges", "cannot open inv filter file");
while ((line = sfgetr (fp, '\n', 1))) {
if (!(s1 = strchr (line, '|'))) {
SUwarning (0, "vg_timeranges", "bad line: %s", line);
break;
}
*s1++ = 0;
trs[trm].ft = strtoll (line, &s2, 10);
trs[trm].lt = strtoll (s1, &s2, 10);
trm++;
}
sfclose (fp);
}
if (trm != trn)
trn = -1;
return 0;
}
示例10: LogOpen
int LogOpen(void)
{
#ifdef MAXSNOOP
if(!pipe)
SnSetPipeName("\\pipe\\maxsnoop");
SnoopOpen(pipe, &hsnoop, xfer_id, NullNotify);
#endif
if (!logfile && log_name && log_name[0])
{
log_written=TRUE;
Convert_Star_To_Task(log_name);
if ((logfile=sfopen(log_name, fopen_append, O_APPEND | O_TEXT | O_WRONLY |
O_CREAT | O_NOINHERIT, SH_DENYWR))==NULL)
{
Lprintf(copen_log, log_name);
vbuf_flush();
}
return (logfile != NULL);
}
else return TRUE;
}
示例11: EMinit
int EMinit (char *file) {
Sfio_t *fp;
char *line, *s1;
EMops = NULL;
EMopn = EMopm = 0;
if (!(imagedict = dtopen (&imagedisc, Dtset))) {
SUwarning (0, "EMinit", "cannot create imagedict");
return -1;
}
if (!(nodedict = dtopen (&nodedisc, Dtset))) {
SUwarning (0, "EMinit", "cannot create nodedict");
return -1;
}
if (!(edgedict = dtopen (&edgedisc, Dtset))) {
SUwarning (0, "EMinit", "cannot create edgedict");
return -1;
}
if (!(fp = sfopen (NULL, file, "r")))
SUerror ("EMinit", "cannot open file %s", file);
while ((line = sfgetr (fp, '\n', 1))) {
if (!(s1 = strchr (line, '|'))) {
SUwarning (0, "EMinit", "bad line: %s", line);
continue;
}
*s1++ = 0;
if (load (line, s1) == -1)
SUerror ("EMinit", "cannot load embed file %s", line);
}
sfclose (fp);
return 0;
}
示例12: sfopen
/*
read_gmsh: read the gmsh II file and output a pointer to mesh structure
ckecked: ok
*/
mesh *read_gmsh(const char *fname)
{
id i; // index cell
id j; // index for face in all faces
id k; // index for faces in one cell
gmsh_raw *gmsh;
mesh *m;
// open mesh file and allocate gmsh strucut
fp = sfopen(fname, "in read_gmsh() for fp");
gmsh = smalloc(sizeof(gmsh_raw)*1, "in read_gmsh, for gmsh");
/*find the opening mark, and read the text blocks*/
while(fgets(line, MAXLINE, fp) != NULL){ // read line by line
if (sscanf(line, "%s", w) == 1){
if (strcmp(w, "$PhysicalNames") == 0) read_physicalNames(fp, gmsh);
if (strcmp(w, "$Nodes") == 0) read_nodes(fp, gmsh);
if (strcmp(w, "$Elements") == 0) read_elems(fp, gmsh);
}
}
/* construct mesh from elements*/
m = elems_to_mesh(gmsh);
/* sort the faces according to its 3 types: boundary, salve, nb*/
sort_faces();
/*clean up*/
fclose(fp);
free(facetypes);
return m;
}
示例13: savenpacoords
static int savenpacoords (char *dir) {
Sfio_t *fp;
loc_t *locp;
int loci;
int npanxxi;
npa_t *npap;
int npai, npa;
SUmessage (1, "savenpacoords", "saving file %s/npa.coords", dir);
if (!(fp = sfopen (NULL, sfprints ("%s/npa.coords", dir), "w"))) {
SUwarning (1, "savenpacoords", "open failed for %s/npa.coords", dir);
return -1;
}
sfsetbuf (fp, NULL, 1048576);
for (loci = 0; loci < locn; loci++) {
locp = locs[loci];
for (npanxxi = 0; npanxxi < locp->npanxxn; npanxxi++) {
npa = locp->npanxxs[npanxxi]->npanxx / 1000;
xs[npa] += locp->x, ys[npa] += locp->y, ns[npa]++;
}
}
for (npai = 0; npai < npan; npai++) {
npap = npas[npai];
if (ns[npap->npa] > 0)
sfprintf (
fp, "%03d %d %d\n", npap->npa,
(int) (xs[npap->npa] / (double) ns[npap->npa]),
(int) (ys[npap->npa] / (double) ns[npap->npa])
);
}
sfclose (fp);
return 0;
}
示例14: getpass
extern char* getpass(const char *prompt)
{
struct termios told,tnew;
Sfio_t *iop;
static char *cp, passwd[32];
void (*savesig)(int);
if(!(iop = sfopen((Sfio_t*)0, "/dev/tty", "r")))
return(0);
if(tcgetattr(sffileno(iop),&told) < 0)
return(0);
interrupt = 0;
tnew = told;
tnew.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL);
if(tcsetattr(sffileno(iop),TCSANOW,&tnew) < 0)
return(0);
savesig = signal(SIGINT, handler);
sfputr(sfstderr,prompt,-1);
if(cp = sfgetr(iop,'\n',1))
strncpy(passwd,cp,sizeof(passwd)-1);
tcsetattr(sffileno(iop),TCSANOW,&told);
sfputc(sfstderr,'\n');
sfclose(iop);
signal(SIGINT, savesig);
if(interrupt)
kill(getpid(),SIGINT);
return(cp?passwd:0);
}
示例15: MAIN
MAIN()
{
Sfio_t* f;
char buf[1024], *s;
int n;
#ifdef DEBUG
Sfio_t* logf = sfopen(0,"LOG","a"); sfsetbuf(logf,NIL(Void_t*),0);
#endif
alarm(10);
if(argc > 1)
{ /* coprocess only */
while((s = sfreserve(sfstdin,-1,0)) )
{
#ifdef DEBUG
sfwrite(logf, s, sfvalue(sfstdin));
#endif
sfwrite(sfstdout, s, sfvalue(sfstdin));
}
return 0;
}
/* make coprocess */
if(!(f = sfpopen(NIL(Sfio_t*), sfprints("%s -p",argv[0]), "r+")))
terror("Opening for read/write\n");
for(n = 0; n < 10; ++n)
{ sfsprintf(buf,sizeof(buf),"Line %d",n);
sfputr(f,buf,'\n');
if(!(s = sfgetr(f,'\n',1)))
terror("Did not read back line\n");
if(strcmp(s,buf) != 0)
terror("Input=%s, Expect=%s\n",s,buf);
}
if(sfputr(f,"123456789",'\n') != 10)
terror("Bad write");
if(sfread(f,buf,3) != 3)
terror("Did not get data back\n");
if(strncmp(s,"123",3) != 0)
terror("Wrong data\n");
if(sfwrite(f,"aaa",3) != 3 || sfputc(f,'\n') != '\n')
terror("Fail on write\n");
if(!(s = sfgetr(f,'\n',1)) )
terror("Should have gotten 456789\n");
if(strcmp(s,"456789") != 0)
terror("Wrong data2\n");
if(!(s = sfgetr(f,'\n',1)) )
terror("Should have gotten aaa\n");
if(strcmp(s,"aaa") != 0)
terror("Wrong data3\n");
sfclose(f);
TSTEXIT(0);
}