本文整理汇总了C++中sfopen函数的典型用法代码示例。如果您正苦于以下问题:C++ sfopen函数的具体用法?C++ sfopen怎么用?C++ sfopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sfopen函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:jiayuehua,项目名称:sfio,代码行数:32,代码来源:topen.c
示例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);
}
开发者ID:ISLEcode,项目名称:kornshell,代码行数:34,代码来源:topen.c
示例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;
}
开发者ID:nathanmkaya,项目名称:ksh-arch,代码行数:57,代码来源:comm.c
示例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);
}
开发者ID:ChappedSky,项目名称:hancock,代码行数:55,代码来源:tmove.c
示例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);
}
开发者ID:att,项目名称:ast,代码行数:54,代码来源:tungetc.c
示例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;
}
开发者ID:nathanmkaya,项目名称:ksh-arch,代码行数:51,代码来源:probe.c
示例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;
}
开发者ID:gitpan,项目名称:sfio,代码行数:14,代码来源:tleak.c
示例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;
}
开发者ID:TidyHuang,项目名称:vizgems,代码行数:26,代码来源:cnvnpanxx.c
示例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;
}
开发者ID:TidyHuang,项目名称:vizgems,代码行数:29,代码来源:vg_timeranges.tmpl.c
示例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;
}
开发者ID:klamonte,项目名称:maximus,代码行数:26,代码来源:log.c
示例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;
}
开发者ID:TidyHuang,项目名称:vizgems,代码行数:34,代码来源:vg_dq_vt_util_em.c
示例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;
}
开发者ID:onlyacan,项目名称:fsc,代码行数:38,代码来源:read_gmsh2.c
示例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;
}
开发者ID:TidyHuang,项目名称:vizgems,代码行数:33,代码来源:cnvnpanxx.c
示例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);
}
开发者ID:nathanmkaya,项目名称:ksh-arch,代码行数:27,代码来源:getpass.c
示例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);
}
开发者ID:gwowen,项目名称:seismicunix,代码行数:59,代码来源:tpopenrw.c
示例16: tmain
tmain() {
UNUSED(argc);
UNUSED(argv);
Sfio_t *f1, *f2;
char *s;
Sfoff_t p;
char buf[1024];
int r, w;
if (!(f1 = sfopen(NULL, tstfile("sf", 0), "w"))) terror("Can't open f1");
if (!(f1 = sfopen(f1, tstfile("sf", 0), "a+"))) terror("Can't open f1");
if (!(f2 = sfopen(NULL, tstfile("sf", 0), "a+"))) terror("Can't open f2");
if (sfwrite(f1, "012345678\n", 10) != 10 || sfsync(f1) < 0) terror("Writing to f1");
if ((p = sftell(f1)) != 10) terror("Bad sftell1 %ld", p);
if (sfwrite(f2, "abcdefghi\n", 10) != 10 || sfsync(f2) < 0) terror("Writing to f2");
if ((p = sftell(f2)) != 20) terror("Bad sftell2");
if ((p = sfseek(f1, (Sfoff_t)0, 0)) != 0) terror("Bad seek");
if (!(s = sfgetr(f1, '\n', 1))) terror("Bad getr1");
if (strcmp(s, "012345678") != 0) terror("Bad input1");
if ((p = sftell(f1)) != 10) terror("Bad sftell3");
if (sfwrite(f1, "012345678\n", 10) != 10 || sfsync(f1) < 0) terror("Writing to f1");
if ((p = sftell(f1)) != 30) terror("Bad sftell4");
if ((p = sfseek(f2, (Sfoff_t)10, 0)) != 10) terror("Bad seek");
if (!(s = sfgetr(f2, '\n', 1))) terror("Bad getr2");
if (strcmp(s, "abcdefghi") != 0) terror("Bad input2");
if (!(s = sfgetr(f2, '\n', 1))) terror("Bad getr3");
if (strcmp(s, "012345678") != 0) terror("Bad input3");
if (!(f1 = sfopen(f1, tstfile("sf", 0), "w"))) terror("Can't open file to write");
for (r = 0; r < 1024; ++r) buf[r] = 'a';
if ((w = sfwrite(f1, buf, 1024)) != 1024) terror("writing w=%d", w);
if (!(f1 = sfopen(f1, tstfile("sf", 0), "a"))) terror("Can't open file to append");
sfseek(f1, (Sfoff_t)0, 0);
if ((w = sfwrite(f1, buf, 64)) != 64) terror("writing w=%d", w);
if ((r = (int)sftell(f1)) != (1024 + 64)) terror("seek position wrong s=%d", r);
texit(0);
}
开发者ID:att,项目名称:ast,代码行数:46,代码来源:tappend.c
示例17: main
int
main(int argc, char** argv)
{
register char* s;
register Sfio_t* sp;
unsigned long n;
int summary = 0;
unsigned long total = 0;
int trailer;
NoP(argc);
error_info.id = "ncsl";
for (;;)
{
switch (optget(argv, usage))
{
case 0:
break;
case 's':
summary = 1;
continue;
case '?':
error(ERROR_USAGE|4, "%s", opt_info.arg);
continue;
case ':':
error(2, "%s", opt_info.arg);
continue;
}
break;
}
argv += opt_info.index;
if (error_info.errors)
error(ERROR_USAGE|4, "%s", optusage(NiL));
if (*argv)
{
trailer = *(argv + 1) != 0;
while (s = *argv++)
{
if (!(sp = sfopen(NiL, s, "r")))
error(2, "%s: cannot open for reading", s);
else
{
n = ncsl(sp);
sfclose(sp);
if (!summary)
sfprintf(sfstdout, "%s: %lu\n", s, n);
total += n;
}
}
if (summary || trailer)
sfprintf(sfstdout, "%lu\n", total);
}
else
sfprintf(sfstdout, "%d\n", ncsl(sfstdin));
return error_info.errors != 0;
}
开发者ID:ISLEcode,项目名称:kornshell,代码行数:57,代码来源:ncsl.c
示例18: xfer_del
void xfer_del(void)
{
char new_log[PATHLEN];
char linebuf[LINELEN + 1];
char bad_real[NAMELEN], bad_temp[NAMELEN];
long bad_fsize, bad_ftime;
FILE *fp, *new_fp;
boolean left;
if (fexist(xfer_pathname))
unlink(xfer_pathname);
if ((fp = sfopen(xfer_log, "rt", DENY_WRITE)) != NULL) {
mergepath(new_log, download, "BAD-XFER.$$$");
if ((new_fp = sfopen(new_log, "wt", DENY_ALL)) != NULL) {
left = false;
while (fgets(linebuf, LINELEN, fp)) {
sscanf(linebuf, "%s %s %ld %lo",
bad_real, bad_temp, &bad_fsize,
&bad_ftime);
if (strcmp(xfer_real, bad_real)
|| strcmp(xfer_temp, bad_temp)
|| xfer_fsize != bad_fsize
|| xfer_ftime != bad_ftime) {
fputs(linebuf, new_fp);
left = true;
}
}
fclose(fp);
fclose(new_fp);
unlink(xfer_log);
if (left)
rename(new_log, xfer_log);
else
unlink(new_log);
} else
fclose(fp);
}
} /*xfer_del() */
开发者ID:hlyytine,项目名称:daydream,代码行数:39,代码来源:fmisc.c
示例19: handle
static void
handle(void)
{
register int c;
char* s;
char* b;
mode_t mask;
if (ed.caught == SIGINT) {
ed.caught = 0;
ed.lastc = '\n';
sfputc(ed.msg, '\n');
error(2, "interrupt");
}
for (c = 0; c < elementsof(signals); c++)
signal(signals[c], SIG_IGN);
if (ed.dol > ed.zero) {
ed.addr1 = ed.zero + 1;
ed.addr2 = ed.dol;
mask = umask(S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
b = "ed.hup";
if (!(ed.iop = sfopen(NiL, b, "w")) && !ed.restricted && (s = getenv("HOME"))) {
sfstrseek(ed.buffer.line, 0, SEEK_SET);
sfprintf(ed.buffer.line, "%s/%s", s, b);
if (!(b = sfstruse(ed.buffer.line)))
error(ERROR_SYSTEM|3, "out of space");
ed.iop = sfopen(NiL, b, "w");
}
umask(mask);
if (!ed.iop)
error(ERROR_SYSTEM|1, "%s: cannot save changes", b);
else {
error_info.file = b;
putfile();
}
}
ed.modified = 0;
quit(0);
}
开发者ID:ISLEcode,项目名称:kornshell,代码行数:39,代码来源:ed.c
示例20: note
static int
note(Css_t* css, register Connection_t* to, int log, char* s, size_t n, int force, Cssdisc_t* disc)
{
register State_t* state = (State_t*)disc;
ssize_t z;
if ((force || to->blocked[log] < 0) && (z = data(state, to, s, n, force)) != n)
{
if (!force && !state->logged)
{
state->logged = 1;
if (!state->logs[log].sp)
{
state->logs[log].name[0] = '0' + log;
remove(state->logs[log].name);
if (!(state->logs[log].sp = sfopen(NiL, state->logs[log].name, "r+")))
error(ERROR_SYSTEM|3, "%s: cannot create message log", state->logs[log].name);
message((-1, "[%d] %s: create log", __LINE__, state->logs[log].name));
}
message((-1, "[%d] %s: %d log", __LINE__, state->logs[log].name, to->fp->fd));
if (sfwrite(state->logs[log].sp, s, n) != n)
error(ERROR_SYSTEM|3, "%s: log file write error", state->logs[log].name);
if ((state->logs[log].offset += n) >= HOG && !state->logs[!log].sp)
state->log = !log;
}
if (to->blocked[log] < 0)
{
message((-1, "[%d] %s: block", __LINE__, state->logs[log].name));
state->logs[log].blocked++;
}
to->blocked[log] = state->logs[log].offset - n + z;
message((-1, "[%d] %s: %d offset %I*d", __LINE__, state->logs[log].name, to->fp->fd, sizeof(to->blocked[log]), to->blocked[log]));
cssfd(css, to->fp->fd, CS_POLL_READ|CS_POLL_WRITE);
return 0;
}
if (to->blocked[log] >= 0)
{
message((-1, "[%d] %s: %d unblock", __LINE__, state->logs[log].name, to->fp->fd));
to->blocked[log] = -1;
if (!--state->logs[log].blocked)
{
sfclose(state->logs[log].sp);
state->logs[log].sp = 0;
state->logs[log].offset = 0;
remove(state->logs[log].name);
message((-1, "[%d] %s: clear", __LINE__, state->logs[log].name));
}
}
return 1;
}
开发者ID:ISLEcode,项目名称:kornshell,代码行数:50,代码来源:mbb.c
注:本文中的sfopen函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论