]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libstdio/fwrite.c
libsec: take just the CN part of Distinguished Name in subjectAltName
[plan9front.git] / sys / src / libstdio / fwrite.c
1 /*
2  * pANS stdio -- fwrite
3  */
4 #include "iolib.h"
5
6 #define BIGN (BUFSIZ/2)
7
8 long fwrite(const void *p, long recl, long nrec, FILE *f){
9         char *s;
10         int n, d;
11
12         s=(char *)p;
13         n=recl*nrec;
14         while(n>0){
15                 d=f->rp-f->wp;
16                 if(d>0){
17                         if(d>n)
18                                 d=n;
19                         memmove(f->wp, s, d);
20                         f->wp+=d;
21                 }else{
22                         if(n>=BIGN && f->state==WR && !(f->flags&(STRING|LINEBUF)) && f->buf!=f->unbuf){
23                                 d=f->wp-f->buf;
24                                 if(d>0){
25                                         if(f->flags&APPEND)
26                                                 seek(f->fd, 0L, 2);
27                                         if(write(f->fd, f->buf, d)!=d){
28                                                 f->state=ERR;
29                                                 goto ret;
30                                         }
31                                         f->wp=f->rp=f->buf;
32                                 }
33                                 if(f->flags&APPEND)
34                                         seek(f->fd, 0L, 2);
35                                 d=write(f->fd, s, n);
36                                 if(d<=0){
37                                         f->state=ERR;
38                                         goto ret;
39                                 }
40                         }else{
41                                 if(_IO_putc(*s, f)==EOF)
42                                         goto ret;
43                                 d=1;
44                         }
45                 }
46                 s+=d;
47                 n-=d;
48         }
49     ret:
50         return (s-(char *)p)/(recl?recl:1);
51 }