本文整理汇总了C++中sfwrite函数的典型用法代码示例。如果您正苦于以下问题:C++ sfwrite函数的具体用法?C++ sfwrite怎么用?C++ sfwrite使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sfwrite函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: spaste
/*
* Handles paste -s, for file <in> to file <out> using delimiters <delim>
*/
static int spaste(Sfio_t *in,register Sfio_t* out,register const char *delim,int dsiz,int dlen,Delim_t* mp)
{
register const char *cp;
register int d=0;
if((cp = sfgetr(in,'\n',0)) && sfwrite(out,cp,sfvalue(in)-1) < 0)
return(-1);
while(cp=sfgetr(in, '\n',0))
{
if(dlen)
{
register int c;
if(d >= dlen)
d = 0;
if(mp)
sfwrite(out,mp[d].chr,mp[d].len);
else if(c=delim[d])
sfputc(out,c);
d++;
}
if(sfwrite(out,cp,sfvalue(in)-1) < 0)
return(-1);
}
sfputc(out,'\n');
return(0);
}
开发者ID:ISLEcode,项目名称:kornshell,代码行数:28,代码来源:paste.c
示例2: optesc
int
optesc(Sfio_t* sp, register const char* s, int esc)
{
register const char* m;
register int c;
if (*s == '[' && *(s + 1) == '+' && *(s + 2) == '?')
{
c = strlen(s);
if (s[c - 1] == ']')
{
sfprintf(sp, "%-.*s", c - 4, s + 3);
return 0;
}
}
if (esc != '?' && esc != ':')
esc = 0;
while (c = *s++)
{
if (isalnum(c))
{
for (m = s - 1; isalnum(*s); s++);
if (isalpha(c) && *s == '(' && isdigit(*(s + 1)) && *(s + 2) == ')')
{
sfputc(sp, '\b');
sfwrite(sp, m, s - m);
sfputc(sp, '\b');
sfwrite(sp, s, 3);
s += 3;
}
else
sfwrite(sp, m, s - m);
}
else if (c == '-' && *s == '-' || c == '<')
{
m = s - 1;
if (c == '-')
s++;
else if (*s == '/')
s++;
while (isalnum(*s))
s++;
if (c == '<' && *s == '>' || isspace(*s) || *s == 0 || *s == '=' || *s == ':' || *s == ';' || *s == '.' || *s == ',')
{
sfputc(sp, '\b');
sfwrite(sp, m, s - m);
sfputc(sp, '\b');
}
else
sfwrite(sp, m, s - m);
}
else
{
if (c == ']' || c == esc)
sfputc(sp, c);
sfputc(sp, c);
}
}
return 0;
}
开发者ID:nathanmkaya,项目名称:ksh-arch,代码行数:60,代码来源:optesc.c
示例3: splice
static void
splice(void)
{
char* s;
int n;
if (ed.spend) {
if (!ed.spl && !(ed.spl = sfstropen()))
error(ERROR_SYSTEM|3, "cannot initialize splice buffer");
sfwrite(ed.spl, ed.spbeg, ed.spend - ed.spbeg);
ed.spend = 0;
sfputc(ed.spl, '\n');
while (s = sfgetr(sfstdin, '\n', 1)) {
if ((n = sfvalue(sfstdin) - 1) > 0 && s[n - 1] == '\r')
n--;
if (n > 0 && s[n - 1] == '\\') {
sfwrite(ed.spl, s, n - 1);
sfputc(ed.spl, '\n');
}
else {
sfwrite(ed.spl, s, n);
break;
}
}
if (!(s = sfstruse(ed.spl)))
error(ERROR_SYSTEM|3, "out of space");
ed.input = s + (ed.input - ed.spbeg);
}
}
开发者ID:ISLEcode,项目名称:kornshell,代码行数:29,代码来源:ed.c
示例4: 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
示例5: paste
static int paste(int nstream,Sfio_t* streams[],Sfio_t *out, register const char *delim, int dsiz, int dlen, Delim_t* mp)
{
register const char *cp;
register int d, n, i, z, more=1;
register Sfio_t *fp;
do
{
d = (dlen>0?0:-1);
for(n=more-1,more=0; n < nstream;)
{
if(fp=streams[n])
{
if(cp = sfgetr(fp,'\n',0))
{
if(n==0)
more = 1;
else if(!more) /* first stream with output */
{
if(dsiz == 1)
sfnputc(out, *delim, n);
else if(dlen>0)
{
for(d=n; d>dlen; d-=dlen)
sfwrite(out,delim,dsiz);
if(d)
{
if(mp)
for (i = z = 0; i < d; i++)
z += mp[i].len;
else
z = d;
sfwrite(out,delim,z);
}
}
more = n+1;
}
if(sfwrite(out,cp,sfvalue(fp)-((n+1)<nstream)) < 0)
return(-1);
}
else
streams[n] = 0;
}
if(++n<nstream && more && d>=0)
{
register int c;
if(d >= dlen)
d = 0;
if(mp)
sfwrite(out,mp[d].chr,mp[d].len);
else if(c=delim[d])
sfputc(out,c);
d++;
}
else if(n==nstream && !streams[n-1] && more)
sfputc(out,'\n');
}
} while(more);
return(0);
}
开发者ID:ISLEcode,项目名称:kornshell,代码行数:59,代码来源:paste.c
示例6: helpwrite
static ssize_t
helpwrite(int fd, const void* buf, size_t len)
{
ssize_t n;
NoP(fd);
n = ed.help ? sfwrite(sfstderr, buf, len) : ed.verbose ? sfputr(ed.msg, "?", '\n') : 0;
sfstrseek(ed.buffer.help, 0, SEEK_SET);
sfwrite(ed.buffer.help, buf, len - 1);
sfputc(ed.buffer.help, 0);
return n;
}
开发者ID:ISLEcode,项目名称:kornshell,代码行数:12,代码来源:ed.c
示例7: main
main()
{
Sfio_t* null;
Sfio_t* f;
char buf[256*1024], b[256*1024];
int k, n;
if(!(null = sfopen(NIL(Sfio_t*),"/dev/null","w")) )
terror("Opening /dev/null");
sfsetbuf(null,NIL(char*),(size_t)SF_UNBOUND);
if(!SFISNULL(null) )
terror("Not /dev/null?");
if(!(f = sfopen(NIL(Sfio_t*), Kpv[0], "w+")) )
terror("Creating %s", Kpv[0]);
sfwrite(f,"1234",4);
sfseek(f,(Sfoff_t)1,0);
sfsync(f);
sfsetfd(null,-1);
sfsetfd(null,sffileno(f));
sfsync(null);
sfseek(f,(Sfoff_t)0,0);
if(sfread(f,buf,4) != 4 || strncmp(buf,"1234",4) != 0)
terror("Bad data");
for(k = 0; k < sizeof(buf); ++k)
buf[k] = 1;
for(k = sizeof(buf)/4; k < sizeof(buf)/2; ++k) /* make a big hole */
buf[k] = 0;
if(!(f = sfopen(f, Kpv[0], "w+")) )
terror("Creating %s", Kpv[0]);
n = sizeof(buf)-127;
if(sfwrite(f,buf,n) != n)
terror("Writing large buffer");
sfseek(f,(Sfoff_t)0,0);
if(sfread(f,b,n) != n)
terror("Reading large buffer");
for(k = 0; k < n; ++k)
if(b[k] != buf[k])
terror("Bad data");
rmkpv();
return 0;
}
开发者ID:xosevp,项目名称:zmailer,代码行数:49,代码来源:thole.c
示例8: tmain
tmain()
{
Sfio_t* f1;
Sfio_t* f2;
char* s;
if(!(f1 = sfopen(NIL(Sfio_t*), tstfile("sf", 0),"w+")) )
terror("Can't open file");
if(sfwrite(f1,"0123456789\n",11) != 11)
terror("Can't write to file");
sfclose(sfstdin);
if(sfswap(f1,sfstdin) != sfstdin)
terror("Can't swap with sfstdin");
sfseek(sfstdin,(Sfoff_t)0,0);
if(!(s = sfgetr(sfstdin,'\n',1)) )
terror("sfgetr failed");
if(strcmp(s,"0123456789") != 0)
terror("Get wrong data");
if(!(f1 = sfswap(sfstdin,NIL(Sfio_t*))) )
terror("Failed swapping to NULL");
if(!sfstack(sfstdout,f1) )
terror("Failed stacking f1");
if(!(f2 = sfopen(NIL(Sfio_t*), tstfile("sf", 0), "r")) )
terror("Can't open for read");
if(sfswap(f1,f2) != NIL(Sfio_t*) )
terror("sfswap should have failed");
texit(0);
}
开发者ID:ISLEcode,项目名称:kornshell,代码行数:33,代码来源:tswap.c
示例9: tmain
tmain()
{
int i;
char wbuf[1023];
char rbuf[1023];
Sfio_t *fp;
for(i = 0; i < sizeof(wbuf); ++i)
wbuf[i] = (i%26)+'a';
wbuf[sizeof(wbuf)-1] = '\0';
if(!(fp = sftmp(0)))
terror("Opening temp file");
for(i = 0; i < 256; ++i)
if(sfwrite(fp,wbuf,sizeof(wbuf)) != sizeof(wbuf))
terror("Writing");
sfseek(fp,(Sfoff_t)0,0);
sfset(fp,SF_WRITE,0);
sfsetbuf(fp,NIL(char*),0);
sfsetbuf(fp,NIL(char*),(size_t)SF_UNBOUND);
for(i = 0; i < 256; ++i)
{ if(sfread(fp,rbuf,sizeof(rbuf)) != sizeof(rbuf))
terror("Reading");
if(strcmp(rbuf,wbuf) != 0)
terror("Unmatched record");
}
texit(0);
}
开发者ID:nathanmkaya,项目名称:ksh-arch,代码行数:33,代码来源:twrrd.c
示例10: MAIN
MAIN()
{
char buf[1024], *s;
Sfio_t* f;
f = sfnew(NIL(Sfio_t*),NIL(Void_t*),(size_t)SF_UNBOUND,-1,SF_WRITE|SF_STRING);
sfsetbuf(sfstdout,buf,sizeof(buf));
sfsetbuf(sfstderr,buf,sizeof(buf));
sfset(sfstdout,SF_SHARE,0);
sfset(sfstderr,SF_SHARE,0);
if(!sfpool(sfstdout,f,SF_SHARE) || !sfpool(sfstderr,f,SF_SHARE) )
terror("Pooling\n");
if(sfputr(sfstdout,"01234",-1) != 5)
terror("Writing to stderr\n");
if(sfputr(sfstderr,"56789",-1) != 5)
terror("Writing to stdout\n");
if(sfputc(f,'\0') < 0)
terror("Writing to string stream\n");
sfseek(f,(Sfoff_t)0,0);
if(!(s = sfreserve(f,SF_UNBOUND,1)) )
terror("Peeking\n");
sfwrite(f,s,0);
if(strcmp(s,"0123456789") != 0)
terror("Data is wrong\n");
TSTEXIT(0);
}
开发者ID:ChappedSky,项目名称:hancock,代码行数:31,代码来源:tshare.c
示例11: MAIN
MAIN()
{
Sfio_t* f;
char buf[1024], buf2[1024], *data;
int n, r;
/* test to see if malloc() winds up calling mmap() */
if(!(data = (char*)malloc(8*1024)) )
terror("Malloc failed\n");
free(data);
Success = 0;
/* our real work */
if(!(f = sfopen(NIL(Sfio_t*), tstfile(0),"w")) )
terror("Can't open to write\n");
for(n = 0; n < sizeof(buf); ++n)
buf[n] = '0' + (n%10);
for(n = 0; n < 10; ++n)
sfwrite(f,buf,sizeof(buf));
if(!(f = sfopen(f, tstfile(0),"r")) )
terror("Can't open to read\n");
for(n = 0; n < 10; ++n)
{ if((r = sfread(f,buf2,sizeof(buf))) != sizeof(buf))
terror("Bad read size=%d\n",r);
if(strncmp(buf,buf2,sizeof(buf)) != 0)
terror("Get wrong data\n");
}
TSTEXIT(0);
}
开发者ID:gwowen,项目名称:seismicunix,代码行数:34,代码来源:tmmap2read.c
示例12: journal_update_crc
/* Recalculate CRC. */
int journal_update_crc(int fd)
{
if (fcntl(fd, F_GETFL) < 0) {
return KNOT_EINVAL;
}
char buf[4096];
ssize_t rb = 0;
crc_t crc = crc_init();
if (lseek(fd, MAGIC_LENGTH + sizeof(crc_t), SEEK_SET) < 0) {
return KNOT_ERROR;
}
while((rb = read(fd, buf, sizeof(buf))) > 0) {
crc = crc_update(crc, (const unsigned char *)buf, rb);
}
if (lseek(fd, MAGIC_LENGTH, SEEK_SET) < 0) {
return KNOT_ERROR;
}
if (!sfwrite(&crc, sizeof(crc_t), fd)) {
dbg_journal("journal: couldn't write CRC to fd=%d\n", fd);
return KNOT_ERROR;
}
return KNOT_EOK;
}
开发者ID:nice-redbull,项目名称:knot,代码行数:26,代码来源:journal.c
示例13: fixedopen
static int
fixedopen(Dssfile_t* file, Dssdisc_t* disc)
{
if (file->flags & DSS_FILE_READ)
{
if (!sfreserve(file->io, file->skip, 0))
{
if (disc->errorf)
(*disc->errorf)(NiL, disc, ERROR_SYSTEM|2, "header read error");
return -1;
}
if (!(file->data = (void*)vmnewof(file->dss->vm, 0, State_t, 1, 0)))
{
if (disc->errorf)
(*disc->errorf)(NiL, disc, ERROR_SYSTEM|2, "out of space");
return -1;
}
((State_t*)file->data)->swap = file->ident;
}
else if (!(file->flags & DSS_FILE_APPEND))
{
Fixedheader_t hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.magic.magic = MAGICID;
strcpy(hdr.magic.name, MAGIC_NAME);
strcpy(hdr.magic.type, MAGIC_TYPE);
hdr.magic.version = MAGIC_VERSION;
hdr.magic.size = sizeof(Netflow_t);
sfwrite(file->io, &hdr, sizeof(hdr));
}
return 0;
}
开发者ID:nathanmkaya,项目名称:ksh-arch,代码行数:33,代码来源:flow-fixed.c
示例14: namebase
static void namebase(Sfio_t *outfile, register char *pathname, char *suffix)
{
register char *first, *last;
register int n=0;
for(first=last=pathname; *last; last++);
/* back over trailing '/' */
if(last>first)
while(*--last=='/' && last > first);
if(last==first && *last=='/')
{
/* all '/' or "" */
if(*first=='/')
if(*++last=='/') /* keep leading // */
last++;
}
else
{
for(first=last++;first>pathname && *first!='/';first--);
if(*first=='/')
first++;
/* check for trailing suffix */
if(suffix && (n=strlen(suffix)) && n<(last-first))
{
if(memcmp(last-n,suffix,n)==0)
last -=n;
}
}
if(last>first)
sfwrite(outfile,first,last-first);
sfputc(outfile,'\n');
}
开发者ID:alarcher,项目名称:illumos-gate,代码行数:31,代码来源:basename.c
示例15: journal_trans_rollback
int journal_trans_rollback(journal_t *journal)
{
if (journal == NULL) {
return KNOT_EINVAL;
}
if ((journal->bflags & JOURNAL_TRANS) == 0) {
return KNOT_ENOENT;
}
/* Preempt last (failed) node. */
journal_node_t *t_end = journal->nodes + journal->qtail;
dbg_journal("journal: rollback transaction id=<%hu,%hu> (@%u, l=%u)\n",
journal->tmark, journal->qtail, t_end->pos, t_end->len);
journal->free.pos = t_end->pos;
journal->free.len = t_end->len;
/* Best effort free. */
t_end->flags = JOURNAL_FREE;
(void) journal_update(journal, t_end);
/* Write back free segment state. */
int seek_ret = lseek(journal->fd, JOURNAL_HSIZE, SEEK_SET);
if (seek_ret < 0 || !sfwrite(&journal->free, sizeof(journal_node_t), journal->fd)) {
return KNOT_ERROR;
}
/* Clear in-transaction flags. */
journal->tmark = 0;
journal->bflags &= (~JOURNAL_TRANS);
return KNOT_EOK;
}
开发者ID:stribika,项目名称:curveprotect,代码行数:32,代码来源:journal.c
示例16: journal_update
int journal_update(journal_t *journal, journal_node_t *n)
{
if (journal == NULL || n == NULL) {
return KNOT_EINVAL;
}
/* Calculate node offset. */
const size_t node_len = sizeof(journal_node_t);
size_t i = n - journal->nodes;
if (i > journal->max_nodes) {
return KNOT_EINVAL;
}
/* Calculate node position in permanent storage. */
long jn_fpos = JOURNAL_HSIZE + (i + 1) * node_len;
dbg_journal("journal: syncing journal node=%zu id=%llu flags=0x%x\n",
i, (unsigned long long)n->id, n->flags);
/* Write back. */
int seek_ret = lseek(journal->fd, jn_fpos, SEEK_SET);
if (seek_ret < 0 || !sfwrite(n, node_len, journal->fd)) {
dbg_journal("journal: failed to writeback node=%llu to %ld\n",
(unsigned long long)n->id, jn_fpos);
return KNOT_ERROR;
}
return KNOT_EOK;
}
开发者ID:nice-redbull,项目名称:knot,代码行数:29,代码来源:journal.c
示例17: l_dirname
static void l_dirname(register Sfio_t *outfile, register const char *pathname)
{
register const char *last;
/* go to end of path */
for(last=pathname; *last; last++);
/* back over trailing '/' */
while(last>pathname && *--last=='/');
/* back over non-slash chars */
for(;last>pathname && *last!='/';last--);
if(last==pathname)
{
/* all '/' or "" */
if(*pathname!='/')
last = pathname = ".";
}
else
{
/* back over trailing '/' */
for(;*last=='/' && last > pathname; last--);
}
/* preserve // */
if(last!=pathname && pathname[0]=='/' && pathname[1]=='/')
{
while(pathname[2]=='/' && pathname<last)
pathname++;
if(last!=pathname && pathname[0]=='/' && pathname[1]=='/' && *astconf("PATH_LEADING_SLASHES",NiL,NiL)!='1')
pathname++;
}
sfwrite(outfile,pathname,last+1-pathname);
sfputc(outfile,'\n');
}
开发者ID:nathanmkaya,项目名称:ksh-arch,代码行数:31,代码来源:dirname.c
示例18: 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
示例19: tmain
tmain() {
UNUSED(argc);
UNUSED(argv);
char buf[1024];
sfsetbuf(sfstdout, buf, sizeof(buf));
sfset(sfstdout, SF_LINE, 0);
if (sfdisc(sfstdout, &seekable) != &seekable) terror("Can't set discipline");
if (sfseek(sfstdout, (Sfoff_t)0, 0) < 0) terror("Sfstdout should be seekable");
if (sfwrite(sfstdout, "123\n", 4) != 4) terror("Can't write");
if (sfwrite(sfstdout, "123\n", 4) != 4) terror("Can't write");
if (sfdisc(sfstdout, NULL) != &seekable) terror("Can't pop discipline");
if (buffer != buf || size != 8 || count != 1) terror("Wrong calls to write");
texit(0);
}
开发者ID:att,项目名称:ast,代码行数:18,代码来源:tnoseek.c
示例20: killClientProgramHandler
void killClientProgramHandler(){
sfwrite(&lock, stdout, "\n");
//printf("\n");
protocolMethod(clientFd,BYE,NULL,NULL,NULL,verbose, &lock);
if(clientFd >0){
close(clientFd);
}
exit(0);
}
开发者ID:davlin95,项目名称:DJLT,代码行数:9,代码来源:client.c
注:本文中的sfwrite函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论